Skip to content

Commit

Permalink
[LYNX] Small fixes for Customer and Customer Address EAV in GraphQL (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
loginesta authored May 4, 2023
1 parent f1a3898 commit b3d7b83
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
18 changes: 9 additions & 9 deletions app/code/Magento/EavGraphQl/Model/Resolver/AttributesForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']])
]
]
];
Expand All @@ -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_');
}
}
7 changes: 4 additions & 3 deletions app/code/Magento/EavGraphQl/Model/Resolver/AttributesList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
];
}
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/EavGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -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.") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AttributesFormTest extends GraphQlAbstract
{
private const QUERY = <<<QRY
{
attributesForm(type: "%s") {
attributesForm(formCode: "%s") {
items {
uid
code
Expand Down

0 comments on commit b3d7b83

Please sign in to comment.