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.

`refetch` promise with `fetchPolicy` 'cache-and-network' immediately resolves

See original GitHub issue

Intended outcome:

Calling refetch() on a query result that has fetchPolicy: 'cache-and-network' should return a promise that resolves once the request to the network has completed.

Actual outcome:

The promise resolves immediately, while the request to the network is still fired.

How to reproduce the issue:

Call refetch on a query with cache-and-network fetch policy and compare when the promise resolves and when the network request comes back.

I guess this happens because of these lines: https://github.com/apollographql/apollo-client/blob/c00252f2d923d23285b76a24a2b5c151f9e87b96/packages/apollo-client/src/core/QueryManager.ts#L440-L444

However even for the cache-first fetch policy, the promise resolves after a network roundtrip:

https://github.com/apollographql/apollo-client/blob/c00252f2d923d23285b76a24a2b5c151f9e87b96/packages/apollo-client/src/core/ObservableQuery.ts#L307-L313

Would you be open to a PR that fixes this?

Versions


  System:
    OS: macOS Mojave 10.14.6
  Binaries:
    Node: 12.3.1 - /usr/local/bin/node
    Yarn: 1.19.1 - ~/.yarn/bin/yarn
    npm: 6.9.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 78.0.3904.97
    Firefox: 69.0.3
    Safari: 13.0.3
  npmPackages:
    @apollo/react-testing: ^3.1.3 => 3.1.3 
    apollo-cache-inmemory: 1.6.3 => 1.6.3 
    apollo-client: 2.6.4 => 2.6.4 
    apollo-link: 1.2.13 => 1.2.13 
    apollo-link-error: 1.1.12 => 1.1.12 
    apollo-link-http: 1.5.16 => 1.5.16 
    apollo-link-token-refresh: 0.2.7 => 0.2.7 
    react-apollo: ^3.1.3 => 3.1.3 
    react-apollo-network-status: 3.0.0 => 3.0.0 
  npmGlobalPackages:
    apollo-client: 2.5.1
    react-apollo: 3.1.3

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:16
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

6reactions
hsavit1commented, Apr 28, 2021

@hwillson this is still a problem

5reactions
brainkimcommented, Apr 28, 2021

@hsavit1 We’re doing a little spring cleaning because a lot of issues refer to old versions and are slightly outdated. I’ll make sure to look into this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Queries - Apollo GraphQL Docs
To guarantee that the refetch performs a network request, its fetchPolicy is set to network-only (unless the original query's fetchPolicy is no-cache or...
Read more >
Get first result of WatchQuery Method of Apollo-Client (when ...
Maybe I can use the cache-and-network fetch-policy? ... options) { return new Promise((resolve, reject) => aClient.
Read more >
ApolloClient - Client (React) - Apollo GraphQL Docs
This resolves a single mutation according to the options specified and returns a Promise which is either resolved with the resulting data or...
Read more >
Provide quick app start-up times by syncing the Apollo cache ...
We'll also look at setting global "cache-and-network" fetch policies that ensure our ... fetch policy back to the default "cache-first" once the app...
Read more >
Top 5 apollo-utilities Code Examples - Snyk
early return if trying to read from cache during refetch if (fetchPolicy ... or cache-and-network), override it with // network-only to force the...
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