-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
useQuery: networkError overwrites graphQLErrors, and vice versa on refetch #8157
Comments
So I just tested this again on Apollo 3.5.8 and it's a bit better, although still strange. Now when refetching it behaves the same as when initially fetching, which is good, but it still does the odd behaviour of initially setting Here's a codesandbox to reproduce this: https://codesandbox.io/s/apollo-network-error-demo-k5elw?file=/client/App.jsx Open the console tab after the page loads, you'll see that once the query finishes, the component first re-renders with I would expect the component to only re-render once after the query finishes, and for both |
I believe this issue is happening because of the two server responses you're getting, one has a " That would make this one of many issues related to #9870, so I plan to close this as a duplicate to try and keep discussion in a single place. If you think this issue is unrelated, please let me know and we can keep this open. Thanks a ton :) |
I don't think it's because one response has a "data" field and the other doesn't, both responses are identical. I believe this is caused by the response having both GraphQL errors and a network status error (401). So In this scenario I'd expect both If you still believe this is related to #9870 though then I am fine with closing this. |
Hi @mogzol! Thanks so much for the fast response. Yep, you're right - there's only the one server response that results in two renders. However, the underlying issue appears to be the same as in #9870 - Apollo Client's handling/presenting of network-code errors separately from GraphQL errors.
These seem to me to be two sides of the same coin, so I'll be updating #9870 with insights from this issue - while this behavior might not necessarily be unintended, it's definitely confusing for users and in need of change. |
Intended outcome:
I have a query which might cause the server to return a 401 status, with additional GraphQL errors in the body. I want to be able to get both the network status code, and the graphQL errors out of the result.
Actual outcome:
When I run the query, initially
result.error
contains thegraphQLErrors
field, but thenetworkError
field is null. The component then immediately re-renders and now thenetworkError
field is set, but thegraphQLErrors
field is null.This alone would be manageable (although still odd behaviour). I can wait for the second render then get the network status from
networkError.statusCode
and get the GraphQL errors out ofnetworkError.result.errors
.However, if I ever
refetch
the query, then the result will only ever havegraphQLErrors
, andnetworkError
is always null, even though the server is returning a 401.How to reproduce the issue:
Here's a really simple example component.
QUERY
here needs to be a query that causes the server to return an error status, and also includes GraphQL errors in the body.After loading this component, I see this in my console:
Note that initially once done loading, there's a non-empty
graphQLErrors
array, but nonetworkError
, then immediately after that there's an emptygraphQLErrors
array, but now there is anetworkError
.If I click the refetch button, I only get a single output to the console, it goes back to having
graphQLErrors
, but nonetworkError
:This means that after re-fetching, I can no longer check the network status code of the response.
Versions
The text was updated successfully, but these errors were encountered: