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.

fetchPolicy: 'network-only' being ignored

See original GitHub issue

I’m trying to use watchQuery with ‘netwok-only’ fetchPolicy and pollInterval, as a result the following output

Error: Queries that specify the cache-first and cache-only fetchPolicies cannot also be polling queries.
let options:any = {
            query: gql `...`,
            fetchPolicy: 'network-only',
        };
        this.feedRef = this.apollo.watchQuery(options);
        console.log('queryRef: ',  this.feedRef)

image

I have even put this mode in the default settings,

this.apollo.create({
      link: middleware ? errorLink.concat(middleware) : errorLink.concat(this.link),
      cache: this.cache,
      ssrMode: true,
      defaultOptions: {
        watchQuery: {
          fetchPolicy: 'network-only'
        }
      }
    });

in the package.json …

"apollo-angular": "1.0.1",
    "apollo-angular-link-http": "1.0.2-beta.0",
    "apollo-cache-inmemory": "1.1.11",
    "apollo-cache-persist": "0.1.1",
    "apollo-client": "2.2.7",
    "apollo-client-rxjs": "^0.6.0-rc.2",
    "apollo-link": "1.2.1",
    "apollo-link-context": "1.0.7",
    "apollo-link-error": "1.0.7",
    "apollo-link-http": "1.5.3",
    "graphql": "0.13.2",
    "graphql-tag": "2.8.0",

Anyone knows what I’m missing up? Thanks

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kamilkisielacommented, Mar 18, 2018

Do you use SSR mode?

0reactions
michaelbromleycommented, Nov 2, 2022

Try using setting the ssrForceFetchDelay option to a non-zero value, say 500. This should undo the forced “cache-only” policy as per this code: https://github.com/apollographql/apollo-client/blob/337314111bc75e17834d0dfb6af461b921276dd2/packages/apollo-client/src/ApolloClient.ts#L127-L132

    if (ssrForceFetchDelay) {
      setTimeout(
        () => (this.disableNetworkFetches = false),
        ssrForceFetchDelay,
      );
    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

fetchPolicy: 'network-only' being ignored · Issue #503 - GitHub
I'm trying to use watchQuery with 'netwok-only' fetchPolicy and pollInterval, as a result the following output Error: Queries that specify ...
Read more >
Queries - Apollo GraphQL Docs
The useQuery React hook is the primary API for executing queries in an Apollo ... fetchPolicy: 'network-only', // Doesn't check cache before making...
Read more >
Cache management for watchQuery (Angular-Apollo)
If not all data is available in the cache, an error will be thrown. This is equivalent to the former noFetch. { fetchPolicy:...
Read more >
How to use the apollo-link.from function in apollo-link - Snyk
export default function createApolloClient() { // "apollo-link" is a standard ... cache }; const devtoolsLink = from([ errorLink(), cacheLink(fetchPolicy), ...
Read more >
Understanding Apollo Fetch Policies | by Galen Corey - Medium
The default fetch policy for Apollo is cache-first. ... information from the cache, it may make sense to use a 'network-only' fetch policy....
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