Skip to content

Commit 98c65c0

Browse files
committed
Merge branch 'graphql-issue-230' of github.com:magento-honey-badgers/magento2ce into graphql-issue-230
2 parents b21ce3e + a7f6ba0 commit 98c65c0

File tree

29 files changed

+488
-256
lines changed

29 files changed

+488
-256
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/Category/CategoriesIdentityResolver.php renamed to app/code/Magento/CatalogGraphQl/Model/Resolver/Category/CategoriesIdentity.php

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

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

10-
use Magento\Framework\GraphQl\Query\IdentityResolverInterface;
10+
use Magento\Framework\GraphQl\Query\Resolver\IdentityInterface;
1111

1212
/**
1313
* Identity for multiple resolved categories
1414
*/
15-
class CategoriesIdentityResolver implements IdentityResolverInterface
15+
class CategoriesIdentity implements IdentityInterface
1616
{
1717
/**
1818
* Get category IDs from resolved data
1919
*
2020
* @param array $resolvedData
2121
* @return array
2222
*/
23-
public function getIdentifiers(array $resolvedData): array
23+
public function getIdentities(array $resolvedData): array
2424
{
2525
$ids = [];
2626
if (!empty($resolvedData)) {

app/code/Magento/CatalogGraphQl/Model/Resolver/Category/CategoryTreeIdentityResolver.php renamed to app/code/Magento/CatalogGraphQl/Model/Resolver/Category/CategoryTreeIdentity.php

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

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

10-
use Magento\Framework\GraphQl\Query\IdentityResolverInterface;
10+
use Magento\Framework\GraphQl\Query\Resolver\IdentityInterface;
1111

1212
/**
1313
* Identity for resolved category
1414
*/
15-
class CategoryTreeIdentityResolver implements IdentityResolverInterface
15+
class CategoryTreeIdentity implements IdentityInterface
1616
{
1717
/**
1818
* Get category ID from resolved data
1919
*
2020
* @param array $resolvedData
2121
* @return array
2222
*/
23-
public function getIdentifiers(array $resolvedData): array
23+
public function getIdentities(array $resolvedData): array
2424
{
2525
return empty($resolvedData['id']) ? [] : [$resolvedData['id']];
2626
}

app/code/Magento/CatalogGraphQl/Model/Resolver/Product/IdentityResolver.php renamed to app/code/Magento/CatalogGraphQl/Model/Resolver/Product/Identity.php

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

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

10-
use Magento\Framework\GraphQl\Query\IdentityResolverInterface;
10+
use Magento\Framework\GraphQl\Query\Resolver\IdentityInterface;
1111

1212
/**
1313
* Identity for resolved products
1414
*/
15-
class IdentityResolver implements IdentityResolverInterface
15+
class Identity implements IdentityInterface
1616
{
1717
/**
1818
* Get product ids for cache tag
1919
*
2020
* @param array $resolvedData
2121
* @return array
2222
*/
23-
public function getIdentifiers(array $resolvedData): array
23+
public function getIdentities(array $resolvedData): array
2424
{
2525
$ids = [];
2626
$items = $resolvedData['items'] ?? [];

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ type Query {
99
currentPage: Int = 1 @doc(description: "Specifies which page of results to return. The default value is 1."),
1010
sort: ProductSortInput @doc(description: "Specifies which attribute to sort on, and whether to return the results in ascending or descending order.")
1111
): Products
12-
@resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Products") @doc(description: "The products query searches for products that match the criteria specified in the search and filter attributes") @cache(cacheTag: "cat_p", cacheIdentityResolver: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\IdentityResolver")
12+
@resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Products") @doc(description: "The products query searches for products that match the criteria specified in the search and filter attributes") @cache(cacheTag: "cat_p", cacheIdentity: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\Identity")
1313
category (
1414
id: Int @doc(description: "Id of the category")
1515
): CategoryTree
16-
@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") @cache(cacheTag: "cat_c", cacheIdentityResolver: "Magento\\CatalogGraphQl\\Model\\Resolver\\Category\\CategoryTreeIdentityResolver")
16+
@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") @cache(cacheTag: "cat_c", cacheIdentity: "Magento\\CatalogGraphQl\\Model\\Resolver\\Category\\CategoryTreeIdentity")
1717
}
1818

1919
enum CurrencyEnum @doc(description: "The list of available currency codes") {
@@ -275,7 +275,7 @@ interface ProductInterface @typeResolver(class: "Magento\\CatalogGraphQl\\Model\
275275
price: ProductPrices @doc(description: "A ProductPrices object, indicating the price of an item") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\Price")
276276
gift_message_available: String @doc(description: "Indicates whether a gift message is available")
277277
manufacturer: Int @doc(description: "A number representing the product's manufacturer")
278-
categories: [CategoryInterface] @doc(description: "The categories assigned to a product") @cache(cacheTag: "cat_c", cacheIdentityResolver: "Magento\\CatalogGraphQl\\Model\\Resolver\\Category\\CategoriesIdentityResolver") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Categories")
278+
categories: [CategoryInterface] @doc(description: "The categories assigned to a product") @cache(cacheTag: "cat_c", cacheIdentity: "Magento\\CatalogGraphQl\\Model\\Resolver\\Category\\CategoriesIdentity") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Categories")
279279
canonical_url: String @doc(description: "Canonical URL") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CanonicalUrl")
280280
}
281281

@@ -396,7 +396,7 @@ interface CategoryInterface @typeResolver(class: "Magento\\CatalogGraphQl\\Model
396396
pageSize: Int = 20 @doc(description: "Specifies the maximum number of results to return at once. This attribute is optional."),
397397
currentPage: Int = 1 @doc(description: "Specifies which page of results to return. The default value is 1."),
398398
sort: ProductSortInput @doc(description: "Specifies which attribute to sort on, and whether to return the results in ascending or descending order.")
399-
): CategoryProducts @doc(description: "The list of products assigned to the category") @cache(cacheTag: "cat_p", cacheIdentityResolver: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\IdentityResolver") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Category\\Products")
399+
): CategoryProducts @doc(description: "The list of products assigned to the category") @cache(cacheTag: "cat_p", cacheIdentity: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\Identity") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Category\\Products")
400400
breadcrumbs: [Breadcrumb] @doc(description: "Breadcrumbs, parent categories info") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Category\\Breadcrumbs")
401401
}
402402

app/code/Magento/CmsGraphQl/Model/Resolver/Block/IdentityResolver.php renamed to app/code/Magento/CmsGraphQl/Model/Resolver/Block/Identity.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@
88
namespace Magento\CmsGraphQl\Model\Resolver\Block;
99

1010
use Magento\Cms\Api\Data\BlockInterface;
11-
use Magento\Framework\GraphQl\Query\IdentityResolverInterface;
11+
use Magento\Framework\GraphQl\Query\Resolver\IdentityInterface;
1212

1313
/**
1414
* Identity for resolved CMS block
1515
*/
16-
class IdentityResolver implements IdentityResolverInterface
16+
class Identity implements IdentityInterface
1717
{
1818
/**
19-
* Get block identifiers from resolved data
19+
* Get block identities from resolved data
2020
*
2121
* @param array $resolvedData
2222
* @return array
2323
*/
24-
public function getIdentifiers(array $resolvedData): array
24+
public function getIdentities(array $resolvedData): array
2525
{
2626
$ids = [];
2727
$items = $resolvedData['items'] ?? [];

app/code/Magento/CmsGraphQl/Model/Resolver/Page/IdentityResolver.php renamed to app/code/Magento/CmsGraphQl/Model/Resolver/Page/Identity.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@
88
namespace Magento\CmsGraphQl\Model\Resolver\Page;
99

1010
use Magento\Cms\Api\Data\PageInterface;
11-
use Magento\Framework\GraphQl\Query\IdentityResolverInterface;
11+
use Magento\Framework\GraphQl\Query\Resolver\IdentityInterface;
1212

1313
/**
1414
* Identity for resolved CMS page
1515
*/
16-
class IdentityResolver implements IdentityResolverInterface
16+
class Identity implements IdentityInterface
1717
{
1818
/**
1919
* Get page ID from resolved data
2020
*
2121
* @param array $resolvedData
2222
* @return array
2323
*/
24-
public function getIdentifiers(array $resolvedData): array
24+
public function getIdentities(array $resolvedData): array
2525
{
2626
return empty($resolvedData[PageInterface::PAGE_ID]) ? [] : [$resolvedData[PageInterface::PAGE_ID]];
2727
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ type StoreConfig @doc(description: "The type contains information about a store
1313
type Query {
1414
cmsPage (
1515
id: Int @doc(description: "Id of the CMS page")
16-
): CmsPage @resolver(class: "Magento\\CmsGraphQl\\Model\\Resolver\\Page") @doc(description: "The CMS page query returns information about a CMS page") @cache(cacheTag: "cms_p", cacheIdentityResolver: "Magento\\CmsGraphQl\\Model\\Resolver\\Page\\IdentityResolver")
16+
): CmsPage @resolver(class: "Magento\\CmsGraphQl\\Model\\Resolver\\Page") @doc(description: "The CMS page query returns information about a CMS page") @cache(cacheTag: "cms_p", cacheIdentity: "Magento\\CmsGraphQl\\Model\\Resolver\\Page\\Identity")
1717
cmsBlocks (
1818
identifiers: [String] @doc(description: "Identifiers of the CMS blocks")
19-
): CmsBlocks @resolver(class: "Magento\\CmsGraphQl\\Model\\Resolver\\Blocks") @doc(description: "The CMS block query returns information about CMS blocks") @cache(cacheTag: "cms_b", cacheIdentityResolver: "Magento\\CmsGraphQl\\Model\\Resolver\\Block\\IdentityResolver")
19+
): CmsBlocks @resolver(class: "Magento\\CmsGraphQl\\Model\\Resolver\\Blocks") @doc(description: "The CMS block query returns information about CMS blocks") @cache(cacheTag: "cms_b", cacheIdentity: "Magento\\CmsGraphQl\\Model\\Resolver\\Block\\Identity")
2020
}
2121

2222
type CmsPage @doc(description: "CMS page defines all CMS page information") {

app/code/Magento/GraphQlCache/Model/CacheableQueryHandler.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Framework\GraphQl\Config\Element\Field;
1111
use Magento\Framework\App\RequestInterface;
12+
use Magento\GraphQlCache\Model\Resolver\IdentityPool;
1213

1314
/**
1415
* Handler of collecting tagging on cache.
@@ -29,23 +30,23 @@ class CacheableQueryHandler
2930
private $request;
3031

3132
/**
32-
* @var IdentityResolverPool
33+
* @var IdentityPool
3334
*/
34-
private $identityResolverPool;
35+
private $identityPool;
3536

3637
/**
3738
* @param CacheableQuery $cacheableQuery
3839
* @param RequestInterface $request
39-
* @param IdentityResolverPool $identityResolverPool
40+
* @param IdentityPool $identityPool
4041
*/
4142
public function __construct(
4243
CacheableQuery $cacheableQuery,
4344
RequestInterface $request,
44-
IdentityResolverPool $identityResolverPool
45+
IdentityPool $identityPool
4546
) {
4647
$this->cacheableQuery = $cacheableQuery;
4748
$this->request = $request;
48-
$this->identityResolverPool = $identityResolverPool;
49+
$this->identityPool = $identityPool;
4950
}
5051

5152
/**
@@ -58,15 +59,15 @@ public function __construct(
5859
public function handleCacheFromResolverResponse(array $resolvedValue, Field $field) : void
5960
{
6061
$cache = $field->getCache();
61-
$cacheIdentityResolverClass = $cache['cacheIdentityResolver'] ?? '';
62+
$cacheIdentityClass = $cache['cacheIdentity'] ?? '';
6263
$cacheable = $cache['cacheable'] ?? true;
6364
$cacheTag = $cache['cacheTag'] ?? null;
6465

6566
$cacheTags = [];
6667
if ($cacheTag && $this->request->isGet()) {
67-
if (!empty($cacheIdentityResolverClass)) {
68-
$cacheIdentityResolver = $this->identityResolverPool->get($cacheIdentityResolverClass);
69-
$cacheTagIds = $cacheIdentityResolver->getIdentifiers($resolvedValue);
68+
if (!empty($cacheIdentityClass)) {
69+
$cacheIdentity = $this->identityPool->get($cacheIdentityClass);
70+
$cacheTagIds = $cacheIdentity->getIdentities($resolvedValue);
7071
if (!empty($cacheTagIds)) {
7172
$cacheTags[] = $cacheTag;
7273
foreach ($cacheTagIds as $cacheTagId) {

app/code/Magento/GraphQlCache/Model/IdentityResolverPool.php

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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\GraphQlCache\Model\Resolver;
9+
10+
use Magento\Framework\ObjectManagerInterface;
11+
use Magento\Framework\GraphQl\Query\Resolver\IdentityInterface;
12+
13+
/**
14+
* Pool of IdentityInterface objects
15+
*/
16+
class IdentityPool
17+
{
18+
/**
19+
* @var IdentityInterface[]
20+
*/
21+
private $identityInstances = [];
22+
23+
/**
24+
* @var ObjectManagerInterface
25+
*/
26+
private $objectManager;
27+
28+
/**
29+
* @param ObjectManagerInterface $objectManager
30+
*/
31+
public function __construct(ObjectManagerInterface $objectManager)
32+
{
33+
$this->objectManager = $objectManager;
34+
}
35+
36+
/**
37+
* Get an identity resolver by class name
38+
*
39+
* @param string $identityClass
40+
* @return IdentityInterface
41+
*/
42+
public function get(string $identityClass): IdentityInterface
43+
{
44+
if (!isset($this->identityInstances[$identityClass])) {
45+
$this->identityInstances[$identityClass] = $this->objectManager->create($identityClass);
46+
}
47+
return $this->identityInstances[$identityClass];
48+
}
49+
}

0 commit comments

Comments
 (0)