2.0 not clearing error after refetch
See original GitHub issueIntended outcome: data.error should be cleared after successful refetch.
Actual outcome: after error a successful refetch does not clear the error. (In fact I dont think query data is set to undefined on error either, it also retains previous response if there was one. Not sure if that caching and is possibly expected on network-only calls?)
How to reproduce the issue:
1. turn graphql server offline
2. as expected queries return an error { myData: undefined, loading: false, error: 'Error: Network error: Failed to fetch' }
3. turn graphql server back online and do a refetch
4. query returns data successfully but error is not cleared { myData: { uuid: abc123 }, loading: false, error: 'Error: Network error: Failed to fetch' }
Version
- apollo-client@2.0.0
Issue Analytics
- State:
- Created 6 years ago
- Reactions:32
- Comments:32 (4 by maintainers)
Top Results From Across the Web
Refetching queries in Apollo Client - Apollo GraphQL Docs
The client.refetchQueries method collects the TResult results returned by onQueryUpdated , defaulting to TResult = Promise<ApolloQueryResult<any>> if ...
Read more >Refresh or reset Surface RT or Surface 2 - Microsoft Support
If you're having problems with your Surface RT or Surface 2, try refreshing it or resetting it to its factory settings.
Read more >React-Query: How to useQuery when button is clicked
it starts fetching data from backend with this line of code const {status, data, error, refetch } = useQuery( myKey, fetchData(), ...
Read more >useQuery | TanStack Query Docs
This function receives a retryAttempt integer and the actual Error and returns the delay to apply ... If set to false , the...
Read more >Automated Re-fetching | Redux Toolkit
RTK Query > Usage > Automated Refetching: cache invalidation management. ... be undefined based on whether the query was successful or not.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This issue prevents letting users retry failed queries manually. I would assume this is a really common use case. Any ETA on a fix?
I am running into this issue as well… strangely enough it seems like the unit test for this scenario was removed some months ago.
The issue is fundamentally caused by ES6 Observables terminating the stream when an error is sent to an observer. In this case, any kind of error in the query causes the react-apollo component to get dropped (from here to here to here), and the subsequent teardown of the query is just a further consequence. The components themselves don’t contain much subscription logic beyond the mount/unmount lifecycle and thus remain unaware the queries were torn down.
It seems like the subscription logic for react components might need further consideration, or perhaps a different way to handle error conditions.
In either case, here is my own short-term workaround which should serve as a drop-in replacement for the normal
graphql
function: