Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetchPolicy: 'cache-and-network' and @client not fetching from the cache #3177

Closed
rcacheira opened this issue Mar 20, 2018 · 4 comments
Closed
Labels
🚧 in-triage Issue currently being triaged

Comments

@rcacheira
Copy link

rcacheira commented Mar 20, 2018

I’m checking that when setting the following default options on ApolloClient:

defaultOptions: {
  query: { fetchPolicy: 'cache-and-network', errorPolicy: 'all' },
  mutate: { errorPolicy: 'all' },
  watchQuery: { fetchPolicy: 'cache-and-network', errorPolicy: 'all' }
}

a query marked with @client is not returning the info from the cache unless a resolver to the query is implemented or marked with the following options options: { fetchPolicy: 'cache-only' }.

I exposed this on slack channel and I got the following response from Dennis Bækgaard, maybe it can help:

I just tried appending it to a query and experience the same behaviour. Havn't seen if I can actually get it to resolve from the cache if I implement a resolver, but without one it at least, it always seems to fetch from the remote store.
Don't know if this helps, but after a short view of the source, it looks to me that it has to happen in QueryManager.ts:301 - Inside that conditional is the only place it actually diffs with the cache. Of the conditionals, the only one I can see could cause problems is the FetchType

Version

  • apollo-cache-inmemory@1.1.7
  • apollo-client@2.2.3
  • apollo-link@1.1.0
  • apollo-link-schema@1.0.3
  • apollo-link-state@0.4.0
  • react-apollo@2.0.4
@uNScope
Copy link

uNScope commented Apr 10, 2018

I have a same problem.

QueryManager.ts line 360

const shouldDispatchClientResult =
      !shouldFetch || fetchPolicy === 'cache-and-network';

if (shouldDispatchClientResult) {
      this.queryStore.markQueryResultClient(queryId, !shouldFetch);
}

In function markQueryResultClient with fetch policy 'cache-and-network' second argument always pass 'false' and it fetch from remote storage instead of fetch from cache. When I replace '!shouldFetch' on 'true' everything became good.

@asafigan
Copy link

Idk, if this is actually a bug. I was printing out the results of the query and I found that on the second watch it returns the result from the cache but also returns loading true.

The problem is if loading should be true in this case or is it better for loading to be false or to have a new value loaded for something like that.

@rstrand
Copy link

rstrand commented Jan 16, 2019

@asafigan I also see this behaviour - the data is returned from the query butloading is true. I agree the behaviour of loading is confusing as most apollo examples just show a loading message when loading is true and ignore the returned data.

networkStatus isn't much help either as it is always 1 even on a cache hit. There is more discussion in issue #3660.

@jbaxleyiii jbaxleyiii added the 🚧 in-triage Issue currently being triaged label Jul 9, 2019
@jbaxleyiii
Copy link
Contributor

Thanks for reporting this. There hasn't been any activity here in quite some time, so we'll close this issue for now. If this is still a problem (using a modern version of Apollo Client), please let us know. Thanks!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🚧 in-triage Issue currently being triaged
Projects
None yet
Development

No branches or pull requests

5 participants