Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "throwError" option to useMutation defaulting to false #220

Open
glen-rhodes opened this issue Apr 2, 2020 · 0 comments
Open

Add "throwError" option to useMutation defaulting to false #220

glen-rhodes opened this issue Apr 2, 2020 · 0 comments
Labels
🪝 react hooks Feature requests related to React hooks project-apollo-client (legacy) LEGACY TAG DO NOT USE

Comments

@glen-rhodes
Copy link

glen-rhodes commented Apr 2, 2020

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:

if (!this.getOptions().onError && this.getOptions().throwError) throw error;

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).

@jpvajda jpvajda added the project-apollo-client (legacy) LEGACY TAG DO NOT USE label Aug 24, 2022
@jerelmiller jerelmiller added the 🪝 react hooks Feature requests related to React hooks label Apr 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🪝 react hooks Feature requests related to React hooks project-apollo-client (legacy) LEGACY TAG DO NOT USE
Projects
None yet
Development

No branches or pull requests

3 participants