question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pollInterval with fetchPolicy of 'cache-first'

See original GitHub issue

Use 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.

simulator screen shot may 16 2017 10 10 33 am

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

18reactions
scf4commented, Aug 17, 2017

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 😄

7reactions
sgtpepper43commented, Jul 25, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found