apollographql / apollo-client

:rocket:  A fully-featured, production ready caching GraphQL client for every UI framework and GraphQL server.
https://apollographql.com/client
MIT License
19.38k stars 2.66k forks source link

watchQuery with pollInterval ignores no-cache fetchPolicy #6187

Closed timkendrick closed 2 years ago

timkendrick commented 4 years ago

Currently, when executing a watchQuery with a pollInterval and the fetchPolicy: 'no-cache' option, the caching option is overridden internally within Apollo to network-only, causing data to be written to the cache despite the no-cache fetch policy.

Intended outcome:

client.watchQuery({
  query,
  pollInterval: 1000,
  fetchPolicy: 'no-cache', // No objects should be written to the cache
}).valueChanges.subscribe(...);

Actual outcome: The cache .write() method is called with the results of the query

How to reproduce the issue: See 'Intended outcome' section

Versions

  System:
    OS: macOS Mojave 10.14.6
  Binaries:
    Node: 12.14.0 - /usr/local/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.13.4 - /usr/local/bin/npm
  Browsers:
    Chrome: 81.0.4044.113
    Firefox: 61.0.2
    Safari: 13.1
  npmPackages:
    @apollo/client: 3.0.0-beta.44 => 3.0.0-beta.44
hwillson commented 4 years ago

@timkendrick can you re-rest with @apollo/client@3.0.0-beta.50 and let us know if this is still an issue?

VasiliKubarka commented 4 years ago

Have the same bug for apollo-client v 2.6.10

mutefiRe commented 4 years ago

same bug here with @apollo/client@3.1.3, but worked for us in apollo-client@2.6.10 - or at least didn't mess up the cache because the merge behaviour was different.

jcreighton commented 3 years ago

Marking this is as needs-reproduction since I see this might still be an issue. If so, a runnable reproduction will go a long away in helping us resolve this. You can use either this repo or this CodeSandbox to reproduce the issue.

Wozniaxos commented 3 years ago

Have the same issue with apollo 3.3.8 - on every poll interval with "no-cache" policy query enters cache read/merge functions. https://codesandbox.io/s/stoic-star-0g4ms?file=/src/App.js here you can see that it adds object to no cached data, and this is my usage in app, basically i need to have same query with different parameters one query for one part of data and second query for second part of data, one is with infinite scroll configured so it needs to be cached, but from the same query with unread variable i want to read also unreadCount data which i am polling.

amitgoldarb commented 2 years ago

This still happens in apollo/client v3.5.8

EllaSharakanski commented 2 years ago

@jcreighton @hwillson I think this might be the problematic line in the code: https://github.com/apollographql/apollo-client/blob/main/src/core/ObservableQuery.ts#L637 It always uses network-only for polling.

I think the logic from refetch could be used instead, see here https://github.com/apollographql/apollo-client/blob/main/src/core/ObservableQuery.ts#L327

jpvajda commented 2 years ago

This issue might be related to what was reported in #9691

MrDoomBringer commented 2 years ago

Commenting to say this should be resolved in https://github.com/apollographql/apollo-client/pull/10020! Please let us know if this issue is still cropping up after our next release.

All the best, Emmanuel, Intern :-)