Refetch returns cached data
See original GitHub issueIntended outcome:
The promise returned from query.refetch()
should resolve with the data fetched from the refetch.
Actual outcome:
The promise returned from query.refetch()
resolves with the cached data from the initial query.
How to reproduce the issue:
I crated a minimal reproduction example: https://codesandbox.io/s/cache-and-network-with-cache-present-wlptu
The server just returns the current time, check in the log to see that the refetch result is the same as in the initial render.
Versions
3.1.3
This is the same as issue #3243 that got closed even though the issue still exists as can be seen in the linked example.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:7
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Refetching queries in Apollo Client - Apollo GraphQL Docs
Local cache updates and refetching work especially well in combination: your application can display the results of local cache modifications immediately, while ...
Read more >Avoiding refetch to update Apollo Client cached data (React)
In order for Apollo Client to update the cache automatically, we have to remember to always return the new data in operation responses....
Read more >Should RTK query only be used to fetch data that doesn't need ...
RTK Query is only for caching fetched data. It's always been common to fetch data from the server and put it into the...
Read more >How to Query GraphQL - LogiCloud
If all data is available locally, useQuery returns that data and doesn't query your GraphQL server. This cache-first policy is Apollo Client's default...
Read more >GraphQL Cache Updates Made Easy - Christian Lüdemann
Refetch query; Built-in normalization · Configure/design the client-side data using cache policies. Query data using client. · By splitting the results into ...
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 FreeTop 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
Top GitHub Comments
This has nothing to do with having or not having an id property. As stated in the issue, the problem is that the promise returned from query.refetch() resolves with the cached data from the initial query instead of the refetched data.
In my case the fetched data has ids (was getting warnings about
merge
without them) but still the cache is not updated. @MahmudHamid is there any other reason for this you can think of?I succeeded to update the pagination cache with
refetch
only by sending a unique random variable to the query, likerandom: Math.random()
. Very hacky.Without this,
refetch
just returns CACHED data – instead of the data fetched from the server 🤷