Add "throwError" option to useMutation defaulting to false #220
Labels
🪝 react hooks
Feature requests related to React hooks
project-apollo-client (legacy)
LEGACY TAG DO NOT USE
As reported here : apollographql/apollo-client#5708, the default behavior of useMutation regarding errors is forcing users to add boilerplate code in order to achieve what they expect.
Expected behavior:
Defining a global onError handler (either through apollo-boost's helper or through using a custom link) should avoid having to call useMutation in a try/catch or with
{onError: () => null}
(as proposed here apollographql/apollo-client#5708 (comment)) everywhere it is used.Proposed solution:
Add a "throwError" option to useMutation with as default value false which would be used here: https://github.com/apollographql/apollo-client/blob/c14c94b73ada83c92d75271d3a5dc17b03ccb85f/src/react/data/MutationData.ts#L76
I was imagining something along these lines:
This would remove the obligation to add boilerplate code on every use of useMutation.
I am aware this would alter the default behavior of useMutation but it seems to me to be more of a sensible default as it smooths the behavior between useMutation and useQuery (which never throws errors if I am not mistaking).
The text was updated successfully, but these errors were encountered: