apollo icon indicating copy to clipboard operation
apollo copied to clipboard

Polling happens instantly after a refetch (when using reactive pollInterval)

Open dseltenr-netapp opened this issue 3 years ago • 0 comments

Describe the bug When using a reactive pollInterval function and then issuing a refetch on the query with new variables the inner pollInterval property does not properly get set on subsequent Apollo queries causing the poll to fire off instantly each time (creating a constant stream of queries).

To Reproduce Steps to reproduce the behavior:

  1. Have an apollo option smart query with a reactive pollInterval function getter:
myQueryName {
    pollInterval() { return this.myPollInterval; },
    // ... rest of the options
    }
  1. Issue a refetch on myQueryName with new variables.
  2. Either wait until the next poll occurs or call refresh() on myQueryName query.
  3. Notice that the query is fired off one after another without waiting.

Expected behavior The query should only fire off a query after the pollInterval time has elasped.

Versions vue: 2.6.14 vue-apollo: 3.1.0 apollo-client: 2.6.10

Additional context I was able to get this working locally by adding the following snippet to generateApolloOptions but I haven't dug into the code enough to know if this is the correct place to fix it. If this seems like a decent spot to fix it let me know and I can open a PR to address it:

if (typeof apolloOptions.pollInterval === 'function') {
		  apolloOptions.pollInterval = apolloOptions.pollInterval.call(this.vm);
	  }

If anyone else runs into this issue I was able to address it by changing the pollInterval back to a static value:

pollInerval: 30000 // static value

And then by updating the options in a watch callback:

otherListValue(newValue) {
			const pollInterval = newValue.some(({ pending }) => pending)
				? 5000
				: 30000;
			this.$apollo.queries.myQueryName.setOptions({
				pollInterval,
			});
		},

dseltenr-netapp avatar Apr 05 '22 16:04 dseltenr-netapp