Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQL does not throw mutation errors #439

Open
chris-rudmin opened this issue Dec 2, 2020 · 3 comments
Open

GraphQL does not throw mutation errors #439

chris-rudmin opened this issue Dec 2, 2020 · 3 comments

Comments

@chris-rudmin
Copy link

When doing a mutation shopify.graphql(mutationQuery) where the query is a mutation such as:

mutation {
  customerCreate(
    input: {
      ...
    }
  )
  {
    customer {
      id
      displayName
    }
    userErrors {
      field
      message
    }
  }
}

Errors are returned in the userErrors field. However the request promise resolves successfully. I was expecting the error to be thrown as it is done for normal queries.

@lpinca
Copy link
Collaborator

lpinca commented Dec 2, 2020

The field used to check for errors is errors:

Shopify-api-node/index.js

Lines 236 to 246 in c949c7d

if (res.body.errors) {
const first = res.body.errors[0];
const err = new Error(first.message);
err.locations = first.locations;
err.path = first.path;
err.extensions = first.extensions;
err.response = res;
throw err;
}

@chris-rudmin
Copy link
Author

@lpinca I see that. According to all the Shopify docs I have seen. Mutation queries will have any error in the field userErrors

Some example doc references:
https://shopify.dev/docs/admin-api/graphql/reference/customers/customeraddtaxexemptions
https://shopify.dev/docs/admin-api/graphql/reference/customers/customercreate
https://shopify.dev/docs/admin-api/graphql/reference/orders/ordereditsetquantity

@lpinca
Copy link
Collaborator

lpinca commented Dec 3, 2020

Feel free to open a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants