Skip to content

Commit 59f2672

Browse files
authored
Merge pull request #8303 from magento-lynx/eav-graphql
2 parents bf37250 + b3a6b8e commit 59f2672

File tree

10 files changed

+1584
-120
lines changed

10 files changed

+1584
-120
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ input CustomerAddressInput @doc(description: "Contains details about a billing o
4949
prefix: String @doc(description: "An honorific, such as Dr., Mr., or Mrs.")
5050
suffix: String @doc(description: "A value such as Sr., Jr., or III.")
5151
vat_id: String @doc(description: "The customer's Tax/VAT number (for corporate customers).")
52-
custom_attributes: [AttributeValueInput] @doc(description: "Deprecated: Custom attributes should not be put into container.")
52+
custom_attributes: [CustomerAddressAttributeInput] @doc(description: "Deprecated. Use custom_attributesV2 instead.") @deprecated(reason: "Use custom_attributesV2 instead.")
53+
custom_attributesV2: [AttributeValueInput] @doc(description: "Custom attributes assigned to the customer address.")
5354
}
5455

5556
input CustomerAddressRegionInput @doc(description: "Defines the customer's state or province.") {
@@ -163,7 +164,7 @@ type CustomerAddress @doc(description: "Contains detailed information about a cu
163164
default_shipping: Boolean @doc(description: "Indicates whether the address is the customer's default shipping address.")
164165
default_billing: Boolean @doc(description: "Indicates whether the address is the customer's default billing address.")
165166
custom_attributes: [CustomerAddressAttribute] @deprecated(reason: "Use custom_attributesV2 instead.")
166-
custom_attributesV2: [AttributeValueInterface!]! @doc(description: "Customer address' custom attributes.")
167+
custom_attributesV2: [AttributeValueInterface!]! @doc(description: "Custom attributes assigned to the customer address.")
167168
extension_attributes: [CustomerAddressAttribute] @doc(description: "Contains any extension attributes for the address.")
168169
}
169170

@@ -175,7 +176,7 @@ type CustomerAddressRegion @doc(description: "Defines the customer's state or pr
175176

176177
type CustomerAddressAttribute @doc(description: "Specifies the attribute code and value of a customer address attribute.") {
177178
attribute_code: String @doc(description: "The name assigned to the customer address attribute.")
178-
value: String @doc(description: "The valuue assigned to the customer address attribute.")
179+
value: String @doc(description: "The value assigned to the customer address attribute.")
179180
}
180181

181182
type IsEmailAvailableOutput @doc(description: "Contains the result of the `isEmailAvailable` query.") {

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: 6 additions & 16 deletions
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
}
@@ -34,16 +34,6 @@ type StorefrontProperties @doc(description: "Indicates where an attribute can be
3434
use_in_search_results_layered_navigation: Boolean @doc(description: "Indicates whether the attribute can be used in layered navigation on search results pages.")
3535
}
3636

37-
input AttributeValueInput @doc(description: "Specifies the value for attribute.") {
38-
attribute_code: String! @doc(description: "The code of the attribute.")
39-
value: String @doc(description: "The value which should be set for the attribute")
40-
selected_options: [AttributeInputSelectedOption!] @doc(description: "An array with selected option(s) for select or multiselect attribute")
41-
}
42-
43-
input AttributeInputSelectedOption @doc(description: "Specifies selected option for dropdown or multiselect attribute value .") {
44-
value: String! @doc(description: "The attribute option value.")
45-
}
46-
4737
enum UseInLayeredNavigationOptions @doc(description: "Defines whether the attribute is filterable in layered navigation.") {
4838
NO
4939
FILTERABLE_WITH_RESULTS
@@ -150,13 +140,13 @@ interface AttributeSelectedOptionInterface @typeResolver(class: "Magento\\EavGra
150140
type AttributeSelectedOption implements AttributeSelectedOptionInterface {
151141
}
152142

153-
input AttributeValueInput {
154-
attribute_code: String! @doc(description: "The attribute code.")
155-
value: String @doc(description: "The attribute value.")
156-
selected_options: [AttributeInputSelectedOption!] @doc(description: "An array with selected option(s) for select or multiselect attribute")
143+
input AttributeValueInput @doc(description: "Specifies the value for attribute.") {
144+
attribute_code: String! @doc(description: "The code of the attribute.")
145+
value: String @doc(description: "The value assigned to the attribute.")
146+
selected_options: [AttributeInputSelectedOption!] @doc(description: "An array containing selected options for a select or multiselect attribute.")
157147
}
158148

159-
input AttributeInputSelectedOption @doc(description: "Specifies selected option for dropdown or multiselect attribute value .") {
149+
input AttributeInputSelectedOption @doc(description: "Specifies selected option for a select or multiselect attribute value.") {
160150
uid: ID! @doc(description: "Selected option UID.")
161151
value: String! @doc(description: "The attribute option value.")
162152
}

0 commit comments

Comments
 (0)