ApolloStore

interface ApolloStore

ApolloStore exposes a thread-safe api to access a com.apollographql.apollo3.cache.normalized.api.NormalizedCache.

Note that most operations are synchronous and might block if the underlying cache is doing IO - calling them from the main thread should be avoided.

Properties

Link copied to clipboard
abstract val changedKeys: SharedFlow<Set<String>>

Exposes the keys of records that have changed.

Functions

Link copied to clipboard
abstract fun <R> accessCache(block: (NormalizedCache) -> R): R

Direct access to the cache. This is a synchronous operation that might block if the underlying cache is doing IO.

Link copied to clipboard
abstract fun clearAll(): Boolean

Clear all records from this ApolloStore. This is a synchronous operation that might block if the underlying cache is doing IO

Link copied to clipboard
abstract fun dispose()

Release resources associated with this store.

Link copied to clipboard
abstract fun dump(): Map<KClass<*>, Map<String, Record>>

Dump the content of the store for debugging purposes. This is a synchronous operation that might block if the underlying cache is doing IO.

Link copied to clipboard
abstract fun <D : Operation.Data> normalize(operation: Operation<D>, data: D, customScalarAdapters: CustomScalarAdapters): Map<String, Record>

Normalize data to a map of Record keyed by Record.key.

Link copied to clipboard
abstract suspend fun publish(keys: Set<String>)
Link copied to clipboard
abstract fun <D : Fragment.Data> readFragment(fragment: Fragment<D>, cacheKey: CacheKey, customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, cacheHeaders: CacheHeaders = CacheHeaders.NONE): D

Read a GraphQL fragment from the store. This is a synchronous operation that might block if the underlying cache is doing IO

Link copied to clipboard
abstract fun <D : Operation.Data> readOperation(operation: Operation<D>, customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, cacheHeaders: CacheHeaders = CacheHeaders.NONE): D

Read GraphQL operation from store. This is a synchronous operation that might block if the underlying cache is doing IO

Link copied to clipboard
abstract fun remove(cacheKey: CacheKey, cascade: Boolean = true): Boolean

Remove cache record by the key This is a synchronous operation that might block if the underlying cache is doing IO

abstract fun remove(cacheKeys: List<CacheKey>, cascade: Boolean = true): Int

Remove a list of cache records This is an optimized version of remove for caches that can batch operations This is a synchronous operation that might block if the underlying cache is doing IO

Link copied to clipboard
abstract fun rollbackOptimisticUpdates(mutationId: Uuid): Set<String>
abstract suspend fun rollbackOptimisticUpdates(mutationId: Uuid, publish: Boolean = true): Set<String>

Rollback operation data optimistic updates. This is a synchronous operation that might block if the underlying cache is doing IO.

Link copied to clipboard
abstract fun <D : Fragment.Data> writeFragment(fragment: Fragment<D>, cacheKey: CacheKey, fragmentData: D, customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, cacheHeaders: CacheHeaders = CacheHeaders.NONE): Set<String>

Write a fragment data to the store. This is a synchronous operation that might block if the underlying cache is doing IO

abstract suspend fun <D : Fragment.Data> writeFragment(fragment: Fragment<D>, cacheKey: CacheKey, fragmentData: D, customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, cacheHeaders: CacheHeaders = CacheHeaders.NONE, publish: Boolean = true): Set<String>

Write a fragment data to the store and optionally publish changes of Record which have changed, that will notify any watcher that depends on these Record to re-fetch. This is a synchronous operation that might block if the underlying cache is doing IO

Link copied to clipboard
abstract fun <D : Operation.Data> writeOperation(operation: Operation<D>, operationData: D, customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, cacheHeaders: CacheHeaders = CacheHeaders.NONE): Set<String>

Write an operation data to the store. This is a synchronous operation that might block if the underlying cache is doing IO

abstract suspend fun <D : Operation.Data> writeOperation(operation: Operation<D>, operationData: D, customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, cacheHeaders: CacheHeaders = CacheHeaders.NONE, publish: Boolean = true): Set<String>

Write an operation data to the store and optionally publish changes of Record which have changed, that will notify any watcher that depends on these Record to re-fetch. This is a synchronous operation that might block if the underlying cache is doing IO

Link copied to clipboard
abstract fun <D : Operation.Data> writeOptimisticUpdates(operation: Operation<D>, operationData: D, mutationId: Uuid, customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty): Set<String>

Write operation data to the optimistic store. This is a synchronous operation that might block if the underlying cache is doing IO.

abstract suspend fun <D : Operation.Data> writeOptimisticUpdates(operation: Operation<D>, operationData: D, mutationId: Uuid, customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, publish: Boolean = true): Set<String>

Write operation data to the optimistic store and optionally publish changes of Record which have changed, that will notify any watcher that depends on these Record to re-fetch. This is a synchronous operation that might block if the underlying cache is doing IO.