pollInterval with fetchPolicy of 'cache-first'
See original GitHub issueUse case: I want a query to load data from the cache, and only fetch from network if it’s been more than 1 day. The API docs indicate that I need to use fetchPolicy: 'cache-first'
and pollInterval: 1000*60*60*24
.
But this gives me the error (attached) ‘Queries that specify the cache-first and cache-only fetchPolicies cannot also be polling queries.’.
Why should that be the case? The expected behavior would be for the Apollo client to include a timestamp in its redux store of the last time the query was fetched. Then in setup it should check if it’s been more than pollInterval since the last fetch. I believe that was how it worked before v1.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Queries - Apollo GraphQL Docs
To enable polling for a query, pass a pollInterval configuration option to the useQuery ... This cache-first policy is Apollo Client's default fetch...
Read more >Apollo Client to fetch data from GraphQL | by Dilip Kumar
Query component provides fetchPolicy option to change default behavior. Valid fetchPolicy values are: cache-first : This is the default value where it ...
Read more >How to Query GraphQL - LogiCloud
To enable polling for a query, pass a pollInterval configuration option to the useQuery ... This cache-first policy is Apollo Client's default fetch...
Read more >Update the cache of Apollo client 3 when polling not working
Here's the codesandbox. I am adding a user to a cached list of users using client.writeQuery , and the query has a pollInterval...
Read more >useQuery | Vue Apollo
fetchPolicy : Customize cache behavior. cache-first (default): return result from cache. Only fetch from network if cached result is not available.
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
I had this error using
fetchPolicy: 'network-only'
with server-side rendering.Need to check for window object e.g.
pollInterval: typeof window === 'undefined' ? null : 180 * 1000,
I guess the error message could be more clear 😄
I just want to add another use case for this: We have an expensive query that, on page load, we would like to fetch, but on any subsequent requests, we want to grab it from the cache. So we use
cache-first
. However this value can be updated by other users on the system, it’s just a count so it’s not that important that it’s up-to-date, but, we want it to update from the server every five minutes. It’s not that weird of a case, so it seems odd that it wouldn’t be supported.