MONEI / Shopify-api-node

Node Shopify connector sponsored by MONEI
https://monei.com/shopify-payment-gateway/
MIT License
946 stars 277 forks source link

GraphQL method does not return errors #297

Closed scherroman closed 5 years ago

scherroman commented 5 years ago

Package version 2.21.0

Expected Behavior The graphql method returns the errors from the GraphQL API when encountered.

Actual Behavior The graphql method currently returns only the data, and not the errors from the GraphQL API when encountered.

In particular, when the data is empty due to an error, there is no access to the error information to understand why, or to know that there was an error at all. Try-catching has no effect as errors are only thrown when there is a json parsing error, but this makes sense as GraphQL is meant to still be able to provide data even when errors are encountered.

For example, when asking for:

let response = await shopify.graphql(`
  {
    inventoryItems(first: 1, quer: "sku:'RX 3A20'") {
      edges {
        node {
          id
          sku
        }
      }
    }
  }
`)

The response is an empty object:

{}

Whereas the GraphQL API (tested with the Shopify GraphiQL App) returns an error message:

{
  "errors": [
    {
      "message": "Field 'inventoryItems' doesn't accept argument 'quer'",
      "locations": [
        {
          "line": 20,
          "column": 28
        }
      ],
      "path": [
        "query",
        "inventoryItems",
        "quer"
      ],
      "extensions": {
        "code": "argumentNotAccepted",
        "name": "inventoryItems",
        "typeName": "Field",
        "argumentName": "quer"
      }
    }
  ]
}

Fixing the query for the method call returns the data, but without the usual wrapping { "data": ... } to provide room for an errors field:

{ inventoryItems: { edges: [ [Object] ] } }

Also, thanks for integrating GraphQL into the project! There are some features missing in the REST API like searching by query syntax, and still some missing in the GraphQL API like setting inventory levels directly, so having them both available side-by-side is very handy.

lpinca commented 5 years ago

Should be fixed by https://github.com/MONEI/Shopify-api-node/pull/291.