Apollo Kotlin Normalized Cache Help

Partial cache reads

The cache supports partial cache reads, in a similar way to how GraphQL supports partial responses. This means that if some fields are missing from the cache, the cache returns the available data along with any errors for the missing fields.

With ApolloStore

The ApolloStore.readOperation() API returns an ApolloResponse<D> that can contain partial data and non-empty errors for any missing (or stale) fields in the cache.

If a cache miss exception is preferred, you can use the ApolloResponse<D>.errorsAsException() extension function that returns a response with an exception if there are any errors.

With ApolloClient

When executing operations, the built-in fetch policies (FetchPolicy.CacheFirst, FetchPolicy.CacheOnly, etc.) will treat cache misses as exceptions (partial results are disabled) by default.

To benefit from partial cache reads, you can set throwOnCacheMiss(false), or implement your own fetch policy interceptor as shown in this example:

object PartialCacheOnlyInterceptor : ApolloInterceptor { override fun <D : Operation.Data> intercept( request: ApolloRequest<D>, chain: ApolloInterceptorChain ): Flow<ApolloResponse<D>> { return chain.proceed( request = request .newBuilder() // Controls where to read the data from (cache or network) .fetchFromCache(true) .build() ) } } // ... val apolloClient = ApolloClient.Builder() /*...*/ .serverUrl("https://example.com/graphql") .fetchPolicyInterceptor(PartialCacheOnlyInterceptor) .build()

Error stored in the cache

Errors from the server are stored in the cache, and will be returned when reading it.

By default, errors don't replace existing data in the cache. You can change this behavior with errorsReplaceCachedValues(true).

Last modified: 15 September 2025