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

useSuspenseQuery should always throw network errors regardless of error policy #10384

Closed
jerelmiller opened this issue Dec 22, 2022 · 0 comments · Fixed by #10401
Closed

useSuspenseQuery should always throw network errors regardless of error policy #10384

jerelmiller opened this issue Dec 22, 2022 · 0 comments · Fixed by #10401

Comments

@jerelmiller
Copy link
Member

jerelmiller commented Dec 22, 2022

While implementing the error policy behavior with useSuspenseQuery, I misunderstood how ignore is supposed to work when a network error occurs. Per the error policy docs:

graphQLErrors are ignored (error.graphQLErrors is not populated), and any returned data is cached and rendered as if no errors occurred.

The key here is that GraphQL errors are ignored, not network errors.

To compare with useQuery, when a network error occurs, the onError callback is called with the network error and the error property is populated. I assume because there is no possibility that partial data will ever be returned. See this diff that demonstrates this behavior.

I think useSuspenseQuery should work similarly to useQuery. The outstanding question is whether we should throw (which would act more like errorPolicy: "none"), or whether we populate the error property (which would act more like errorPolicy: "all").

In fact, this question could expand to errorPolicy: "all" as well. Should useSuspenseQuery always throw when a network error occurs, regardless of the error policy? This aligns with the behavior of useQuery where the onError callback is always called with network errors, regardless of the errorPolicy. After having read the docs a bit closer, it seems the errorPolicy is really meant for altering the behavior when GraphQL errors are encountered and it doesn't really apply to network errors. I'm inclined to say that network errors should always be thrown since these are typically unexpected errors outside of GraphQL.

How to reproduce the issue:

This is an intentional design decision. You can see this demonstrated in the useSuspenseQuery test suite.

Versions

v3.8.0-alpha.x

@jerelmiller jerelmiller self-assigned this Dec 22, 2022
@jerelmiller jerelmiller changed the title useSuspenseQuery should throw network errors when errorPolicy is set to ignore useSuspenseQuery should always throw network errors regardless of error policy Dec 22, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
1 participant