vtex-apps / store-graphql

GraphQL schema and resolvers for the VTEX Commerce Stores API
78 stars 45 forks source link

add fallback value #663

Closed beatrizmaselli closed 4 months ago

beatrizmaselli commented 5 months ago

What problem is this solving?

Error when saving address in Ireland:

image

This API fails when the administrativeAreaLevel1 is null due to the schema validation:

image

How to test it?

Try add a new address at my account for ireland at the master and after at this workspace:

Workspace

How does this PR make you feel? :link:

vtex-io-ci-cd[bot] commented 5 months ago

Hi! I'm VTEX IO CI/CD Bot and I'll be helping you to publish your app! 🤖

Please select which version do you want to release:

And then you just need to merge your PR when you are ready! There is no need to create a release commit/tag.

vmourac-vtex commented 4 months ago

Testes Realizados

Teste em ambiente sem Fix

Resultado: Erro replicado como esperado

Passo a passo:

Acessar o Admin da Loja e submeter a seguinte query:

mutation SaveAddress($address: AddressInput!) {
  saveAddress(address: $address) {
    id
    cacheId
  }
}

Com os seguintes parâmetros:

{
  "address": {
    "addressType":"residential",
    "city":"Dublin",
    "complement":null,
    "country":"IRL",
    "receiverName":"Victor Cortez",
    "geoCoordinates":[],
    "neighborhood":null,
    "number":null,
    "postalCode":"D08 H6X3",
    "reference":null,
    "state":null,
    "street":"Teste GraphiQL - SEM Fix"}
}

O teste falha, como esperado, com a mensagem de erro:

{
  "data": null,
  "errors": [
    {
      "message": "Request failed with status code 400",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "vtex_storegraphql_2_170_2_saveAddress"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "message": "Request failed with status code 400",
          "name": "UserInputError",
          "status": 400,
          "code": "BAD_USER_INPUT",
          "level": "warn",
          "response": {
            "data": {
              "content": null,
              "status": "UserInputError",
              "message": "Error on schema validation:\n\n\tStringExpected: #/administrativeAreaLevel1"
            },
            "headers": {
              "content-length": "130",
              "content-type": "application/json; charset=utf-8",
              "date": "Mon, 24 Jun 2024 14:44:24 GMT",
              "server": "VTEX IO",
              "set-cookie": [
                "janus_sid=7fc219c9-8931-4646-9f75-e00ab6ef3f9e; expires=Thu, 27 Jun 2024 14:44:02 GMT; domain=portal.vtexcommercestable.com.br; path=/; samesite=lax"
              ],
              "x-envoy-decorator-operation": "profile-system.profile-system-stable.svc.cluster.local:80/*",
              "x-envoy-upstream-service-time": "316",
              "x-vtex-janus-router-backend-app": "storage-pf-vstable-eu-g1d",
              "x-vtex-operation-id": "0771d2f7-1c6b-4717-828e-d5f68e7d5a81",
              "x-request-id": "18a9a66e94fb4b93b470c296efcfedf8",
              "x-vtex-router-version": "9.15.7",
              "x-vtex-backend-status-code": "BadRequest",
              "x-vtex-backend-elapsed-time": "00:00:00.3894808",
              "x-vtex-router-elapsed-time": "00:00:00.4039510",
              "x-vtex-io-cluster-id": "prod-dj-iodev-eks-use1a-n1c"
            },
            "status": 400
          },
          "stacktrace": [
            "Error: Request failed with status code 400",
            "    at createError (/usr/local/app/node_modules/axios/lib/core/createError.js:16:15)",
            "    at settle (/usr/local/app/node_modules/axios/lib/core/settle.js:18:12)",
            "    at IncomingMessage.handleStreamEnd (/usr/local/app/node_modules/axios/lib/adapters/http.js:202:11)",
            "    at IncomingMessage.emit (events.js:208:15)",
            "    at endReadableNT (_stream_readable.js:1168:12)",
            "    at processTicksAndRejections (internal/process/task_queues.js:77:11)"
          ],
          "sensitive": {
            "config": {
              "baseURL": "http://portal.vtexcommercestable.com.br",
              "data": "{\"administrativeAreaLevel1\":null,\"addressName\":\"o6nwbpxrvl\",\"addressType\":\"residential\",\"countryCode\":\"IRL\",\"complement\":\"\",\"geoCoordinates\":[],\"locality\":\"Dublin\",\"localityAreaLevel1\":\"\",\"name\":\"o6nwbpxrvl\",\"nearly\":\"\",\"postalCode\":\"D08 H6X3\",\"route\":\"Teste GraphiQL - SEM Fix\",\"streetNumber\":\"\",\"receiverName\":\"Victor Cortez\"}",
              "headers": {
                "Accept": "application/json, text/plain, */*",
                "Content-Type": "application/json;charset=utf-8",
                "accept-encoding": "gzip",
                "user-agent": "vtex.store-graphql@2.170.2",
                "x-forwarded-host": "victormoura--dunnesstoresqa.myvtex.com",
                "x-vtex-tenant": "en-GB",
                "x-vtex-binding": "eyJpZCI6ImVjODkzZmEzLTM4ZGItNDE3Ni05ZDMwLTUzY2RkNGVmZTcyMCIsImxvY2FsZSI6ImVuLUdCIn0=",
                "x-vtex-locale": "en-GB",
                "x-vtex-operation-id": "0771d2f7-1c6b-4717-828e-d5f68e7d5a81",
                "x-vtex-segment": "eyJjYW1wYWlnbnMiOm51bGwsImNoYW5uZWwiOiIxIiwicHJpY2VUYWJsZXMiOm51bGwsInJlZ2lvbklkIjpudWxsLCJ1dG1fY2FtcGFpZ24iOm51bGwsInV0bV9zb3VyY2UiOm51bGwsInV0bWlfY2FtcGFpZ24iOm51bGwsImN1cnJlbmN5Q29kZSI6IkVVUiIsImN1cnJlbmN5U3ltYm9sIjoi4oKsIiwiY291bnRyeUNvZGUiOiJJUkwiLCJjdWx0dXJlSW5mbyI6ImVuLUdCIiwiYWRtaW5fY3VsdHVyZUluZm8iOiJlbi1VUyIsImNoYW5uZWxQcml2YWN5IjoicHVibGljIn0",
                "x-vtex-session": "eyJhbGciOiJFUzI1NiIsImtpZCI6IjZBNEI1MDE2RDYyOTYzNjk1OTE5QURENzkzQjdBRTU5RUZENzI4REIiLCJ0eXAiOiJqd3QifQ.eyJhY2NvdW50LmlkIjoiOTRlM2JhYWQtMmQxOC00ZDY4LThjNzYtMmY5ZTBjMmY2MDBiIiwiaWQiOiI3ZGNhNjBmZS03MGFiLTRmOTktOTg5Ny04ZDkyNDE3NzE5ZDkiLCJ2ZXJzaW9uIjo3LCJzdWIiOiJzZXNzaW9uIiwiYWNjb3VudCI6InNlc3Npb24iLCJleHAiOjE3MTk5Mjg1MTUsImlhdCI6MTcxOTIzNzMxNSwiaXNzIjoidG9rZW4tZW1pdHRlciIsImp0aSI6IjZjMGUyNGUyLThmNDEtNDE5Zi04MGU2LTQ5MDIwOWM1MzJmNSJ9.g0GrnA1XQsu3FU4Uh3KTpfCZunbPz-1rUjnJjY092El5aVWpd57kxYJZNsPk1CTVF-JmTUJsRLsdaUPG0eS55Q",
                "Content-Length": 328
              },
              "method": "post",
              "timeout": 5000,
              "url": "http://portal.vtexcommercestable.com.br/api/storage/profile-system/profiles/dc7716f7-cafb-4675-bbad-b4f14be60903/addresses",
              "metric": "profile-system-v2-createAddress",
              "params": {
                "an": "dunnesstoresqa"
              }
            },
            "request": {
              "finished": true,
              "method": "POST",
              "path": "/api/storage/profile-system/profiles/dc7716f7-cafb-4675-bbad-b4f14be60903/addresses?an=dunnesstoresqa"
            },
            "stack": "Error: Request failed with status code 400\n    at createError (/usr/local/app/node_modules/axios/lib/core/createError.js:16:15)\n    at settle (/usr/local/app/node_modules/axios/lib/core/settle.js:18:12)\n    at IncomingMessage.handleStreamEnd (/usr/local/app/node_modules/axios/lib/adapters/http.js:202:11)\n    at IncomingMessage.emit (events.js:208:15)\n    at endReadableNT (_stream_readable.js:1168:12)\n    at processTicksAndRejections (internal/process/task_queues.js:77:11)"
          }
        }
      },
      "positions": [
        76
      ],
      "name": "GraphQLError",
      "source": {
        "body": "mutation SaveAddress($address: vtex_storegraphql_2_170_2_AddressInput!) {\n  saveAddress: vtex_storegraphql_2_170_2_saveAddress(address: $address) {\n    id: vtex_storegraphql_2_170_2_id\n    cacheId: vtex_storegraphql_2_170_2_cacheId\n  }\n}\n",
        "name": "GraphQL request",
        "locationOffset": {
          "line": 1,
          "column": 1
        }
      },
      "operationId": "0771d2f7-1c6b-4717-828e-d5f68e7d5a81",
      "requestId": "957c4b378c7646c7b7a45b58c22cf6a2"
    }
  ]
}

Evidência: erro-esperado

Erro na UI da Loja

Teste em ambiente com Fix aplicado:

Resultado: Correção validada com sucesso

Passo a passo:

Acessar o Admin da Loja e submeter a seguinte query:

mutation SaveAddress($address: AddressInput!) {
  saveAddress(address: $address) {
    id
    cacheId
  }
}

Com os seguintes parâmetros:

{
  "address": {
    "addressType":"residential",
    "city":"Dublin",
    "complement":null,
    "country":"IRL",
    "receiverName":"Victor Cortez",
    "geoCoordinates":[],
    "neighborhood":null,
    "number":null,
    "postalCode":"D08 H6X3",
    "reference":null,
    "state":null,
    "street":"Teste GraphiQL - COM Fix"}
}

O teste não dá erros, como esperado, com a mensagem de retornada:

{
  "data": {
    "saveAddress": {
      "id": null,
      "cacheId": null
    }
  }
}

Evidência: Teste Fix Aplicado Com Sucesso - GraphQL

Fix na UI da Loja

vtex-io-ci-cd[bot] commented 4 months ago

Your PR has been merged! App is being published. :rocket: Version 2.170.3 → 2.170.4

After the publishing process has been completed (check #vtex-io-releases) and doing A/B tests with the new version, you can deploy your release by running:

vtex deploy vtex.store-graphql@2.170.4

After that your app will be updated on all accounts.

For more information on the deployment process check the docs. :book: