We have a graphql mutation call that can possibly return a response with both the errors
field and data
field:
{
"data": // data,
"errors": // errors,
}
without setting errorPolicy: all
to the useMutation
hook, onCompleted
will fire only if there is no errors
present in the response and onError
will fire only if there is errors
present in the response. However, the issue I am facing is that, onComplete
handler doesn’t have access to the errors
field when it is present in the response and onError
handler doesn’t have access to the data
field in the response either.
Once I set errorPolicy: all
to the useMutation
hook, onComplete
will always fire even when the errors
field is present in the response, but still it doesn’t have access to errors
from the onComplete
handler. The onError
handler will never fire even when the errors
field is present in the response. We can only get the errors
from the result
object returned by useMutation
.
I wonder if there is a better, more elegant way to handle this within the respective handlers (i.e. onCompleted
and onError
)?