useQuery does not return data on refetch after error.
See original GitHub issueSteps to reproduce:
- Make a successful request
- Take graphql server offline
- Make a new request
- We get an error now.
- Take graphql server online
- Invoke
refetch. - Note the successful network request in devtools, but we never get data back from useQuery.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:11
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Refetching queries in Apollo Client - Apollo GraphQL Docs
If onQueryUpdated is not provided, the default implementation returns the result of calling observableQuery.refetch() . When onQueryUpdated is provided, it can ...
Read more >react-query: Refetch if and only if there is no error
I am assuming you are trying to fetch the user data but if it fails you do not want to retry, is that...
Read more >useQuery | TanStack Query Docs
Optional; Defaults to true; If set to true , the query will refetch on mount if the data is stale. If set to...
Read more >React Query FAQs - TkDodo's blog
1const { data, refetch } = useQuery(['item'], () => fetchItem({ id: 1 })). 2. 3<button onClick={() => {. 4 // this is not...
Read more >Queries - Redux Toolkit
RTK Query > Usage > Queries: fetching data from a server. ... See Customizing Queries if fetchBaseQuery does not handle your requirements.
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

I’m assuming a PR is still needed for this? Running into this issue now and it is still unresolved in react-apollo so thought it would probably be easier to apply the workaround above in this repo. I can open one if needed.
I was able to solve the problem based on https://github.com/apollographql/react-apollo/blob/master/src/Query.tsx#L363
changing useEffect inside useQuery by: