onCompleted and onError not working with mutation
See original GitHub issueHey, great library.
I’m trying to catch mutation errors but it seems none of the callbacks are called. The only way I was able to catch errors is to use errorPolicy: “ignore” and then checking the result in refetchQueries callback.
Is it an error or am I doing something wrong?
addUser = useMutation(mutation, {
update: (proxy, mutationResult) => {
/* NOT CALLED */
},
refetchQueries: (result) => {
/* CALLED ON errorPolicy: "ignore" */
},
onCompleted: (data) => {
/* NOT CALLED */
},
onError: (data) => {
/* NOT CALLED */
}
});
Issue Analytics
- State:
- Created 5 years ago
- Comments:14 (2 by maintainers)
Top Results From Across the Web
`onCompleted` and `onError` not working in `useMutation ...
Given the following code: const [createMedicalDocument, { loading }] = useMutation( CREATE_MEDICAL_DOCUMENT_MUTATION, { onCompleted: (data) ...
Read more >Mutations in Apollo Client - Apollo GraphQL Docs
A callback function that's called when your mutation successfully completes with zero errors (or if errorPolicy is ignore and partial data is returned)....
Read more >onCompleted of useMutation get executed even on error
This is the reason that the GraphQL errors are ignored. They will only be triggered when using the default policy of none ....
Read more >commitMutation | Relay
The value passed to onCompleted is the the mutation fragment, as read out from the store, after updaters and declarative mutation directives are ......
Read more >How to use the react-relay.commitMutation function in ... - Snyk
function commit({ environment, onCompleted, onError }) { const variables = { input: {} } commitMutation(environment, { mutation, variables, onCompleted, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I needed this and
loadingso I made a wrapper hook. To those who may find it useful:Hi @shlomokraus
Right now you can use only the mutation options supported directly by apollo-client.
onCompletedandonErrorare react-apollo specific. You can have a similar result with something like that:Or with async/await syntax:
And then: