Skip to content

Commit 56a068e

Browse files
committed
MC-21480: Add caching for CategoryList resolver
- Made changes to caching test and resolver
1 parent e4f6094 commit 56a068e

File tree

3 files changed

+63
-40
lines changed

3 files changed

+63
-40
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/Category/CategoryListIdentity.php

Lines changed: 0 additions & 39 deletions
This file was deleted.

app/code/Magento/CatalogGraphQl/etc/schema.graphqls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type Query {
1616
@resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\CategoryTree") @doc(description: "The category query searches for categories that match the criteria specified in the search and filter attributes.") @deprecated(reason: "Use 'categoryList' query instead of 'category' query") @cache(cacheIdentity: "Magento\\CatalogGraphQl\\Model\\Resolver\\Category\\CategoryTreeIdentity")
1717
categoryList(
1818
filters: CategoryFilterInput @doc(description: "Identifies which Category filter inputs to search for and return.")
19-
): [CategoryTree] @doc(description: "Returns an array of categories based on the specified filters.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\CategoryList") @cache(cacheIdentity: "Magento\\CatalogGraphQl\\Model\\Resolver\\Category\\CategoryListIdentity")
19+
): [CategoryTree] @doc(description: "Returns an array of categories based on the specified filters.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\CategoryList") @cache(cacheIdentity: "Magento\\CatalogGraphQl\\Model\\Resolver\\Category\\CategoriesIdentity")
2020
}
2121

2222
type Price @doc(description: "Price is deprecated, replaced by ProductPrice. The Price object defines the price of a product as well as any tax-related adjustments.") {

dev/tests/integration/testsuite/Magento/GraphQlCache/Controller/Catalog/CategoryListCacheTest.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,66 @@ public function testSecondRequestIsServedFromCache()
7777
$actualCacheTags = explode(',', $cacheResponse->getHeader('X-Magento-Tags')->getFieldValue());
7878
$this->assertEquals($expectedCacheTags, $actualCacheTags);
7979
}
80+
81+
/**
82+
* Test cache tags are generated
83+
*
84+
* @magentoDataFixture Magento/Catalog/_files/category_tree.php
85+
*/
86+
public function testRequestCacheTagsForCategoryListOnMultipleIds(): void
87+
{
88+
$categoryId1 ='400';
89+
$categoryId2 = '401';
90+
$query
91+
= <<<QUERY
92+
{
93+
categoryList(filters: {ids: {in: ["$categoryId1", "$categoryId2"]}}) {
94+
id
95+
name
96+
url_key
97+
description
98+
product_count
99+
}
100+
}
101+
QUERY;
102+
$response = $this->dispatchGraphQlGETRequest(['query' => $query]);
103+
$this->assertEquals('MISS', $response->getHeader('X-Magento-Cache-Debug')->getFieldValue());
104+
$actualCacheTags = explode(',', $response->getHeader('X-Magento-Tags')->getFieldValue());
105+
$expectedCacheTags = ['cat_c','cat_c_' . $categoryId1, 'cat_c_' . $categoryId2, 'FPC'];
106+
$this->assertEquals($expectedCacheTags, $actualCacheTags);
107+
}
108+
109+
/**
110+
* Test request is served from cache
111+
*
112+
* @magentoDataFixture Magento/Catalog/_files/category_tree.php
113+
*/
114+
public function testSecondRequestIsServedFromCacheOnMultipleIds()
115+
{
116+
$categoryId1 ='400';
117+
$categoryId2 = '401';
118+
$query
119+
= <<<QUERY
120+
{
121+
categoryList(filters: {ids: {in: ["$categoryId1", "$categoryId2"]}}) {
122+
id
123+
name
124+
url_key
125+
description
126+
product_count
127+
}
128+
}
129+
QUERY;
130+
$expectedCacheTags = ['cat_c','cat_c_' . $categoryId1, 'cat_c_' . $categoryId2, 'FPC'];
131+
132+
$response = $this->dispatchGraphQlGETRequest(['query' => $query]);
133+
$this->assertEquals('MISS', $response->getHeader('X-Magento-Cache-Debug')->getFieldValue());
134+
$actualCacheTags = explode(',', $response->getHeader('X-Magento-Tags')->getFieldValue());
135+
$this->assertEquals($expectedCacheTags, $actualCacheTags);
136+
137+
$cacheResponse = $this->dispatchGraphQlGETRequest(['query' => $query]);
138+
$this->assertEquals('HIT', $cacheResponse->getHeader('X-Magento-Cache-Debug')->getFieldValue());
139+
$actualCacheTags = explode(',', $cacheResponse->getHeader('X-Magento-Tags')->getFieldValue());
140+
$this->assertEquals($expectedCacheTags, $actualCacheTags);
141+
}
80142
}

0 commit comments

Comments
 (0)