Package-level declarations

Types

Link copied to clipboard
class ApolloStore(val cacheManager: CacheManager, val customScalarAdapters: CustomScalarAdapters)

A wrapper around CacheManager that provides a simplified API for reading and writing data.

Link copied to clipboard
class CacheInfo : ExecutionContext.Element
Link copied to clipboard
interface CacheManager

CacheManager exposes a high-level API to access a com.apollographql.cache.normalized.api.NormalizedCache.

Link copied to clipboard
class CacheMissLoggingInterceptor(log: (String) -> Unit) : ApolloInterceptor
Link copied to clipboard
Link copied to clipboard
class GarbageCollectResult(val removedStaleFields: RemovedFieldsAndRecords, val removedDanglingReferences: RemovedFieldsAndRecords, val removedUnreachableRecords: Set<CacheKey>)
Link copied to clipboard
class RemovedFieldsAndRecords(val removedFields: Set<String>, val removedRecords: Set<CacheKey>)

Properties

Link copied to clipboard
val ApolloClient.apolloStore: ApolloStore
Link copied to clipboard
val CacheAndNetworkInterceptor: ApolloInterceptor

An interceptor that emits the response from the cache first, and then emits the response(s) from the network.

Link copied to clipboard
val <D : Operation.Data> ApolloResponse<D>.cacheHeaders: CacheHeaders
Link copied to clipboard
val <D : Operation.Data> ApolloResponse<D>.cacheInfo: CacheInfo?
Link copied to clipboard
val Error.cacheMissException: CacheMissException?

If this Error represents a cache miss, returns an equivalent CacheMissException.

Link copied to clipboard
val DefaultFetchPolicyInterceptor: ApolloInterceptor

An interceptor that emits the response from the cache first, and if there was a cache miss, emits the response(s) from the network.

Link copied to clipboard
val <D : Operation.Data> ApolloRequest<D>.fetchFromCache: Boolean
Link copied to clipboard
val <D : Operation.Data> ApolloResponse<D>.isFromCache: Boolean

True if this response comes from the cache, false if it comes from the network.

Link copied to clipboard
val NetworkFirstInterceptor: ApolloInterceptor

An interceptor that emits the response(s) from the network first, and if there was a network error, emits the response from the cache.

Link copied to clipboard

Functions

Link copied to clipboard
fun <T> MutableExecutionOptions<T>.addCacheHeader(key: String, value: String): T

Add a cache header to be passed to your com.apollographql.cache.normalized.api.NormalizedCache

Link copied to clipboard
Link copied to clipboard
fun <D : Operation.Data> ApolloResponse.Builder<D>.cacheHeaders(cacheHeaders: CacheHeaders): ApolloResponse.Builder<D>
fun <T> MutableExecutionOptions<T>.cacheHeaders(cacheHeaders: CacheHeaders): T
Link copied to clipboard
fun CacheManager(normalizedCacheFactory: NormalizedCacheFactory, cacheKeyGenerator: CacheKeyGenerator, cacheResolver: CacheResolver, metadataGenerator: MetadataGenerator = EmptyMetadataGenerator, recordMerger: RecordMerger = DefaultRecordMerger, fieldKeyGenerator: FieldKeyGenerator = DefaultFieldKeyGenerator, embeddedFieldsProvider: EmbeddedFieldsProvider = EmptyEmbeddedFieldsProvider, maxAgeProvider: MaxAgeProvider = DefaultMaxAgeProvider, enableOptimisticUpdates: Boolean = false): CacheManager
Link copied to clipboard
fun ApolloClient.Builder.cacheManager(cacheManager: CacheManager, writeToCacheAsynchronously: Boolean = false): ApolloClient.Builder
Link copied to clipboard
fun <T> MutableExecutionOptions<T>.clock(clock: () -> Long): T

Sets the clock used to:

Link copied to clipboard
fun <T> MutableExecutionOptions<T>.doNotStore(doNotStore: Boolean): T
Link copied to clipboard
fun <D : Operation.Data> ApolloResponse<D>.errorsAsException(): ApolloResponse<D>

If this response has errors, returns a response with an exception, otherwise returns this response. This can be used to accommodate com.apollographql.apollo.ApolloCall.execute which splits responses based on exceptions and should only be called on cache responses.

Link copied to clipboard
fun <T> MutableExecutionOptions<T>.errorsReplaceCachedValues(errorsReplaceCachedValues: Boolean): T
Link copied to clipboard
fun <D : Operation.Data> ApolloRequest.Builder<D>.fetchFromCache(fetchFromCache: Boolean): ApolloRequest.Builder<D>
Link copied to clipboard
fun <T> MutableExecutionOptions<T>.fetchPolicy(fetchPolicy: FetchPolicy): T

Sets the initial FetchPolicy This only has effects for queries. Mutations and subscriptions always use the network only.

Link copied to clipboard
fun <T> MutableExecutionOptions<T>.fetchPolicyInterceptor(interceptor: ApolloInterceptor): T

Sets the initial FetchPolicy This only has effects for queries. Mutations and subscriptions always use FetchPolicy.NetworkOnly

Link copied to clipboard
suspend fun ApolloStore.garbageCollect(maxAgeProvider: MaxAgeProvider, maxStale: Duration = Duration.ZERO): GarbageCollectResult

Perform garbage collection on the store.

suspend fun NormalizedCache.garbageCollect(maxAgeProvider: MaxAgeProvider, maxStale: Duration = Duration.ZERO, clock: () -> Long = { currentTimeMillis() }): GarbageCollectResult

Perform garbage collection on the cache.

Link copied to clipboard
fun ApolloClient.Builder.logCacheMisses(log: (String) -> Unit = { println(it) }): ApolloClient.Builder
Link copied to clipboard
fun <T> MutableExecutionOptions<T>.maxStale(maxStale: Duration): T
Link copied to clipboard
fun <T> MutableExecutionOptions<T>.memoryCacheOnly(memoryCacheOnly: Boolean): T
Link copied to clipboard
fun ApolloClient.Builder.normalizedCache(normalizedCacheFactory: NormalizedCacheFactory, cacheKeyGenerator: CacheKeyGenerator, cacheResolver: CacheResolver, metadataGenerator: MetadataGenerator = EmptyMetadataGenerator, recordMerger: RecordMerger = DefaultRecordMerger, fieldKeyGenerator: FieldKeyGenerator = DefaultFieldKeyGenerator, embeddedFieldsProvider: EmbeddedFieldsProvider = EmptyEmbeddedFieldsProvider, maxAgeProvider: MaxAgeProvider = DefaultMaxAgeProvider, enableOptimisticUpdates: Boolean = false, writeToCacheAsynchronously: Boolean = false): ApolloClient.Builder

Configures an ApolloClient with a normalized cache.

fun ApolloClient.Builder.normalizedCache(normalizedCacheFactory: NormalizedCacheFactory, typePolicies: Map<String, TypePolicy>, fieldPolicies: Map<String, FieldPolicies>, connectionTypes: Set<String>, embeddedFields: Map<String, EmbeddedFields>, maxAges: Map<String, MaxAge>, defaultMaxAge: Duration, keyScope: CacheKey.Scope, enableOptimisticUpdates: Boolean, writeToCacheAsynchronously: Boolean): ApolloClient.Builder
fun ApolloClient.Builder.normalizedCache(normalizedCacheFactory: NormalizedCacheFactory, typePolicies: Map<String, TypePolicy>, fieldPolicies: Map<String, FieldPolicies>, metadataGenerator: MetadataGenerator = EmptyMetadataGenerator, recordMerger: RecordMerger = DefaultRecordMerger, fieldKeyGenerator: FieldKeyGenerator = DefaultFieldKeyGenerator, embeddedFieldsProvider: EmbeddedFieldsProvider = EmptyEmbeddedFieldsProvider, maxAgeProvider: MaxAgeProvider = DefaultMaxAgeProvider, keyScope: CacheKey.Scope = CacheKey.Scope.TYPE, enableOptimisticUpdates: Boolean = false, writeToCacheAsynchronously: Boolean = false): ApolloClient.Builder
Link copied to clipboard
fun <D : Mutation.Data> ApolloCall<D>.optimisticUpdates(data: D): ApolloCall<D>

fun <D : Mutation.Data> ApolloRequest.Builder<D>.optimisticUpdates(data: D): ApolloRequest.Builder<D>

Sets the optimistic updates to write to the cache while a query is pending.

Link copied to clipboard
fun <T> MutableExecutionOptions<T>.refetchPolicy(fetchPolicy: FetchPolicy): T

Sets the FetchPolicy used when watching queries and a cache change has been published

Link copied to clipboard
fun <T> MutableExecutionOptions<T>.refetchPolicyInterceptor(interceptor: ApolloInterceptor): T

Sets the FetchPolicy used when watching queries and a cache change has been published

Link copied to clipboard

Remove all dangling references in the store.

Remove all dangling references in the cache. A field is a dangling reference if its value (or, for lists, any of its values) is a reference to a record that does not exist.

Link copied to clipboard
suspend fun <D : Fragment.Data> ApolloStore.removeFragment(fragment: Fragment<D>, cacheKey: CacheKey, data: D, cacheHeaders: CacheHeaders = CacheHeaders.NONE, publish: Boolean = false): Set<String>

Removes a fragment from the store.

Link copied to clipboard
suspend fun <D : Operation.Data> ApolloStore.removeOperation(operation: Operation<D>, data: D, cacheHeaders: CacheHeaders = CacheHeaders.NONE, publish: Boolean = false): Set<String>

Removes an operation from the store.

Link copied to clipboard
suspend fun ApolloStore.removeStaleFields(maxAgeProvider: MaxAgeProvider, maxStale: Duration = Duration.ZERO): RemovedFieldsAndRecords

Remove all stale fields in the store.

suspend fun NormalizedCache.removeStaleFields(maxAgeProvider: MaxAgeProvider, maxStale: Duration = Duration.ZERO, clock: () -> Long = { currentTimeMillis() }): RemovedFieldsAndRecords

Remove all stale fields in the cache. A field is stale if its received date is older than its max age (configurable via maxAgeProvider) or if its expiration date has passed. A maximum staleness can be passed.

Link copied to clipboard

Remove all unreachable records in the store.

Remove all unreachable records in the cache. A record is unreachable if there exists no chain of references from the root record to it.

Link copied to clipboard
fun <T> MutableExecutionOptions<T>.storeExpirationDate(storeExpirationDate: Boolean): T
Link copied to clipboard
fun <T> MutableExecutionOptions<T>.storePartialResponses(storePartialResponses: Boolean): Nothing
Link copied to clipboard
fun <T> MutableExecutionOptions<T>.storeReceivedDate(storeReceivedDate: Boolean): T
Link copied to clipboard
fun <D : Query.Data> ApolloCall<D>.watch(): Flow<ApolloResponse<D>>

Gets initial response(s) then observes the cache for any changes.

fun <D : Query.Data> ApolloCall<D>.watch(data: D?): Flow<ApolloResponse<D>>

Observes the cache for the given data. Unlike watch, no initial request is executed on the network. The fetch policy set by fetchPolicy will be used.

Link copied to clipboard
fun <T> MutableExecutionOptions<T>.writeToCacheAsynchronously(writeToCacheAsynchronously: Boolean): T