-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
GraphQLErrors from mutation not available in ApolloError #8503
Labels
Comments
Thanks for the reproduction @atstojanov! Possibly related: #6222 |
1 task
I have defined and used the following helper function to get the validation errors generated by mutation. export const formatApolloError = (error?: ApolloError): ApolloError | undefined => {
if (!error) return undefined;
if (
error.networkError &&
'result' in error.networkError &&
'errors' in error.networkError.result &&
error.networkError.result.errors.length
) {
const networkError = error.networkError.result.errors[0];
if (networkError.extensions.code === 'BAD_USER_INPUT') {
error.message = networkError.message.split(';').slice(-1)[0].trim();
} else {
error.message = networkError.message;
}
}
if (error.graphQLErrors && error.graphQLErrors.length) {
error.message = error.graphQLErrors[0].message;
}
return error;
}; |
I believe this issue is directly related to #9870, so I plan to close this as a duplicate to try and keep discussion in a single place. If you think this issue is unrelated, please let me know and we can keep this open. Thanks a ton :) |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Intended outcome:
Network and graphql errors in the ApolloError object should be available in the onError handler.
Actual outcome:
If a mutation results in Validation error a NetworkError is raised. The onError link show correctly both errors. Like shown below. The ApolloError object that is passed to the
onError
handler contains only the NetworkError.In the
onError
linkgraphQLErrors:
networkError:
Error in the handler:
How to reproduce the issue:
Here is code example with the problem:
https://github.com/atstojanov/apolloerror-reproduce
Versions
System:
OS: Linux 5.4 Ubuntu 20.04.2 LTS (Focal Fossa)
Binaries:
Node: 12.18.1 - ~/.nvm/versions/node/v12.18.1/bin/node
Yarn: 1.22.10 - ~/.nvm/versions/node/v12.18.1/bin/yarn
npm: 6.14.8 - ~/.nvm/versions/node/v12.18.1/bin/npm
npmPackages:
@apollo/client: ^3.3.21 => 3.3.21
apollo-upload-client: ^14.1.3 => 14.1.3
The text was updated successfully, but these errors were encountered: