Skip to content

Commit 6c4024f

Browse files
LYNX-149: Cache identity for attributesMetadata query (#114)
* LYNX-149: Cache identity for attributesMetadata query
1 parent 29519af commit 6c4024f

File tree

4 files changed

+423
-1
lines changed

4 files changed

+423
-1
lines changed

app/code/Magento/EavGraphQl/Model/Output/GetAttributeData.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public function execute(
6363
int $storeId
6464
): array {
6565
return [
66+
'id' => $attribute->getAttributeId(),
6667
'uid' => $this->attributeUid->encode($entityType, $attribute->getAttributeCode()),
6768
'code' => $attribute->getAttributeCode(),
6869
'label' => $attribute->getStoreLabel($storeId),
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\EavGraphQl\Model\Resolver\Cache;
9+
10+
use Magento\Eav\Model\Entity\Attribute as EavAttribute;
11+
use Magento\Framework\GraphQl\Query\Resolver\IdentityInterface;
12+
13+
/**
14+
* Cache identity provider for custom attribute metadata query results.
15+
*/
16+
class CustomAttributeMetadataV2Identity implements IdentityInterface
17+
{
18+
/**
19+
* @inheritDoc
20+
*/
21+
public function getIdentities(array $resolvedData): array
22+
{
23+
$identities = [];
24+
if (isset($resolvedData['items']) && !empty($resolvedData['items'])) {
25+
foreach ($resolvedData['items'] as $item) {
26+
if (is_array($item)) {
27+
$identities[] = sprintf(
28+
"%s_%s",
29+
EavAttribute::CACHE_TAG,
30+
$item['id']
31+
);
32+
}
33+
}
34+
} else {
35+
return [];
36+
}
37+
return $identities;
38+
}
39+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type Query {
88
@doc(description: "Return the attribute type, given an attribute code and entity type.")
99
@cache(cacheIdentity: "Magento\\EavGraphQl\\Model\\Resolver\\Cache\\CustomAttributeMetadataIdentity")
1010
@deprecated(reason: "Use `customAttributeMetadataV2` query instead.")
11-
customAttributeMetadataV2(attributes: [AttributeInput!]): AttributesMetadataOutput! @resolver(class: "Magento\\EavGraphQl\\Model\\Resolver\\AttributesMetadata") @doc(description: "Retrieve EAV attributes metadata.")
11+
customAttributeMetadataV2(attributes: [AttributeInput!]): AttributesMetadataOutput! @resolver(class: "Magento\\EavGraphQl\\Model\\Resolver\\AttributesMetadata") @doc(description: "Retrieve EAV attributes metadata.") @cache(cacheIdentity: "Magento\\EavGraphQl\\Model\\Resolver\\Cache\\CustomAttributeMetadataV2Identity")
1212
attributesForm(formCode: String! @doc(description: "Form code.")): AttributesFormOutput! @resolver(class: "Magento\\EavGraphQl\\Model\\Resolver\\AttributesForm") @doc(description: "Retrieve EAV attributes associated to a frontend form.")
1313
attributesList(entityType: AttributeEntityTypeEnum! @doc(description: "Entity type.")): AttributesMetadataOutput @resolver(class: "Magento\\EavGraphQl\\Model\\Resolver\\AttributesList") @doc(description: "Returns a list of attributes metadata for a given entity type.") @cache(cacheable: false)
1414
}

0 commit comments

Comments
 (0)