Skip to content

Commit b3d7b83

Browse files
authored
[LYNX] Small fixes for Customer and Customer Address EAV in GraphQL (#110)
1 parent f1a3898 commit b3d7b83

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

app/code/Magento/EavGraphQl/Model/Resolver/AttributesForm.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,18 @@ public function resolve(
5151
array $value = null,
5252
array $args = null
5353
) {
54-
if (empty($args['type'])) {
55-
throw new GraphQlInputException(__('Required parameter "%1" of type string.', 'type'));
54+
if (empty($args['formCode'])) {
55+
throw new GraphQlInputException(__('Required parameter "%1" of type string.', 'formCode'));
5656
}
5757

58-
$attributes = $this->getAttributesFormComposite->execute($args['type']);
59-
if ($this->isAdminFormType($args['type']) || $attributes === null) {
58+
$attributes = $this->getAttributesFormComposite->execute($args['formCode']);
59+
if ($this->isAnAdminForm($args['formCode']) || $attributes === null) {
6060
return [
6161
'items' => [],
6262
'errors' => [
6363
[
6464
'type' => 'ENTITY_NOT_FOUND',
65-
'message' => (string) __('Form "%form" could not be found.', ['form' => $args['type']])
65+
'message' => (string) __('Form "%form" could not be found.', ['form' => $args['formCode']])
6666
]
6767
]
6868
];
@@ -75,13 +75,13 @@ public function resolve(
7575
}
7676

7777
/**
78-
* Check if passed form type is an admin form
78+
* Check if passed form formCode is an admin form.
7979
*
80-
* @param string $type
80+
* @param string $formCode
8181
* @return bool
8282
*/
83-
private function isAdminFormType(string $type): bool
83+
private function isAnAdminForm(string $formCode): bool
8484
{
85-
return str_starts_with($type, 'adminhtml_');
85+
return str_starts_with($formCode, 'adminhtml_');
8686
}
8787
}

app/code/Magento/EavGraphQl/Model/Resolver/AttributesList.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use Magento\EavGraphQl\Model\Output\GetAttributeDataInterface;
2020

2121
/**
22-
* Resolve attribute options data for custom attribute.
22+
* Returns a list of attributes metadata for a given entity type.
2323
*/
2424
class AttributesList implements ResolverInterface
2525
{
@@ -103,7 +103,7 @@ public function resolve(
103103

104104
$attributesList = $this->attributeRepository->getList(strtolower($entityType), $searchCriteria)->getItems();
105105
return [
106-
'items' => $this->getAtrributesMetadata($attributesList, $entityType, $storeId),
106+
'items' => $this->getAttributesMetadata($attributesList, $entityType, $storeId),
107107
'errors' => $errors
108108
];
109109
}
@@ -116,8 +116,9 @@ public function resolve(
116116
* @param int $storeId
117117
*
118118
* @return array[]
119+
* @throws RuntimeException
119120
*/
120-
private function getAtrributesMetadata(array $attributesList, string $entityType, int $storeId): array
121+
private function getAttributesMetadata(array $attributesList, string $entityType, int $storeId): array
121122
{
122123
return array_map(function (AttributeInterface $attribute) use ($entityType, $storeId): array {
123124
return $this->getAttributeData->execute($attribute, strtolower($entityType), $storeId);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ type Query {
99
@cache(cacheIdentity: "Magento\\EavGraphQl\\Model\\Resolver\\Cache\\CustomAttributeMetadataIdentity")
1010
@deprecated(reason: "Use `customAttributeMetadataV2` query instead.")
1111
customAttributeMetadataV2(attributes: [AttributeInput!]): AttributesMetadataOutput! @resolver(class: "Magento\\EavGraphQl\\Model\\Resolver\\AttributesMetadata") @doc(description: "Retrieve EAV attributes metadata.")
12-
attributesForm(type: String! @doc(description: "Form type")): AttributesFormOutput! @resolver(class: "Magento\\EavGraphQl\\Model\\Resolver\\AttributesForm") @doc(description: "Retrieve EAV attributes associated to a frontend form.")
13-
attributesList(entityType: AttributeEntityTypeEnum! @doc(description: "Entity type.")): AttributesMetadataOutput @resolver(class: "Magento\\EavGraphQl\\Model\\Resolver\\AttributesList") @doc(description: "Returns list of atributes metadata for given entity type.") @cache(cacheable: false)
12+
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.")
13+
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
}
1515

1616
type CustomAttributeMetadata @doc(description: "Defines an array of custom attributes.") {

dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/Attribute/AttributesFormTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class AttributesFormTest extends GraphQlAbstract
2121
{
2222
private const QUERY = <<<QRY
2323
{
24-
attributesForm(type: "%s") {
24+
attributesForm(formCode: "%s") {
2525
items {
2626
uid
2727
code

0 commit comments

Comments
 (0)