Skip to content

Commit 9c74aac

Browse files
committed
B2B-2259: customAttributeMetadata GraphQl query has no cache identity
1 parent a0e94c5 commit 9c74aac

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

app/code/Magento/EavGraphQl/Model/Resolver/Cache/CustomAttributeMetadataIdentity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class CustomAttributeMetadataIdentity implements IdentityInterface
2020
*/
2121
public function getIdentities(array $resolvedData): array
2222
{
23-
$identities = [EavAttribute::CACHE_TAG];
23+
$identities = [];
2424
if (isset($resolvedData['items']) && !empty($resolvedData['items'])) {
2525
foreach ($resolvedData['items'] as $item) {
2626
if (is_array($item)) {

dev/tests/api-functional/testsuite/Magento/GraphQl/Eav/CustomAttributesMetadataCacheTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\GraphQl\PageCache\GraphQLPageCacheAbstract;
1212
use Magento\Store\Model\StoreRepository;
1313
use Magento\TestFramework\Helper\Bootstrap;
14+
use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException;
1415

1516
class CustomAttributesMetadataCacheTest extends GraphQLPageCacheAbstract
1617
{
@@ -176,6 +177,55 @@ public function testCacheInvalidation()
176177
);
177178
}
178179

180+
/**
181+
* @magentoApiDataFixture Magento/Catalog/_files/dropdown_attribute.php
182+
* @magentoConfigFixture default/system/full_page_cache/caching_application 2
183+
*
184+
* @return void
185+
*/
186+
public function testCacheInvalidationOnAttributeDelete()
187+
{
188+
$query = $this->getAttributeQuery("dropdown_attribute", "catalog_product");
189+
// check cache missed on first query
190+
$response = $this->assertCacheMissAndReturnResponse($query, []);
191+
$this->assertResponseFields(
192+
$response['body']['customAttributeMetadata']['items'][0],
193+
[
194+
'attribute_code' => 'dropdown_attribute',
195+
'attribute_type' => 'String',
196+
'entity_type' => 'catalog_product',
197+
'input_type' => 'select',
198+
]
199+
);
200+
// assert cache hit on second query
201+
$this->assertCacheHitAndReturnResponse($query, []);
202+
/** @var AttributeRepository $eavAttributeRepo */
203+
$eavAttributeRepo = $this->objectManager->get(AttributeRepository::class);
204+
$attribute = $eavAttributeRepo->get("catalog_product", "dropdown_attribute");
205+
$eavAttributeRepo->delete($attribute);
206+
$caughtException = null;
207+
try {
208+
// get response
209+
$response = $this->graphQlQuery($query, []);
210+
} catch (ResponseContainsErrorsException $exception) {
211+
$caughtException = $exception;
212+
}
213+
$this->assertInstanceOf(
214+
ResponseContainsErrorsException::class,
215+
$caughtException
216+
);
217+
// cannot use expectException because need to assert the headers
218+
$this->assertStringContainsString(
219+
"GraphQL response contains errors: Internal server error",
220+
$caughtException->getMessage()
221+
);
222+
// assert that it's a miss after deletion
223+
$this->assertEquals(
224+
$response['headers']['X-Magento-Cache-Debug'],
225+
'MISS'
226+
);
227+
}
228+
179229
/**
180230
* Test cache invalidation when queried for attribute data of different entity types.
181231
* Required for GraphQL FPC use-case since there is no attribute ID provided in the result.

dev/tests/integration/testsuite/Magento/Catalog/_files/dropdown_attribute_rollback.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
'Magento\Catalog\Model\ResourceModel\Eav\Attribute'
1313
);
1414
$attribute->load('dropdown_attribute', 'attribute_code');
15-
$attribute->delete();
15+
if ($attribute->getAttributeId()) {
16+
$attribute->delete();
17+
}
1618

1719
$registry->unregister('isSecureArea');
1820
$registry->register('isSecureArea', false);

0 commit comments

Comments
 (0)