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.

loading flag should be true on initial network request of cache-first policy

See original GitHub issue

Intended outcome: Using the default ‘cache-first’ fetchPolicy, the client will need to load data from the network since the cache is empty initially. In order to display loading indicators, I need to be able to distinguish a network response from a cache response via the loading flag.

Actual outcome: All responses using the cache-first policy have loading set to false. Hence no distinction is possible.

How to reproduce the issue: Create a query with ‘cache-first’ fetchPolicy and inspect the loading prop of the response object.

Version

  • apollo-client@1.2.2

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
danielddbcommented, Oct 4, 2018

The docs at https://www.apollographql.com/docs/angular/basics/queries.html#basics state “The observable will only emit once when the query is complete, and loading will be set to false unless you set the watchQuery parameters notifyOnNetworkStatusChange or returnPartialData to true.”, but I’ve found that even when setting notifyOnNetworkStatusChange to true, it does not. Also, the property returnPartialData doesn’t exist. Using apollo-client 2.4.2. Setting fetchPolicy to cache-and-network made it work. But as this issue states, it should now. 😕

I’m having exactly the same issue on 2.4.2 and could only get it to work using cache-and-network too.

4reactions
patricknazarcommented, Oct 3, 2018

The docs at https://www.apollographql.com/docs/angular/basics/queries.html#basics state “The observable will only emit once when the query is complete, and loading will be set to false unless you set the watchQuery parameters notifyOnNetworkStatusChange or returnPartialData to true.”, but I’ve found that even when setting notifyOnNetworkStatusChange to true, it does not. Also, the property returnPartialData doesn’t exist. Using apollo-client 2.4.2. Setting fetchPolicy to cache-and-network made it work. But as this issue states, it should now. 😕

Read more comments on GitHub >

github_iconTop Results From Across the Web

Local state management - Apollo GraphQL Docs
Ideally, we would like the Apollo cache to be the single source of truth for all data ... You can even request local...
Read more >
React Apollo: Understanding Fetch Policy with useQuery
I googled for that and I got to know that apollo client uses cache-first as a default fetch policy. I changed the fetch...
Read more >
Interfaces: ApolloQuery - Apollo Elements
If data was read from the cache with missing fields, partial will be true. ... Set to prevent subsequent network requests when the...
Read more >
Cache asset via freshness in Angular 6 Service Worker
Having this service worker flag, Angular CLI 1.6 will do some automation ... For network-first strategy, it's freshness , for cache-first ...
Read more >
workbox-strategies - Chrome Developers
An implementation of a cache-first request strategy. ... If the network request fails, and there is no cache match, this will throw a...
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