apollo-client: graphQLErrors not populated in thrown ApolloError during 400 NetworkError
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 callsomeActionwithout specifying therequiredParam - In the thrown
ApolloError, only thenetworkErrorproperty is set.- The
networkErroris:ServerError: Response not successful: Received status code 400. - The
graphQLErrorsis not set.
- The
- However, when using
onErrorinapollo-link-error, both thenetworkErrorand thegraphQLErrorsproperties 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
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 4
- Comments: 16 (6 by maintainers)
I can confirm that this happens in version
3.2.5as well. ThegraphQLErrorsare present in custom theonError(({ graphQLErrors, networkError })link, but when it is read within theerrorobject via auseMutationhook within a component, it is set to an empty array[]😢@hwillson Here it is: https://codesandbox.io/s/hardcore-snyder-kifgs?file=/src/App.js
If you were to add an
ErrorLinkinto the ApolloClient you would also see thatGraphQLErrorsis correctly populated. It’s only after the errors get basically wrapped by aServerErrorinHttpLinkthey get lost deeper down in the error object.I just upgraded to
3.4.7and I’m still seeing this issue.Here’s the error’s stack trace:
The error originates here: https://github.com/apollographql/apollo-client/blob/c550c57135e7293897ab4038cff43f655dcd0835/src/link/http/parseAndCheckHttpResponse.ts#L30-L37
Then it’s wrapped here: https://github.com/apollographql/apollo-client/blob/c550c57135e7293897ab4038cff43f655dcd0835/src/core/QueryManager.ts#L306-L308
I can access the graphql errors by accessing
error.networkError.result.errors.Any chance you could provide a small runnable reproduction that shows this @TriPSs?
This is still the case with
3.3.16@hwillson.