Open Michael-M-Judd opened 1 month ago
It seems like this behaviour was introduced in 3.3.15 via https://github.com/apollographql/apollo-client/pull/8018.
At this point, I have to be honest: this has been around for so long that I think we can't change it easily, even if it is inconsistent.
I'll bring it up with the team, but my gut feeling is that this would need to be addressed in a major release - and even then a lot of people would probably still miss it and get bitten by it 😕
I guess we actually did discuss that - I checked old meeting notes: this is on our TODO list for a 4.0 release.
So.. I can't offer you an immediate fix, but can tell you that we're aware and planning to change this.
We're closing this issue now but feel free to ping the maintainers or open a new issue if you still need support. Thank you!
Keeping this open to track for 4.0
I'm curious about this useMutation error handling here: https://github.com/apollographql/apollo-client/blob/c95848e859fb7ce0b3b9439ac71dff880f991450/src/react/hooks/useMutation.ts#L211
I was really not expecting this behaviour because its different between useMutation and useQuery, where on a failure, we end up throwing a promise only if there is no onError handling.
The impact of this was that in my jest test, I was testing a component that uses a mutation and correctly handling error via the hook
error
return, but I was receiving an unhandled promise rejection which ended up failing my jest test. A very simple reproduction can be shown here:Is there a reason we want to handle this different than that of a useQuery or useLazyQuery call?