Query options
When you execute a query, options control how the query is executed. ApolloClient returns an ApolloResponse that satisfies the options or an exceptional response otherwise (response.exception is not null).
fetchPolicy
Fetch policy controls how and if the cache is used. The default is CacheFirst.
CacheFirst
A response is fetched from the cache first. If no valid response cannot be found, the network is queried.
CacheOnly
The response is fetched from the cache. If no valid response cannot be found, response.exception is set.
NetworkOnly
The response is fetched from the network. If no valid response cannot be found, response.exception is set.
NetworkFirst
A response is fetched from the network first. If no valid response cannot be found, the cache is queried.
CacheAndNetwork
A response is fetched from the cache and then from the network.
Warning: this can emit multiple successful responses, therefore ApolloCall.execute() should not be used with this policy. Use only with ApolloCall.toFlow() or ApolloCall.watch().
serverErrorsAsCacheMisses
Sets whether GraphQL errors in the cache should be treated as cache misses. When true (the default), if any field is an Error in the cache, the returned response will have a null data and a non-null exception of type ApolloGraphQLException.
throwOnCacheMiss
Sets whether missing fields from the cache should result in an exception. When true (the default), if any field is missing in the cache, the returned response will have a null data and a non-null exception of type CacheMissException.
Set this to false to allow partial responses from the cache, where some or all of the fields may be missing.
maxStale
If stale fields are acceptable up to a certain value, you can set a maximum staleness duration. This duration is the maximum time that a stale field will be resolved without resulting in a cache miss. To set this duration, call .maxStale(Duration) either globally on your client, or per operation:
isStale
With maxStale, it is possible to get data from the cache even if it is stale. To know if the response contains stale fields, you can check CacheInfo.isStale: