From b3d7b832dad37814bd7a6586974f99ce4db20f10 Mon Sep 17 00:00:00 2001 From: Marc Ginesta Date: Thu, 4 May 2023 10:49:55 +0200 Subject: [PATCH] [LYNX] Small fixes for Customer and Customer Address EAV in GraphQL (#110) --- .../Model/Resolver/AttributesForm.php | 18 +++++++++--------- .../Model/Resolver/AttributesList.php | 7 ++++--- .../Magento/EavGraphQl/etc/schema.graphqls | 4 ++-- .../Customer/Attribute/AttributesFormTest.php | 2 +- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/app/code/Magento/EavGraphQl/Model/Resolver/AttributesForm.php b/app/code/Magento/EavGraphQl/Model/Resolver/AttributesForm.php index 5cd8ab4e76549..8b86fc606ff74 100644 --- a/app/code/Magento/EavGraphQl/Model/Resolver/AttributesForm.php +++ b/app/code/Magento/EavGraphQl/Model/Resolver/AttributesForm.php @@ -51,18 +51,18 @@ public function resolve( array $value = null, array $args = null ) { - if (empty($args['type'])) { - throw new GraphQlInputException(__('Required parameter "%1" of type string.', 'type')); + if (empty($args['formCode'])) { + throw new GraphQlInputException(__('Required parameter "%1" of type string.', 'formCode')); } - $attributes = $this->getAttributesFormComposite->execute($args['type']); - if ($this->isAdminFormType($args['type']) || $attributes === null) { + $attributes = $this->getAttributesFormComposite->execute($args['formCode']); + if ($this->isAnAdminForm($args['formCode']) || $attributes === null) { return [ 'items' => [], 'errors' => [ [ 'type' => 'ENTITY_NOT_FOUND', - 'message' => (string) __('Form "%form" could not be found.', ['form' => $args['type']]) + 'message' => (string) __('Form "%form" could not be found.', ['form' => $args['formCode']]) ] ] ]; @@ -75,13 +75,13 @@ public function resolve( } /** - * Check if passed form type is an admin form + * Check if passed form formCode is an admin form. * - * @param string $type + * @param string $formCode * @return bool */ - private function isAdminFormType(string $type): bool + private function isAnAdminForm(string $formCode): bool { - return str_starts_with($type, 'adminhtml_'); + return str_starts_with($formCode, 'adminhtml_'); } } diff --git a/app/code/Magento/EavGraphQl/Model/Resolver/AttributesList.php b/app/code/Magento/EavGraphQl/Model/Resolver/AttributesList.php index 22a57f84922b5..357ef10b80e3e 100644 --- a/app/code/Magento/EavGraphQl/Model/Resolver/AttributesList.php +++ b/app/code/Magento/EavGraphQl/Model/Resolver/AttributesList.php @@ -19,7 +19,7 @@ use Magento\EavGraphQl\Model\Output\GetAttributeDataInterface; /** - * Resolve attribute options data for custom attribute. + * Returns a list of attributes metadata for a given entity type. */ class AttributesList implements ResolverInterface { @@ -103,7 +103,7 @@ public function resolve( $attributesList = $this->attributeRepository->getList(strtolower($entityType), $searchCriteria)->getItems(); return [ - 'items' => $this->getAtrributesMetadata($attributesList, $entityType, $storeId), + 'items' => $this->getAttributesMetadata($attributesList, $entityType, $storeId), 'errors' => $errors ]; } @@ -116,8 +116,9 @@ public function resolve( * @param int $storeId * * @return array[] + * @throws RuntimeException */ - private function getAtrributesMetadata(array $attributesList, string $entityType, int $storeId): array + private function getAttributesMetadata(array $attributesList, string $entityType, int $storeId): array { return array_map(function (AttributeInterface $attribute) use ($entityType, $storeId): array { return $this->getAttributeData->execute($attribute, strtolower($entityType), $storeId); diff --git a/app/code/Magento/EavGraphQl/etc/schema.graphqls b/app/code/Magento/EavGraphQl/etc/schema.graphqls index f5e47c9ac9047..8afb7aeb8ab0c 100644 --- a/app/code/Magento/EavGraphQl/etc/schema.graphqls +++ b/app/code/Magento/EavGraphQl/etc/schema.graphqls @@ -9,8 +9,8 @@ type Query { @cache(cacheIdentity: "Magento\\EavGraphQl\\Model\\Resolver\\Cache\\CustomAttributeMetadataIdentity") @deprecated(reason: "Use `customAttributeMetadataV2` query instead.") customAttributeMetadataV2(attributes: [AttributeInput!]): AttributesMetadataOutput! @resolver(class: "Magento\\EavGraphQl\\Model\\Resolver\\AttributesMetadata") @doc(description: "Retrieve EAV attributes metadata.") - 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.") - 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) + 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.") + 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) } type CustomAttributeMetadata @doc(description: "Defines an array of custom attributes.") { diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/Attribute/AttributesFormTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/Attribute/AttributesFormTest.php index 9414ee53bdf75..a086f833fc0a6 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/Attribute/AttributesFormTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/Attribute/AttributesFormTest.php @@ -21,7 +21,7 @@ class AttributesFormTest extends GraphQlAbstract { private const QUERY = <<