Apollo-angular: apollo angular watchQuery with pollInterval not working

Created on 27 Sep 2017  路  2Comments  路  Source: kamilkisiela/apollo-angular

Hi,
I'm having an issue using pollInterval with watchQuery, this initial query is returned but subsequent requests are not made.

Relevant pieces from package.json
"apollo-angular": "0.13.1",
"apollo-client": "^1.9.1",
"apollo-client-rxjs": "^0.6.0-rc.1",
"graphql": "^0.11.2",
"graphql-tag": "^2.4.2",

This is my code;

this.apollo.watchQuery<any>({
  query: queryName,
  pollInterval: 1000,
  variables: {
    name: 'testing',
  },
}).subscribe((res: ApolloQueryResult<any>) => {
  console.log('Got Data', res);
}, (err: any) => {
   console.log('Error loading data');
});

Thanks,
David

Most helpful comment

it is working i think, but you have to keep in mind, that your callback is only executed if there are any changes in the cache/response object.

I had the same misleading idea how this works.

  1. if you want to make a request everytime, you need to change the fetchPolicy from cache-first (if the value is in cache --> no requests are made) to e.g. network-only or cache-and-network
  2. even if you set fetchPolicy to network-only --> requests are made in the specified polling interval, but your callback is only executed if the response value changes. ;)

All 2 comments

it is working i think, but you have to keep in mind, that your callback is only executed if there are any changes in the cache/response object.

I had the same misleading idea how this works.

  1. if you want to make a request everytime, you need to change the fetchPolicy from cache-first (if the value is in cache --> no requests are made) to e.g. network-only or cache-and-network
  2. even if you set fetchPolicy to network-only --> requests are made in the specified polling interval, but your callback is only executed if the response value changes. ;)

Please create a reproduction on stackblitz.io or similar.

Here's a template: https://stackblitz.com/edit/simple-apollo-angular-example

Was this page helpful?
0 / 5 - 0 ratings