Skip to content

Commit 0458eb9

Browse files
committed
MC-32387: Add pagination support to categoryList query
- review comments - add caching
1 parent 96f8ded commit 0458eb9

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\CatalogGraphQl\Model\Resolver\Category;
99

10+
use Magento\Catalog\Model\Category;
1011
use Magento\Framework\GraphQl\Query\Resolver\IdentityInterface;
1112

1213
/**
@@ -15,7 +16,7 @@
1516
class CategoriesIdentity implements IdentityInterface
1617
{
1718
/** @var string */
18-
private $cacheTag = \Magento\Catalog\Model\Category::CACHE_TAG;
19+
private $cacheTag = Category::CACHE_TAG;
1920

2021
/**
2122
* Get category IDs from resolved data
@@ -26,8 +27,9 @@ class CategoriesIdentity implements IdentityInterface
2627
public function getIdentities(array $resolvedData): array
2728
{
2829
$ids = [];
29-
if (!empty($resolvedData)) {
30-
foreach ($resolvedData as $category) {
30+
$resolvedCategories = $resolvedData['items'] ?? $resolvedData;
31+
if (!empty($resolvedCategories)) {
32+
foreach ($resolvedCategories as $category) {
3133
$ids[] = sprintf('%s_%s', $this->cacheTag, $category['id']);
3234
}
3335
if (!empty($ids)) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Query {
2121
filters: CategoryFilterInput @doc(description: "Identifies which Category filter inputs to search for and return.")
2222
pageSize: Int = 20 @doc(description: "Specifies the maximum number of results to return at once. This attribute is optional.")
2323
currentPage: Int = 1 @doc(description: "Specifies which page of results to return. The default value is 1.")
24-
): CategoryResult @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\CategoriesQuery")
24+
): CategoryResult @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\CategoriesQuery") @cache(cacheIdentity: "Magento\\CatalogGraphQl\\Model\\Resolver\\Category\\CategoriesIdentity")
2525
}
2626

2727
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.") {
@@ -138,8 +138,8 @@ type CategoryTree implements CategoryInterface @doc(description: "Category Tree
138138
children: [CategoryTree] @doc(description: "Child categories tree.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\CategoryTree")
139139
}
140140

141-
type CategoryResult @doc(description: "Collection of CategoryTree object and pagination information.") {
142-
items: [CategoryTree] @doc(description: "List of categories that match filter criteria.")
141+
type CategoryResult @doc(description: "A collection of CategoryTree objects and pagination information.") {
142+
items: [CategoryTree] @doc(description: "A list of categories that match the filter criteria.")
143143
page_info: SearchResultPageInfo @doc(description: "An object that includes the page_info and currentPage values specified in the query.")
144144
total_count: Int @doc(description: "The total number of categories that match the criteria.")
145145
}

0 commit comments

Comments
 (0)