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

default errorPolicy : "all" #11682

Closed
schoenbergeringo opened this issue Mar 14, 2024 · 4 comments
Closed

default errorPolicy : "all" #11682

schoenbergeringo opened this issue Mar 14, 2024 · 4 comments

Comments

@schoenbergeringo
Copy link

Hello everyone,

I just wanted to know if there is a specific reason not to have errorPolicy: "all" as default. With the current default errorPolicy : "none" mutations are not updating the UI to the latest state of the backend, if one of the fieldresolvers return errors. So I am normally adding to all the mutations errorPolicy: "all" to avoid this issue. Is this a mistake by me ? Is there a central place to set this errorPolicy to what i want ?
Thanks, would be nice if someone could explain this to me

@jerelmiller jerelmiller added ⁉️ question 🏓 awaiting-team-response requires input from the apollo team labels Mar 14, 2024
@jerelmiller
Copy link
Member

jerelmiller commented Mar 15, 2024

Hey @schoenbergeringo 👋

Just an FYI, our community forums or Discord server are a great place for these types of questions 🙂.


Unfortunately I haven't been around long enough to know the original motivation behind the decision to make none the default 🙁. I can at least say that the most common way users treat errors in queries is to ignore any partial results and instead just show some type of error indication. This being the most common form of error handling, the "none" default fits this well. Again, I have no idea if this is the reason its the default or not and unfortunately its a breaking change to switch to anything else at this point.

Is there a central place to set this errorPolicy to what i want ?

Yes! You can set defaultOptions in the constructor that will be used as the default for all queries/mutations in your app. Assuming you're using the query hooks (useQuery, useLazyQuery, etc), you'll want to set the error policy on the watchQuery options:

new ApolloClient({
  defaultOptions: {
    watchQuery: { 
      errorPolicy: 'all'
    }
  }
});

Using defaultOptions still allows you to override the errorPolicy per-query if you need something more specific:

useQuery(query, {
  // will be used instead of the default 'all'
  errorPolicy: 'none'
});

@jerelmiller jerelmiller removed the 🏓 awaiting-team-response requires input from the apollo team label Mar 15, 2024
@schoenbergeringo
Copy link
Author

thank you @jerelmiller that helped

Copy link
Contributor

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.

Copy link
Contributor

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
For general questions, we recommend using StackOverflow or our discord server.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants