Skip to content

Commit 0d05091

Browse files
committed
MC-21480: Add caching for CategoryList resolver
- Added CategoryList Caching resolver
1 parent 394b70e commit 0d05091

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogGraphQl\Model\Resolver\Category;
9+
10+
use Magento\Framework\GraphQl\Query\Resolver\IdentityInterface;
11+
12+
/**
13+
* Identity for resolved category
14+
*/
15+
class CategoryListIdentity implements IdentityInterface
16+
{
17+
/** @var string */
18+
private $cacheTag = \Magento\Catalog\Model\Category::CACHE_TAG;
19+
20+
/**
21+
* Get category IDs from resolved data
22+
*
23+
* @param array $resolvedData
24+
* @return string[]
25+
*/
26+
public function getIdentities(array $resolvedData): array
27+
{
28+
$ids = [];
29+
if (!empty($resolvedData)) {
30+
foreach ($resolvedData as $category) {
31+
$ids[] = sprintf('%s_%s', $this->cacheTag, $category['id']);
32+
}
33+
if (!empty($ids)) {
34+
array_unshift($ids, $this->cacheTag);
35+
}
36+
}
37+
return $ids;
38+
}
39+
}

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")
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")
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.") {

0 commit comments

Comments
 (0)