magento / graphql-ce

[ARCHIVED] Please use magento/magento2 project
https://github.com/magento/magento2
Open Software License 3.0
131 stars 155 forks source link

Postcode is not listed in the array of errors #1029

Closed TomashKhamlai closed 5 years ago

TomashKhamlai commented 5 years ago

Preconditions (*)

No preconditions

Steps to reproduce (*)

  1. Perform mutation as a Customer
    mutation {
    createCustomerAddress(
      input: {
        country_id: AF
        #country_code: "AF"
        city: "1"
        firstname: "2"
        lastname: "3"
      }
    ) {
      country_id
      #country_code
      city
      firstname
      lastname
    }
    }

    Expected result (*)

    {
    "errors": [
    {
      "message": "Required parameters are missing: street, telephone, postcode",
      "extensions": {
        "category": "graphql-input"
      },
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "createCustomerAddress"
      ]
    }
    ],
    "data": {
    "createCustomerAddress": null
    }
    }

Actual result (*)

{
  "errors": [
    {
      "message": "Required parameters are missing: street, telephone",
      "extensions": {
        "category": "graphql-input"
      },
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "createCustomerAddress"
      ]
    }
  ],
  "data": {
    "createCustomerAddress": null
  }
}
osrecio commented 5 years ago

I checked this issue but:

The postcode in the table eav_attribute the column is_required is set to 0.

The implementation on the file: \Magento\CustomerGraphQl\Model\Customer\Address\CreateCustomerAddress::validateData

foreach ($attributes as $attributeName => $attributeInfo) {
            if ($attributeInfo->getIsRequired()
                && (!isset($addressData[$attributeName]) || empty($addressData[$attributeName]))
            ) {
                $errorInput[] = $attributeName;
            }
        }

if the postcode field is not required, so I think the behaviour is ok.

We have 2 options: 1) Add is_required in table eav_attribute. This can be a problem... for BC and the other implementations. 2) Add to validate data something like:

foreach ($attributes as $attributeName => $attributeInfo) {
            if (($attrtibuteName == 'postcode' && && (!isset($addressData[$attributeName]) || empty($addressData[$attributeName])) || $attributeInfo->getIsRequired()
                && (!isset($addressData[$attributeName]) || empty($addressData[$attributeName]))
            ) {
                $errorInput[] = $attributeName;
            }
        } 
osrecio commented 5 years ago

I saw the validation after save. Creating a PR

magento-engcom-team commented 5 years ago

Hi @TomashKhamlai. Thank you for your report. The issue has been fixed in magento/graphql-ce#1031 by @osrecio in 2.3-develop branch Related commit(s):

The fix will be available with the upcoming 2.3.5 release.