question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

graphQLErrors not populated in thrown ApolloError during 400 NetworkError

See original GitHub issue

The graphQlErrors property of ApolloError is not populated with the error details when a schema required field is not supplied during a mutation. However, the error is sent correctly to onError().

Intended outcome: ApolloError.graphQLErrors to be populated with the GraphQL error information

Actual outcome: ApolloError.graphQLErrors is an empty array

How to reproduce the issue:

  • Begin with the schema:
type Mutation {
  someAction(requiredParam: String!): Boolean
}
  • Use apolloClient.mutate(...) to call someAction without specifying the requiredParam
  • In the thrown ApolloError, only the networkError property is set.
    • The networkError is: ServerError: Response not successful: Received status code 400.
    • The graphQLErrors is not set.
  • However, when using onError in apollo-link-error, both the networkError and the graphQLErrors properties are populated correctly.

Versions

  System:
    OS: Linux 4.19 Ubuntu 18.04.3 LTS (Bionic Beaver)
  Binaries:
    Node: 12.13.0 - /usr/bin/node
    Yarn: 1.22.4 - ~/.yarn/bin/yarn
    npm: 6.12.0 - /usr/bin/npm
  Browsers:
    Chrome: 81.0.4044.113
  npmPackages:
    apollo-cache-inmemory: ^1.6.5 => 1.6.5
    apollo-client: ^2.6.8 => 2.6.8
    apollo-link-error: ^1.1.13 => 1.1.13
    apollo-link-http: ^1.5.17 => 1.5.17
    apollo-server: ^2.12.0 => 2.12.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:16 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
r0ughnexcommented, Oct 26, 2020

I can confirm that this happens in version 3.2.5 as well. The graphQLErrors are present in custom the onError(({ graphQLErrors, networkError }) link, but when it is read within the error object via a useMutation hook within a component, it is set to an empty array [] 😢 graphQLErrors_Empty

2reactions
ParallelUniv3rsecommented, May 6, 2021

@hwillson Here it is: https://codesandbox.io/s/hardcore-snyder-kifgs?file=/src/App.js

If you were to add an ErrorLink into the ApolloClient you would also see that GraphQLErrors is correctly populated. It’s only after the errors get basically wrapped by a ServerError in HttpLink they get lost deeper down in the error object.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling operation errors - Apollo GraphQL Docs
If the response includes GraphQL errors, they are returned on error.graphQLErrors and the response data is set to undefined even if the server...
Read more >
GraphQL Error Handling with ApolloClient and Apollo-Server ...
This is by design. From the docs: graphQLErrors: An array of errors from the GraphQL endpoint; networkError: Any error during the link ...
Read more >
Handling Errors with Apollo Client (React) - YouTube
In this video I talk about handling errors when running queries and ... and networkError ) 10:04 Handling GraphQL errors when running a...
Read more >
Hygraph error codes
400 errors are typically thrown when there is a client-side validation error, such as a missing required argument in your GraphQL query, or...
Read more >
Automatically handling Apollo Client errors in your React UI
The graphQLErrors property that it provides to the onError error link will be populated with the errors, but the data will be undefined...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found