Setting The Correct Fetch Policy

Hi Guys,

I’m close to finishing my product. Throughout the software I use a fetch policy of network-only and a nextFetchPolicy of cache-first based on this - [BUG] FetchMore + fetchPolicy: 'network-only' always triggers first page query · Issue #7307 · apollographql/apollo-client · GitHub.

I’m finding this isn’t a great option though because if one of the subsequent request errors it seems to read from the cache which absolutely isn’t what I want. I’ve noticed for example that upon requesting page 2 of live data, it this errors, I see page 1!!

Just now I tried “no-cache” and “network-only” for “fetchPolicy” and “nextFetchPolicy” respectively but whilst this shows correctly in the UI I noticed under the network tab of my browser that the original query is being duplicated.

In short please can somebody explain the best way of implementing a fetch policy which never reads from the cache. Surely this is one of the most common use cases of a graphql client.

Hi @rossm6, welcome to the community!

AFAIK, the main difference between the network-only and no-cache is with network-only fetch-policy, a remote request is made and the response is cached (but is not used). Whereas with no-cache, the response is never written to cache. You should be able to just set the fetchPolicy (and not set the nextFetchPolicy) to either network-only or no-cache and expect the application to make the remote request every time .

If that doesn’t work, can you share the ApolloClient initialization code and version of the Apollo client library you are using?