Skip to content

Commit 6f665ea

Browse files
committed
B2B-2451: Implement GraphQL Resolver Cache for CMS Page Type
1 parent b877306 commit 6f665ea

File tree

3 files changed

+58
-16
lines changed

3 files changed

+58
-16
lines changed

app/code/Magento/CmsGraphQl/etc/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9-
<type name="Magento\GraphQlCache\Observer\InvalidateGraphQlResolverCacheObserver">
9+
<type name="Magento\GraphQlCache\Model\Cache\Query\Resolver\TagResolver">
1010
<arguments>
1111
<argument name="invalidatableObjectTypes" xsi:type="array">
1212
<item name="Magento\Cms\Api\Data\PageInterface" xsi:type="string">
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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\Cache\Query\Resolver;
9+
10+
use Magento\Framework\App\Cache\Tag\Resolver;
11+
use Magento\Framework\App\Cache\Tag\Strategy\Factory as StrategyFactory;
12+
13+
class TagResolver extends Resolver
14+
{
15+
/**
16+
* @var array
17+
*/
18+
private $invalidatableObjectTypes;
19+
20+
/**
21+
* GraphQL Resolver cache-specific tag resolver for the purpose of invalidation
22+
*
23+
* @param StrategyFactory $factory
24+
* @param array $invalidatableObjectTypes
25+
*/
26+
public function __construct(
27+
StrategyFactory $factory,
28+
array $invalidatableObjectTypes = []
29+
) {
30+
$this->invalidatableObjectTypes = $invalidatableObjectTypes;
31+
32+
parent::__construct($factory);
33+
}
34+
35+
/**
36+
* @inheritdoc
37+
*/
38+
public function getTags($object)
39+
{
40+
$isInvalidatable = false;
41+
42+
foreach ($this->invalidatableObjectTypes as $invalidatableObjectType) {
43+
$isInvalidatable = $object instanceof $invalidatableObjectType;
44+
45+
if ($isInvalidatable) {
46+
break;
47+
}
48+
}
49+
50+
if (!$isInvalidatable) {
51+
return [];
52+
}
53+
54+
return parent::getTags($object);
55+
}
56+
}

app/code/Magento/GraphQlCache/Observer/InvalidateGraphQlResolverCacheObserver.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
namespace Magento\GraphQlCache\Observer;
99

1010
use Magento\Framework\App\Cache\StateInterface as CacheState;
11-
use Magento\Framework\App\Cache\Tag\Resolver as TagResolver;
1211
use Magento\Framework\Event\ObserverInterface;
1312
use Magento\Framework\Event\Observer;
13+
use Magento\GraphQlCache\Model\Cache\Query\Resolver\TagResolver as TagResolver;
1414
use Magento\GraphQlCache\Model\Cache\Query\Resolver\Result\Type as GraphQlResolverCache;
1515

1616
class InvalidateGraphQlResolverCacheObserver implements ObserverInterface
@@ -72,20 +72,6 @@ public function execute(Observer $observer)
7272
return;
7373
}
7474

75-
$isInvalidatable = false;
76-
77-
foreach ($this->invalidatableObjectTypes as $invalidatableObjectType) {
78-
$isInvalidatable = $object instanceof $invalidatableObjectType;
79-
80-
if ($isInvalidatable) {
81-
break;
82-
}
83-
}
84-
85-
if (!$isInvalidatable) {
86-
return;
87-
}
88-
8975
$tags = $this->tagResolver->getTags($object);
9076

9177
if (!empty($tags)) {

0 commit comments

Comments
 (0)