Ar26
Ar26

Reputation: 1099

onCompleted of useMutation get executed even on error

When I'm using the useMutation hook and getting an error on the response the onCompleted method gets triggered. Is that normal behavior?

 const [createPerson] = useMutation(CreatePerson, {
   onCompleted: () => {
     console.log('even onError it`s executed')
   }
 })

Upvotes: 0

Views: 1583

Answers (1)

Gh05d
Gh05d

Reputation: 8962

From our discussion in the chat I take that you have set the error policy of the Apollo Provider to ignore:

ignore: Ignore allows you to read any data that is returned alongside GraphQL Errors, but doesn't save the errors or report them to your UI.

This is the reason that the GraphQL errors are ignored. They will only be triggered when using the default policy of none.

More info about the error policies here and in this thread.

Upvotes: 2

Related Questions