diff --git a/CHANGELOG.md b/CHANGELOG.md index 5778c2f8..d27fd3d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Next version (unreleased) -PUT_CHANGELOG_HERE +- Rename `ApolloStore` to `CacheManager` and `SimpleApolloStore` to `ApolloStore`. +- Revert the `ApolloClient.apolloStore` deprecation - keeping the original name makes more sense now after the above rename. # Version 0.0.9 _2025-04-09_ diff --git a/Writerside/topics/migration-guide.md b/Writerside/topics/migration-guide.md index 9789cf64..191918dc 100644 --- a/Writerside/topics/migration-guide.md +++ b/Writerside/topics/migration-guide.md @@ -38,11 +38,10 @@ import com.apollographql.cache.normalized.* import com.apollographql.apollo.cache.normalized.api.MemoryCacheFactory // With import com.apollographql.cache.normalized.memory.MemoryCacheFactory - - - ``` +In most cases, this will be enough to migrate your project, but there were a few renames and API breaking changes. Read on for more details. + ## Database schema The SQLite cache now uses a different schema. @@ -106,7 +105,7 @@ store.writeOperation(operation, data).also { store.publish(it) } Previously, if you configured custom scalar adapters on your client, you had to pass them to the `ApolloStore` methods. -Now, `ApolloClient.apolloStore` returns a `SimpleApolloStore`, a wrapper around `ApolloStore` which passes the client's `CustomScalarAdapters` automatically. +Now, `ApolloStore` has a reference to the client's `CustomScalarAdapters` so individual methods no longer need an adapters argument. ```kotlin // Before @@ -123,11 +122,35 @@ client.apolloStore.writeOperation( ) ``` +### Providing your own store + +The `ApolloStore` interface has been renamed to `CacheManager`. If you provide your own implementation, change the parent interface to `CacheManager`. +Correspondingly, the `ApolloClient.Builder.store()` extension has been renamed to `ApolloClient.Builder.cacheManager()`. + +```kotlin +// Before +val MyStore = object : ApolloStore { + // ... +} +val apolloClient = ApolloClient.Builder() + // ... + .store(MyStore) + .build() + +// After +val MyStore = object : CacheManager { + // ... +} +val apolloClient = ApolloClient.Builder() + // ... + .cacheManager(MyStore) + .build() +``` + ### Other changes - `readFragment()` now returns a `ReadResult` (it previously returned a ``). This allows for surfacing metadata associated to the returned data, e.g. staleness. - Records are now rooted per operation type (`QUERY_ROOT`, `MUTATION_ROOT`, `SUBSCRIPTION_ROOT`), when previously these were all at the same level, which could cause conflicts. -- `ApolloClient.apolloStore` is deprecated in favor of `ApolloClient.store` for consistency. ## CacheResolver, CacheKeyResolver diff --git a/Writerside/topics/pagination/pagination-other.md b/Writerside/topics/pagination/pagination-other.md index 4ac49f36..db217b46 100644 --- a/Writerside/topics/pagination/pagination-other.md +++ b/Writerside/topics/pagination/pagination-other.md @@ -15,7 +15,7 @@ extend type Query @fieldPolicy(forField: "usersPage" paginationArgs: "page") ``` -> This can also be done programmatically by configuring the `ApolloStore` with a [`FieldKeyGenerator`](https://apollographql.github.io/apollo-kotlin-normalized-cache/kdoc/normalized-cache/com.apollographql.cache.normalized.api/-field-key-generator/index.html?query=interface%20FieldKeyGenerator) implementation. +> This can also be done programmatically by configuring your cache with a [`FieldKeyGenerator`](https://apollographql.github.io/apollo-kotlin-normalized-cache/kdoc/normalized-cache/com.apollographql.cache.normalized.api/-field-key-generator/index.html?query=interface%20FieldKeyGenerator) implementation. With that in place, after fetching the first page, the cache will look like this: @@ -44,7 +44,7 @@ This is because the field key is now the same for all pages and the default merg #### Record merging To fix this, we need to supply the store with a piece of code that can merge the lists in a sensible way. -This is done by passing a [`RecordMerger`](https://apollographql.github.io/apollo-kotlin-normalized-cache/kdoc/normalized-cache/com.apollographql.cache.normalized.api/-record-merger/index.html?query=interface%20RecordMerger) to the `ApolloStore` constructor: +This is done by passing a [`RecordMerger`](https://apollographql.github.io/apollo-kotlin-normalized-cache/kdoc/normalized-cache/com.apollographql.cache.normalized.api/-record-merger/index.html?query=interface%20RecordMerger) when configuring your cache: ```kotlin object MyFieldMerger : FieldRecordMerger.FieldMerger { @@ -59,10 +59,13 @@ object MyFieldMerger : FieldRecordMerger.FieldMerger { } } -val apolloStore = ApolloStore( - normalizedCacheFactory = cacheFactory, - recordMerger = FieldRecordMerger(MyFieldMerger), // Configure the store with the custom merger -) +val client = ApolloClient.Builder() + // ... + .normalizedCache( + normalizedCacheFactory = cacheFactory, + recordMerger = FieldRecordMerger(MyFieldMerger), // Configure the store with the custom merger + ) + .build() ``` With this, the cache will be as expected after fetching the second page: @@ -99,7 +102,7 @@ Now let's store in the metadata of each `UserConnection` field the values of the as well as the values of the first and last cursor in its list. This will allow us to insert new pages in the correct position later on. -This is done by passing a [`MetadataGenerator`](https://apollographql.github.io/apollo-kotlin-normalized-cache/kdoc/normalized-cache/com.apollographql.cache.normalized.api/-metadata-generator/index.html?query=interface%20MetadataGenerator) to the `ApolloStore` constructor: +This is done by passing a [`MetadataGenerator`](https://apollographql.github.io/apollo-kotlin-normalized-cache/kdoc/normalized-cache/com.apollographql.cache.normalized.api/-metadata-generator/index.html?query=interface%20MetadataGenerator) when configuring the cache: ```kotlin class ConnectionMetadataGenerator : MetadataGenerator { @@ -144,7 +147,7 @@ extend type Query @typePolicy(embeddedFields: "usersConnection") extend type UserConnection @typePolicy(embeddedFields: "edges") ``` -> This can also be done programmatically by configuring the `ApolloStore` with an [`EmbeddedFieldsProvider`](https://apollographql.github.io/apollo-kotlin-normalized-cache/kdoc/normalized-cache/com.apollographql.cache.normalized.api/-embedded-fields-provider/index.html?query=interface%20EmbeddedFieldsProvider) implementation. +> This can also be done programmatically by configuring the cache with an [`EmbeddedFieldsProvider`](https://apollographql.github.io/apollo-kotlin-normalized-cache/kdoc/normalized-cache/com.apollographql.cache.normalized.api/-embedded-fields-provider/index.html?query=interface%20EmbeddedFieldsProvider) implementation. Now that we have the metadata and embedded fields in place, we can implement the `RecordMerger` (simplified for brevity): diff --git a/Writerside/topics/pagination/pagination-relay-style.md b/Writerside/topics/pagination/pagination-relay-style.md index 55604c2c..c8845ff8 100644 --- a/Writerside/topics/pagination/pagination-relay-style.md +++ b/Writerside/topics/pagination/pagination-relay-style.md @@ -55,14 +55,17 @@ that return a connection: extend type Query @typePolicy(connectionFields: "usersConnection") ``` -In Kotlin, configure the `ApolloStore` like this, using the generated `Pagination` object: +In Kotlin, configure the cache like this, using the generated `Pagination` object: ```kotlin -val apolloStore = ApolloStore( - normalizedCacheFactory = cacheFactory, - metadataGenerator = ConnectionMetadataGenerator(Pagination.connectionTypes), - recordMerger = ConnectionRecordMerger -) +val client = ApolloClient.Builder() + // ... + .normalizedCache( + normalizedCacheFactory = cacheFactory, + metadataGenerator = ConnectionMetadataGenerator(Pagination.connectionTypes), + recordMerger = ConnectionRecordMerger + ) + .build() ``` Query `UsersConnection()` to fetch new pages and update the cache, and watch it to observe the full list. diff --git a/normalized-cache-sqlite/src/commonTest/kotlin/com/apollographql/cache/normalized/sql/TrimTest.kt b/normalized-cache-sqlite/src/commonTest/kotlin/com/apollographql/cache/normalized/sql/TrimTest.kt index c224136a..23cdc865 100644 --- a/normalized-cache-sqlite/src/commonTest/kotlin/com/apollographql/cache/normalized/sql/TrimTest.kt +++ b/normalized-cache-sqlite/src/commonTest/kotlin/com/apollographql/cache/normalized/sql/TrimTest.kt @@ -1,6 +1,6 @@ package com.apollographql.cache.normalized.sql -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.CacheHeaders import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.DefaultRecordMerger @@ -13,7 +13,7 @@ import kotlin.test.assertNull class TrimTest { @Test fun trimTest() { - val apolloStore = ApolloStore(SqlNormalizedCacheFactory()).also { it.clearAll() } + val cacheManager = CacheManager(SqlNormalizedCacheFactory()).also { it.clearAll() } val largeString = "".padStart(1024, '?') @@ -23,7 +23,7 @@ class TrimTest { mutationId = null, metadata = emptyMap() ) - apolloStore.accessCache { it.merge(oldRecord, CacheHeaders.NONE, recordMerger = DefaultRecordMerger) } + cacheManager.accessCache { it.merge(oldRecord, CacheHeaders.NONE, recordMerger = DefaultRecordMerger) } val newRecords = 0.until(2 * 1024).map { Record( @@ -33,16 +33,16 @@ class TrimTest { metadata = emptyMap() ).withDates(receivedDate = it.toString(), expirationDate = null) } - apolloStore.accessCache { it.merge(newRecords, CacheHeaders.NONE, recordMerger = DefaultRecordMerger) } + cacheManager.accessCache { it.merge(newRecords, CacheHeaders.NONE, recordMerger = DefaultRecordMerger) } - val sizeBeforeTrim = apolloStore.trim(-1, 0.1f) + val sizeBeforeTrim = cacheManager.trim(-1, 0.1f) assertEquals(8515584, sizeBeforeTrim) // Trim the cache by 10% - val sizeAfterTrim = apolloStore.trim(8515584, 0.1f) + val sizeAfterTrim = cacheManager.trim(8515584, 0.1f) assertEquals(7667712, sizeAfterTrim) // The oldest key must have been removed - assertNull(apolloStore.accessCache { it.loadRecord(CacheKey("old"), CacheHeaders.NONE) }) + assertNull(cacheManager.accessCache { it.loadRecord(CacheKey("old"), CacheHeaders.NONE) }) } } diff --git a/normalized-cache/api/normalized-cache.api b/normalized-cache/api/normalized-cache.api index b6eb8c96..39591301 100644 --- a/normalized-cache/api/normalized-cache.api +++ b/normalized-cache/api/normalized-cache.api @@ -1,52 +1,34 @@ -public abstract interface class com/apollographql/cache/normalized/ApolloStore { - public static final field Companion Lcom/apollographql/cache/normalized/ApolloStore$Companion; - public abstract fun accessCache (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun clearAll ()Z - public abstract fun dispose ()V - public abstract fun dump ()Ljava/util/Map; - public abstract fun getChangedKeys ()Lkotlinx/coroutines/flow/SharedFlow; - public abstract fun normalize-niOPdRo (Lcom/apollographql/apollo/api/Executable;Ljava/util/Map;Ljava/lang/String;Lcom/apollographql/apollo/api/CustomScalarAdapters;)Ljava/util/Map; - public abstract fun publish (Ljava/util/Set;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun readFragment-dEpVOtE (Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Lcom/apollographql/cache/normalized/ApolloStore$ReadResult; - public abstract fun readOperation (Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Lcom/apollographql/apollo/api/ApolloResponse; - public abstract fun remove (Ljava/util/List;Z)I - public abstract fun remove-eNSUWrY (Ljava/lang/String;Z)Z - public abstract fun rollbackOptimisticUpdates (Ljava/util/UUID;)Ljava/util/Set; - public abstract fun trim (JF)J - public abstract fun writeFragment-1qdIjGk (Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/Fragment$Data;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Ljava/util/Set; - public abstract fun writeOperation (Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/Operation$Data;Ljava/util/List;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Ljava/util/Set; - public abstract fun writeOperation (Lcom/apollographql/apollo/api/Operation;Ljava/util/Map;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Ljava/util/Set; - public abstract fun writeOptimisticUpdates (Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/Operation$Data;Ljava/util/UUID;Lcom/apollographql/apollo/api/CustomScalarAdapters;)Ljava/util/Set; - public abstract fun writeOptimisticUpdates-1qdIjGk (Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/Fragment$Data;Ljava/util/UUID;Lcom/apollographql/apollo/api/CustomScalarAdapters;)Ljava/util/Set; -} - -public final class com/apollographql/cache/normalized/ApolloStore$Companion { - public final fun getALL_KEYS ()Lkotlin/collections/AbstractSet; -} - -public final class com/apollographql/cache/normalized/ApolloStore$DefaultImpls { - public static synthetic fun normalize-niOPdRo$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/Executable;Ljava/util/Map;Ljava/lang/String;Lcom/apollographql/apollo/api/CustomScalarAdapters;ILjava/lang/Object;)Ljava/util/Map; - public static synthetic fun readFragment-dEpVOtE$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Lcom/apollographql/cache/normalized/ApolloStore$ReadResult; - public static synthetic fun readOperation$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Lcom/apollographql/apollo/api/ApolloResponse; +public final class com/apollographql/cache/normalized/ApolloStore { + public fun (Lcom/apollographql/cache/normalized/CacheManager;Lcom/apollographql/apollo/api/CustomScalarAdapters;)V + public final fun accessCache (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public final fun clearAll ()Z + public final fun dispose ()V + public final fun dump ()Ljava/util/Map; + public final fun getCacheManager ()Lcom/apollographql/cache/normalized/CacheManager; + public final fun getChangedKeys ()Lkotlinx/coroutines/flow/SharedFlow; + public final fun getCustomScalarAdapters ()Lcom/apollographql/apollo/api/CustomScalarAdapters; + public final fun normalize-Hljz6HE (Lcom/apollographql/apollo/api/Executable;Ljava/util/Map;Ljava/lang/String;)Ljava/util/Map; + public static synthetic fun normalize-Hljz6HE$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/Executable;Ljava/util/Map;Ljava/lang/String;ILjava/lang/Object;)Ljava/util/Map; + public final fun publish (Ljava/util/Set;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun readFragment-0aEo43o (Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Lcom/apollographql/cache/normalized/CacheManager$ReadResult; + public static synthetic fun readFragment-0aEo43o$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Lcom/apollographql/cache/normalized/CacheManager$ReadResult; + public final fun readOperation (Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Lcom/apollographql/apollo/api/ApolloResponse; + public static synthetic fun readOperation$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Lcom/apollographql/apollo/api/ApolloResponse; + public final fun remove (Ljava/util/List;Z)I public static synthetic fun remove$default (Lcom/apollographql/cache/normalized/ApolloStore;Ljava/util/List;ZILjava/lang/Object;)I + public final fun remove-eNSUWrY (Ljava/lang/String;Z)Z public static synthetic fun remove-eNSUWrY$default (Lcom/apollographql/cache/normalized/ApolloStore;Ljava/lang/String;ZILjava/lang/Object;)Z + public final fun rollbackOptimisticUpdates (Ljava/util/UUID;)Ljava/util/Set; + public final fun trim (JF)J public static synthetic fun trim$default (Lcom/apollographql/cache/normalized/ApolloStore;JFILjava/lang/Object;)J - public static synthetic fun writeFragment-1qdIjGk$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/Fragment$Data;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Ljava/util/Set; - public static synthetic fun writeOperation$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/Operation$Data;Ljava/util/List;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Ljava/util/Set; - public static synthetic fun writeOperation$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/Operation;Ljava/util/Map;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Ljava/util/Set; - public static synthetic fun writeOptimisticUpdates$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/Operation$Data;Ljava/util/UUID;Lcom/apollographql/apollo/api/CustomScalarAdapters;ILjava/lang/Object;)Ljava/util/Set; - public static synthetic fun writeOptimisticUpdates-1qdIjGk$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/Fragment$Data;Ljava/util/UUID;Lcom/apollographql/apollo/api/CustomScalarAdapters;ILjava/lang/Object;)Ljava/util/Set; -} - -public final class com/apollographql/cache/normalized/ApolloStore$ReadResult { - public fun (Lcom/apollographql/apollo/api/Executable$Data;Lcom/apollographql/cache/normalized/api/CacheHeaders;)V - public final fun getCacheHeaders ()Lcom/apollographql/cache/normalized/api/CacheHeaders; - public final fun getData ()Lcom/apollographql/apollo/api/Executable$Data; -} - -public final class com/apollographql/cache/normalized/ApolloStoreKt { - public static final fun ApolloStore (Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory;Lcom/apollographql/cache/normalized/api/CacheKeyGenerator;Lcom/apollographql/cache/normalized/api/MetadataGenerator;Lcom/apollographql/cache/normalized/api/CacheResolver;Lcom/apollographql/cache/normalized/api/RecordMerger;Lcom/apollographql/cache/normalized/api/FieldKeyGenerator;Lcom/apollographql/cache/normalized/api/EmbeddedFieldsProvider;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;)Lcom/apollographql/cache/normalized/ApolloStore; - public static synthetic fun ApolloStore$default (Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory;Lcom/apollographql/cache/normalized/api/CacheKeyGenerator;Lcom/apollographql/cache/normalized/api/MetadataGenerator;Lcom/apollographql/cache/normalized/api/CacheResolver;Lcom/apollographql/cache/normalized/api/RecordMerger;Lcom/apollographql/cache/normalized/api/FieldKeyGenerator;Lcom/apollographql/cache/normalized/api/EmbeddedFieldsProvider;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;ILjava/lang/Object;)Lcom/apollographql/cache/normalized/ApolloStore; + public final fun writeFragment-dEpVOtE (Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/Fragment$Data;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Ljava/util/Set; + public static synthetic fun writeFragment-dEpVOtE$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/Fragment$Data;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Ljava/util/Set; + public final fun writeOperation (Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/Operation$Data;Ljava/util/List;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Ljava/util/Set; + public final fun writeOperation (Lcom/apollographql/apollo/api/Operation;Ljava/util/Map;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Ljava/util/Set; + public static synthetic fun writeOperation$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/Operation$Data;Ljava/util/List;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Ljava/util/Set; + public static synthetic fun writeOperation$default (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/Operation;Ljava/util/Map;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Ljava/util/Set; + public final fun writeOptimisticUpdates (Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/Operation$Data;Ljava/util/UUID;)Ljava/util/Set; + public final fun writeOptimisticUpdates-dEpVOtE (Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/Fragment$Data;Ljava/util/UUID;)Ljava/util/Set; } public final class com/apollographql/cache/normalized/CacheInfo : com/apollographql/apollo/api/ExecutionContext$Element { @@ -82,6 +64,57 @@ public final class com/apollographql/cache/normalized/CacheInfo$Builder { public final class com/apollographql/cache/normalized/CacheInfo$Key : com/apollographql/apollo/api/ExecutionContext$Key { } +public abstract interface class com/apollographql/cache/normalized/CacheManager { + public static final field Companion Lcom/apollographql/cache/normalized/CacheManager$Companion; + public abstract fun accessCache (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public abstract fun clearAll ()Z + public abstract fun dispose ()V + public abstract fun dump ()Ljava/util/Map; + public abstract fun getChangedKeys ()Lkotlinx/coroutines/flow/SharedFlow; + public abstract fun normalize-niOPdRo (Lcom/apollographql/apollo/api/Executable;Ljava/util/Map;Ljava/lang/String;Lcom/apollographql/apollo/api/CustomScalarAdapters;)Ljava/util/Map; + public abstract fun publish (Ljava/util/Set;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public abstract fun readFragment-dEpVOtE (Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Lcom/apollographql/cache/normalized/CacheManager$ReadResult; + public abstract fun readOperation (Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Lcom/apollographql/apollo/api/ApolloResponse; + public abstract fun remove (Ljava/util/List;Z)I + public abstract fun remove-eNSUWrY (Ljava/lang/String;Z)Z + public abstract fun rollbackOptimisticUpdates (Ljava/util/UUID;)Ljava/util/Set; + public abstract fun trim (JF)J + public abstract fun writeFragment-1qdIjGk (Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/Fragment$Data;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Ljava/util/Set; + public abstract fun writeOperation (Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/Operation$Data;Ljava/util/List;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Ljava/util/Set; + public abstract fun writeOperation (Lcom/apollographql/apollo/api/Operation;Ljava/util/Map;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Ljava/util/Set; + public abstract fun writeOptimisticUpdates (Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/Operation$Data;Ljava/util/UUID;Lcom/apollographql/apollo/api/CustomScalarAdapters;)Ljava/util/Set; + public abstract fun writeOptimisticUpdates-1qdIjGk (Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/Fragment$Data;Ljava/util/UUID;Lcom/apollographql/apollo/api/CustomScalarAdapters;)Ljava/util/Set; +} + +public final class com/apollographql/cache/normalized/CacheManager$Companion { + public final fun getALL_KEYS ()Lkotlin/collections/AbstractSet; +} + +public final class com/apollographql/cache/normalized/CacheManager$DefaultImpls { + public static synthetic fun normalize-niOPdRo$default (Lcom/apollographql/cache/normalized/CacheManager;Lcom/apollographql/apollo/api/Executable;Ljava/util/Map;Ljava/lang/String;Lcom/apollographql/apollo/api/CustomScalarAdapters;ILjava/lang/Object;)Ljava/util/Map; + public static synthetic fun readFragment-dEpVOtE$default (Lcom/apollographql/cache/normalized/CacheManager;Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Lcom/apollographql/cache/normalized/CacheManager$ReadResult; + public static synthetic fun readOperation$default (Lcom/apollographql/cache/normalized/CacheManager;Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Lcom/apollographql/apollo/api/ApolloResponse; + public static synthetic fun remove$default (Lcom/apollographql/cache/normalized/CacheManager;Ljava/util/List;ZILjava/lang/Object;)I + public static synthetic fun remove-eNSUWrY$default (Lcom/apollographql/cache/normalized/CacheManager;Ljava/lang/String;ZILjava/lang/Object;)Z + public static synthetic fun trim$default (Lcom/apollographql/cache/normalized/CacheManager;JFILjava/lang/Object;)J + public static synthetic fun writeFragment-1qdIjGk$default (Lcom/apollographql/cache/normalized/CacheManager;Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/Fragment$Data;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Ljava/util/Set; + public static synthetic fun writeOperation$default (Lcom/apollographql/cache/normalized/CacheManager;Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/Operation$Data;Ljava/util/List;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Ljava/util/Set; + public static synthetic fun writeOperation$default (Lcom/apollographql/cache/normalized/CacheManager;Lcom/apollographql/apollo/api/Operation;Ljava/util/Map;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Ljava/util/Set; + public static synthetic fun writeOptimisticUpdates$default (Lcom/apollographql/cache/normalized/CacheManager;Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/Operation$Data;Ljava/util/UUID;Lcom/apollographql/apollo/api/CustomScalarAdapters;ILjava/lang/Object;)Ljava/util/Set; + public static synthetic fun writeOptimisticUpdates-1qdIjGk$default (Lcom/apollographql/cache/normalized/CacheManager;Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/Fragment$Data;Ljava/util/UUID;Lcom/apollographql/apollo/api/CustomScalarAdapters;ILjava/lang/Object;)Ljava/util/Set; +} + +public final class com/apollographql/cache/normalized/CacheManager$ReadResult { + public fun (Lcom/apollographql/apollo/api/Executable$Data;Lcom/apollographql/cache/normalized/api/CacheHeaders;)V + public final fun getCacheHeaders ()Lcom/apollographql/cache/normalized/api/CacheHeaders; + public final fun getData ()Lcom/apollographql/apollo/api/Executable$Data; +} + +public final class com/apollographql/cache/normalized/CacheManagerKt { + public static final fun CacheManager (Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory;Lcom/apollographql/cache/normalized/api/CacheKeyGenerator;Lcom/apollographql/cache/normalized/api/MetadataGenerator;Lcom/apollographql/cache/normalized/api/CacheResolver;Lcom/apollographql/cache/normalized/api/RecordMerger;Lcom/apollographql/cache/normalized/api/FieldKeyGenerator;Lcom/apollographql/cache/normalized/api/EmbeddedFieldsProvider;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;)Lcom/apollographql/cache/normalized/CacheManager; + public static synthetic fun CacheManager$default (Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory;Lcom/apollographql/cache/normalized/api/CacheKeyGenerator;Lcom/apollographql/cache/normalized/api/MetadataGenerator;Lcom/apollographql/cache/normalized/api/CacheResolver;Lcom/apollographql/cache/normalized/api/RecordMerger;Lcom/apollographql/cache/normalized/api/FieldKeyGenerator;Lcom/apollographql/cache/normalized/api/EmbeddedFieldsProvider;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;ILjava/lang/Object;)Lcom/apollographql/cache/normalized/CacheManager; +} + public final class com/apollographql/cache/normalized/CacheMissLoggingInterceptor : com/apollographql/apollo/interceptor/ApolloInterceptor { public fun (Lkotlin/jvm/functions/Function1;)V public fun intercept (Lcom/apollographql/apollo/api/ApolloRequest;Lcom/apollographql/apollo/interceptor/ApolloInterceptorChain;)Lkotlinx/coroutines/flow/Flow; @@ -141,6 +174,8 @@ public final class com/apollographql/cache/normalized/NormalizedCache { public static final fun addCacheHeader (Lcom/apollographql/apollo/api/MutableExecutionOptions;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object; public static final fun cacheHeaders (Lcom/apollographql/apollo/api/ApolloResponse$Builder;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Lcom/apollographql/apollo/api/ApolloResponse$Builder; public static final fun cacheHeaders (Lcom/apollographql/apollo/api/MutableExecutionOptions;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Ljava/lang/Object; + public static final fun cacheManager (Lcom/apollographql/apollo/ApolloClient$Builder;Lcom/apollographql/cache/normalized/CacheManager;Z)Lcom/apollographql/apollo/ApolloClient$Builder; + public static synthetic fun cacheManager$default (Lcom/apollographql/apollo/ApolloClient$Builder;Lcom/apollographql/cache/normalized/CacheManager;ZILjava/lang/Object;)Lcom/apollographql/apollo/ApolloClient$Builder; public static final fun configureApolloClientBuilder2 (Lcom/apollographql/apollo/ApolloClient$Builder;Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory;)Lcom/apollographql/apollo/ApolloClient$Builder; public static final fun configureApolloClientBuilder2 (Lcom/apollographql/apollo/ApolloClient$Builder;Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory;Lcom/apollographql/cache/normalized/api/CacheKeyGenerator;)Lcom/apollographql/apollo/ApolloClient$Builder; public static final fun configureApolloClientBuilder2 (Lcom/apollographql/apollo/ApolloClient$Builder;Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory;Lcom/apollographql/cache/normalized/api/CacheKeyGenerator;Lcom/apollographql/cache/normalized/api/MetadataGenerator;)Lcom/apollographql/apollo/ApolloClient$Builder; @@ -156,11 +191,10 @@ public final class com/apollographql/cache/normalized/NormalizedCache { public static final fun fetchFromCache (Lcom/apollographql/apollo/api/ApolloRequest$Builder;Z)Lcom/apollographql/apollo/api/ApolloRequest$Builder; public static final fun fetchPolicy (Lcom/apollographql/apollo/api/MutableExecutionOptions;Lcom/apollographql/cache/normalized/FetchPolicy;)Ljava/lang/Object; public static final fun fetchPolicyInterceptor (Lcom/apollographql/apollo/api/MutableExecutionOptions;Lcom/apollographql/apollo/interceptor/ApolloInterceptor;)Ljava/lang/Object; - public static final fun getApolloStore (Lcom/apollographql/apollo/ApolloClient;)Lcom/apollographql/cache/normalized/SimpleApolloStore; + public static final fun getApolloStore (Lcom/apollographql/apollo/ApolloClient;)Lcom/apollographql/cache/normalized/ApolloStore; public static final fun getCacheHeaders (Lcom/apollographql/apollo/api/ApolloResponse;)Lcom/apollographql/cache/normalized/api/CacheHeaders; public static final fun getCacheInfo (Lcom/apollographql/apollo/api/ApolloResponse;)Lcom/apollographql/cache/normalized/CacheInfo; public static final fun getFetchFromCache (Lcom/apollographql/apollo/api/ApolloRequest;)Z - public static final fun getStore (Lcom/apollographql/apollo/ApolloClient;)Lcom/apollographql/cache/normalized/SimpleApolloStore; public static final fun isFromCache (Lcom/apollographql/apollo/api/ApolloResponse;)Z public static final fun maxStale-HG0u8IE (Lcom/apollographql/apollo/api/MutableExecutionOptions;J)Ljava/lang/Object; public static final fun memoryCacheOnly (Lcom/apollographql/apollo/api/MutableExecutionOptions;Z)Ljava/lang/Object; @@ -168,8 +202,6 @@ public final class com/apollographql/cache/normalized/NormalizedCache { public static final fun optimisticUpdates (Lcom/apollographql/apollo/api/ApolloRequest$Builder;Lcom/apollographql/apollo/api/Mutation$Data;)Lcom/apollographql/apollo/api/ApolloRequest$Builder; public static final fun refetchPolicy (Lcom/apollographql/apollo/api/MutableExecutionOptions;Lcom/apollographql/cache/normalized/FetchPolicy;)Ljava/lang/Object; public static final fun refetchPolicyInterceptor (Lcom/apollographql/apollo/api/MutableExecutionOptions;Lcom/apollographql/apollo/interceptor/ApolloInterceptor;)Ljava/lang/Object; - public static final fun store (Lcom/apollographql/apollo/ApolloClient$Builder;Lcom/apollographql/cache/normalized/ApolloStore;Z)Lcom/apollographql/apollo/ApolloClient$Builder; - public static synthetic fun store$default (Lcom/apollographql/apollo/ApolloClient$Builder;Lcom/apollographql/cache/normalized/ApolloStore;ZILjava/lang/Object;)Lcom/apollographql/apollo/ApolloClient$Builder; public static final fun storeExpirationDate (Lcom/apollographql/apollo/api/MutableExecutionOptions;Z)Ljava/lang/Object; public static final fun storePartialResponses (Lcom/apollographql/apollo/api/MutableExecutionOptions;Z)Ljava/lang/Void; public static final fun storeReceivedDate (Lcom/apollographql/apollo/api/MutableExecutionOptions;Z)Ljava/lang/Object; @@ -184,37 +216,6 @@ public final class com/apollographql/cache/normalized/RemovedFieldsAndRecords { public final fun getRemovedRecords ()Ljava/util/Set; } -public final class com/apollographql/cache/normalized/SimpleApolloStore { - public fun (Lcom/apollographql/cache/normalized/ApolloStore;Lcom/apollographql/apollo/api/CustomScalarAdapters;)V - public final fun accessCache (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public final fun clearAll ()Z - public final fun dispose ()V - public final fun dump ()Ljava/util/Map; - public final fun getChangedKeys ()Lkotlinx/coroutines/flow/SharedFlow; - public final fun normalize-Hljz6HE (Lcom/apollographql/apollo/api/Executable;Ljava/util/Map;Ljava/lang/String;)Ljava/util/Map; - public static synthetic fun normalize-Hljz6HE$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/apollo/api/Executable;Ljava/util/Map;Ljava/lang/String;ILjava/lang/Object;)Ljava/util/Map; - public final fun publish (Ljava/util/Set;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun readFragment-0aEo43o (Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Lcom/apollographql/cache/normalized/ApolloStore$ReadResult; - public static synthetic fun readFragment-0aEo43o$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Lcom/apollographql/cache/normalized/ApolloStore$ReadResult; - public final fun readOperation (Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Lcom/apollographql/apollo/api/ApolloResponse; - public static synthetic fun readOperation$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Lcom/apollographql/apollo/api/ApolloResponse; - public final fun remove (Ljava/util/List;Z)I - public static synthetic fun remove$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;Ljava/util/List;ZILjava/lang/Object;)I - public final fun remove-eNSUWrY (Ljava/lang/String;Z)Z - public static synthetic fun remove-eNSUWrY$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;Ljava/lang/String;ZILjava/lang/Object;)Z - public final fun rollbackOptimisticUpdates (Ljava/util/UUID;)Ljava/util/Set; - public final fun trim (JF)J - public static synthetic fun trim$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;JFILjava/lang/Object;)J - public final fun writeFragment-dEpVOtE (Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/Fragment$Data;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Ljava/util/Set; - public static synthetic fun writeFragment-dEpVOtE$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/Fragment$Data;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Ljava/util/Set; - public final fun writeOperation (Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/Operation$Data;Ljava/util/List;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Ljava/util/Set; - public final fun writeOperation (Lcom/apollographql/apollo/api/Operation;Ljava/util/Map;Lcom/apollographql/cache/normalized/api/CacheHeaders;)Ljava/util/Set; - public static synthetic fun writeOperation$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/Operation$Data;Ljava/util/List;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Ljava/util/Set; - public static synthetic fun writeOperation$default (Lcom/apollographql/cache/normalized/SimpleApolloStore;Lcom/apollographql/apollo/api/Operation;Ljava/util/Map;Lcom/apollographql/cache/normalized/api/CacheHeaders;ILjava/lang/Object;)Ljava/util/Set; - public final fun writeOptimisticUpdates (Lcom/apollographql/apollo/api/Operation;Lcom/apollographql/apollo/api/Operation$Data;Ljava/util/UUID;)Ljava/util/Set; - public final fun writeOptimisticUpdates-dEpVOtE (Lcom/apollographql/apollo/api/Fragment;Ljava/lang/String;Lcom/apollographql/apollo/api/Fragment$Data;Ljava/util/UUID;)Ljava/util/Set; -} - public final class com/apollographql/cache/normalized/VersionKt { public static final field VERSION Ljava/lang/String; } diff --git a/normalized-cache/api/normalized-cache.klib.api b/normalized-cache/api/normalized-cache.klib.api index e119a291..817e7c28 100644 --- a/normalized-cache/api/normalized-cache.klib.api +++ b/normalized-cache/api/normalized-cache.klib.api @@ -76,40 +76,40 @@ abstract interface com.apollographql.cache.normalized.api/RecordMerger { // com. abstract fun merge(com.apollographql.cache.normalized.api/RecordMergerContext): kotlin/Pair> // com.apollographql.cache.normalized.api/RecordMerger.merge|merge(com.apollographql.cache.normalized.api.RecordMergerContext){}[0] } -abstract interface com.apollographql.cache.normalized/ApolloStore { // com.apollographql.cache.normalized/ApolloStore|null[0] - abstract val changedKeys // com.apollographql.cache.normalized/ApolloStore.changedKeys|{}changedKeys[0] - abstract fun (): kotlinx.coroutines.flow/SharedFlow> // com.apollographql.cache.normalized/ApolloStore.changedKeys.|(){}[0] - - abstract fun <#A1: com.apollographql.apollo.api/Executable.Data> normalize(com.apollographql.apollo.api/Executable<#A1>, kotlin.collections/Map, com.apollographql.cache.normalized.api/CacheKey = ..., com.apollographql.apollo.api/CustomScalarAdapters = ...): kotlin.collections/Map // com.apollographql.cache.normalized/ApolloStore.normalize|normalize(com.apollographql.apollo.api.Executable<0:0>;kotlin.collections.Map;com.apollographql.cache.normalized.api.CacheKey;com.apollographql.apollo.api.CustomScalarAdapters){0§}[0] - abstract fun <#A1: com.apollographql.apollo.api/Fragment.Data> readFragment(com.apollographql.apollo.api/Fragment<#A1>, com.apollographql.cache.normalized.api/CacheKey, com.apollographql.apollo.api/CustomScalarAdapters = ..., com.apollographql.cache.normalized.api/CacheHeaders = ...): com.apollographql.cache.normalized/ApolloStore.ReadResult<#A1> // com.apollographql.cache.normalized/ApolloStore.readFragment|readFragment(com.apollographql.apollo.api.Fragment<0:0>;com.apollographql.cache.normalized.api.CacheKey;com.apollographql.apollo.api.CustomScalarAdapters;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] - abstract fun <#A1: com.apollographql.apollo.api/Fragment.Data> writeFragment(com.apollographql.apollo.api/Fragment<#A1>, com.apollographql.cache.normalized.api/CacheKey, #A1, com.apollographql.apollo.api/CustomScalarAdapters = ..., com.apollographql.cache.normalized.api/CacheHeaders = ...): kotlin.collections/Set // com.apollographql.cache.normalized/ApolloStore.writeFragment|writeFragment(com.apollographql.apollo.api.Fragment<0:0>;com.apollographql.cache.normalized.api.CacheKey;0:0;com.apollographql.apollo.api.CustomScalarAdapters;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] - abstract fun <#A1: com.apollographql.apollo.api/Fragment.Data> writeOptimisticUpdates(com.apollographql.apollo.api/Fragment<#A1>, com.apollographql.cache.normalized.api/CacheKey, #A1, com.benasher44.uuid/Uuid, com.apollographql.apollo.api/CustomScalarAdapters = ...): kotlin.collections/Set // com.apollographql.cache.normalized/ApolloStore.writeOptimisticUpdates|writeOptimisticUpdates(com.apollographql.apollo.api.Fragment<0:0>;com.apollographql.cache.normalized.api.CacheKey;0:0;com.benasher44.uuid.Uuid;com.apollographql.apollo.api.CustomScalarAdapters){0§}[0] - abstract fun <#A1: com.apollographql.apollo.api/Operation.Data> readOperation(com.apollographql.apollo.api/Operation<#A1>, com.apollographql.apollo.api/CustomScalarAdapters = ..., com.apollographql.cache.normalized.api/CacheHeaders = ...): com.apollographql.apollo.api/ApolloResponse<#A1> // com.apollographql.cache.normalized/ApolloStore.readOperation|readOperation(com.apollographql.apollo.api.Operation<0:0>;com.apollographql.apollo.api.CustomScalarAdapters;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] - abstract fun <#A1: com.apollographql.apollo.api/Operation.Data> writeOperation(com.apollographql.apollo.api/Operation<#A1>, #A1, kotlin.collections/List? = ..., com.apollographql.apollo.api/CustomScalarAdapters = ..., com.apollographql.cache.normalized.api/CacheHeaders = ...): kotlin.collections/Set // com.apollographql.cache.normalized/ApolloStore.writeOperation|writeOperation(com.apollographql.apollo.api.Operation<0:0>;0:0;kotlin.collections.List?;com.apollographql.apollo.api.CustomScalarAdapters;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] - abstract fun <#A1: com.apollographql.apollo.api/Operation.Data> writeOperation(com.apollographql.apollo.api/Operation<#A1>, kotlin.collections/Map, com.apollographql.apollo.api/CustomScalarAdapters = ..., com.apollographql.cache.normalized.api/CacheHeaders = ...): kotlin.collections/Set // com.apollographql.cache.normalized/ApolloStore.writeOperation|writeOperation(com.apollographql.apollo.api.Operation<0:0>;kotlin.collections.Map;com.apollographql.apollo.api.CustomScalarAdapters;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] - abstract fun <#A1: com.apollographql.apollo.api/Operation.Data> writeOptimisticUpdates(com.apollographql.apollo.api/Operation<#A1>, #A1, com.benasher44.uuid/Uuid, com.apollographql.apollo.api/CustomScalarAdapters = ...): kotlin.collections/Set // com.apollographql.cache.normalized/ApolloStore.writeOptimisticUpdates|writeOptimisticUpdates(com.apollographql.apollo.api.Operation<0:0>;0:0;com.benasher44.uuid.Uuid;com.apollographql.apollo.api.CustomScalarAdapters){0§}[0] - abstract fun <#A1: kotlin/Any?> accessCache(kotlin/Function1): #A1 // com.apollographql.cache.normalized/ApolloStore.accessCache|accessCache(kotlin.Function1){0§}[0] - abstract fun clearAll(): kotlin/Boolean // com.apollographql.cache.normalized/ApolloStore.clearAll|clearAll(){}[0] - abstract fun dispose() // com.apollographql.cache.normalized/ApolloStore.dispose|dispose(){}[0] - abstract fun dump(): kotlin.collections/Map, kotlin.collections/Map> // com.apollographql.cache.normalized/ApolloStore.dump|dump(){}[0] - abstract fun remove(com.apollographql.cache.normalized.api/CacheKey, kotlin/Boolean = ...): kotlin/Boolean // com.apollographql.cache.normalized/ApolloStore.remove|remove(com.apollographql.cache.normalized.api.CacheKey;kotlin.Boolean){}[0] - abstract fun remove(kotlin.collections/List, kotlin/Boolean = ...): kotlin/Int // com.apollographql.cache.normalized/ApolloStore.remove|remove(kotlin.collections.List;kotlin.Boolean){}[0] - abstract fun rollbackOptimisticUpdates(com.benasher44.uuid/Uuid): kotlin.collections/Set // com.apollographql.cache.normalized/ApolloStore.rollbackOptimisticUpdates|rollbackOptimisticUpdates(com.benasher44.uuid.Uuid){}[0] - abstract fun trim(kotlin/Long, kotlin/Float = ...): kotlin/Long // com.apollographql.cache.normalized/ApolloStore.trim|trim(kotlin.Long;kotlin.Float){}[0] - abstract suspend fun publish(kotlin.collections/Set) // com.apollographql.cache.normalized/ApolloStore.publish|publish(kotlin.collections.Set){}[0] - - final class <#A1: com.apollographql.apollo.api/Executable.Data> ReadResult { // com.apollographql.cache.normalized/ApolloStore.ReadResult|null[0] - constructor (#A1, com.apollographql.cache.normalized.api/CacheHeaders) // com.apollographql.cache.normalized/ApolloStore.ReadResult.|(1:0;com.apollographql.cache.normalized.api.CacheHeaders){}[0] - - final val cacheHeaders // com.apollographql.cache.normalized/ApolloStore.ReadResult.cacheHeaders|{}cacheHeaders[0] - final fun (): com.apollographql.cache.normalized.api/CacheHeaders // com.apollographql.cache.normalized/ApolloStore.ReadResult.cacheHeaders.|(){}[0] - final val data // com.apollographql.cache.normalized/ApolloStore.ReadResult.data|{}data[0] - final fun (): #A1 // com.apollographql.cache.normalized/ApolloStore.ReadResult.data.|(){}[0] +abstract interface com.apollographql.cache.normalized/CacheManager { // com.apollographql.cache.normalized/CacheManager|null[0] + abstract val changedKeys // com.apollographql.cache.normalized/CacheManager.changedKeys|{}changedKeys[0] + abstract fun (): kotlinx.coroutines.flow/SharedFlow> // com.apollographql.cache.normalized/CacheManager.changedKeys.|(){}[0] + + abstract fun <#A1: com.apollographql.apollo.api/Executable.Data> normalize(com.apollographql.apollo.api/Executable<#A1>, kotlin.collections/Map, com.apollographql.cache.normalized.api/CacheKey = ..., com.apollographql.apollo.api/CustomScalarAdapters = ...): kotlin.collections/Map // com.apollographql.cache.normalized/CacheManager.normalize|normalize(com.apollographql.apollo.api.Executable<0:0>;kotlin.collections.Map;com.apollographql.cache.normalized.api.CacheKey;com.apollographql.apollo.api.CustomScalarAdapters){0§}[0] + abstract fun <#A1: com.apollographql.apollo.api/Fragment.Data> readFragment(com.apollographql.apollo.api/Fragment<#A1>, com.apollographql.cache.normalized.api/CacheKey, com.apollographql.apollo.api/CustomScalarAdapters = ..., com.apollographql.cache.normalized.api/CacheHeaders = ...): com.apollographql.cache.normalized/CacheManager.ReadResult<#A1> // com.apollographql.cache.normalized/CacheManager.readFragment|readFragment(com.apollographql.apollo.api.Fragment<0:0>;com.apollographql.cache.normalized.api.CacheKey;com.apollographql.apollo.api.CustomScalarAdapters;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] + abstract fun <#A1: com.apollographql.apollo.api/Fragment.Data> writeFragment(com.apollographql.apollo.api/Fragment<#A1>, com.apollographql.cache.normalized.api/CacheKey, #A1, com.apollographql.apollo.api/CustomScalarAdapters = ..., com.apollographql.cache.normalized.api/CacheHeaders = ...): kotlin.collections/Set // com.apollographql.cache.normalized/CacheManager.writeFragment|writeFragment(com.apollographql.apollo.api.Fragment<0:0>;com.apollographql.cache.normalized.api.CacheKey;0:0;com.apollographql.apollo.api.CustomScalarAdapters;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] + abstract fun <#A1: com.apollographql.apollo.api/Fragment.Data> writeOptimisticUpdates(com.apollographql.apollo.api/Fragment<#A1>, com.apollographql.cache.normalized.api/CacheKey, #A1, com.benasher44.uuid/Uuid, com.apollographql.apollo.api/CustomScalarAdapters = ...): kotlin.collections/Set // com.apollographql.cache.normalized/CacheManager.writeOptimisticUpdates|writeOptimisticUpdates(com.apollographql.apollo.api.Fragment<0:0>;com.apollographql.cache.normalized.api.CacheKey;0:0;com.benasher44.uuid.Uuid;com.apollographql.apollo.api.CustomScalarAdapters){0§}[0] + abstract fun <#A1: com.apollographql.apollo.api/Operation.Data> readOperation(com.apollographql.apollo.api/Operation<#A1>, com.apollographql.apollo.api/CustomScalarAdapters = ..., com.apollographql.cache.normalized.api/CacheHeaders = ...): com.apollographql.apollo.api/ApolloResponse<#A1> // com.apollographql.cache.normalized/CacheManager.readOperation|readOperation(com.apollographql.apollo.api.Operation<0:0>;com.apollographql.apollo.api.CustomScalarAdapters;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] + abstract fun <#A1: com.apollographql.apollo.api/Operation.Data> writeOperation(com.apollographql.apollo.api/Operation<#A1>, #A1, kotlin.collections/List? = ..., com.apollographql.apollo.api/CustomScalarAdapters = ..., com.apollographql.cache.normalized.api/CacheHeaders = ...): kotlin.collections/Set // com.apollographql.cache.normalized/CacheManager.writeOperation|writeOperation(com.apollographql.apollo.api.Operation<0:0>;0:0;kotlin.collections.List?;com.apollographql.apollo.api.CustomScalarAdapters;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] + abstract fun <#A1: com.apollographql.apollo.api/Operation.Data> writeOperation(com.apollographql.apollo.api/Operation<#A1>, kotlin.collections/Map, com.apollographql.apollo.api/CustomScalarAdapters = ..., com.apollographql.cache.normalized.api/CacheHeaders = ...): kotlin.collections/Set // com.apollographql.cache.normalized/CacheManager.writeOperation|writeOperation(com.apollographql.apollo.api.Operation<0:0>;kotlin.collections.Map;com.apollographql.apollo.api.CustomScalarAdapters;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] + abstract fun <#A1: com.apollographql.apollo.api/Operation.Data> writeOptimisticUpdates(com.apollographql.apollo.api/Operation<#A1>, #A1, com.benasher44.uuid/Uuid, com.apollographql.apollo.api/CustomScalarAdapters = ...): kotlin.collections/Set // com.apollographql.cache.normalized/CacheManager.writeOptimisticUpdates|writeOptimisticUpdates(com.apollographql.apollo.api.Operation<0:0>;0:0;com.benasher44.uuid.Uuid;com.apollographql.apollo.api.CustomScalarAdapters){0§}[0] + abstract fun <#A1: kotlin/Any?> accessCache(kotlin/Function1): #A1 // com.apollographql.cache.normalized/CacheManager.accessCache|accessCache(kotlin.Function1){0§}[0] + abstract fun clearAll(): kotlin/Boolean // com.apollographql.cache.normalized/CacheManager.clearAll|clearAll(){}[0] + abstract fun dispose() // com.apollographql.cache.normalized/CacheManager.dispose|dispose(){}[0] + abstract fun dump(): kotlin.collections/Map, kotlin.collections/Map> // com.apollographql.cache.normalized/CacheManager.dump|dump(){}[0] + abstract fun remove(com.apollographql.cache.normalized.api/CacheKey, kotlin/Boolean = ...): kotlin/Boolean // com.apollographql.cache.normalized/CacheManager.remove|remove(com.apollographql.cache.normalized.api.CacheKey;kotlin.Boolean){}[0] + abstract fun remove(kotlin.collections/List, kotlin/Boolean = ...): kotlin/Int // com.apollographql.cache.normalized/CacheManager.remove|remove(kotlin.collections.List;kotlin.Boolean){}[0] + abstract fun rollbackOptimisticUpdates(com.benasher44.uuid/Uuid): kotlin.collections/Set // com.apollographql.cache.normalized/CacheManager.rollbackOptimisticUpdates|rollbackOptimisticUpdates(com.benasher44.uuid.Uuid){}[0] + abstract fun trim(kotlin/Long, kotlin/Float = ...): kotlin/Long // com.apollographql.cache.normalized/CacheManager.trim|trim(kotlin.Long;kotlin.Float){}[0] + abstract suspend fun publish(kotlin.collections/Set) // com.apollographql.cache.normalized/CacheManager.publish|publish(kotlin.collections.Set){}[0] + + final class <#A1: com.apollographql.apollo.api/Executable.Data> ReadResult { // com.apollographql.cache.normalized/CacheManager.ReadResult|null[0] + constructor (#A1, com.apollographql.cache.normalized.api/CacheHeaders) // com.apollographql.cache.normalized/CacheManager.ReadResult.|(1:0;com.apollographql.cache.normalized.api.CacheHeaders){}[0] + + final val cacheHeaders // com.apollographql.cache.normalized/CacheManager.ReadResult.cacheHeaders|{}cacheHeaders[0] + final fun (): com.apollographql.cache.normalized.api/CacheHeaders // com.apollographql.cache.normalized/CacheManager.ReadResult.cacheHeaders.|(){}[0] + final val data // com.apollographql.cache.normalized/CacheManager.ReadResult.data|{}data[0] + final fun (): #A1 // com.apollographql.cache.normalized/CacheManager.ReadResult.data.|(){}[0] } - final object Companion { // com.apollographql.cache.normalized/ApolloStore.Companion|null[0] - final val ALL_KEYS // com.apollographql.cache.normalized/ApolloStore.Companion.ALL_KEYS|{}ALL_KEYS[0] - final fun (): kotlin.collections/AbstractSet // com.apollographql.cache.normalized/ApolloStore.Companion.ALL_KEYS.|(){}[0] + final object Companion { // com.apollographql.cache.normalized/CacheManager.Companion|null[0] + final val ALL_KEYS // com.apollographql.cache.normalized/CacheManager.Companion.ALL_KEYS|{}ALL_KEYS[0] + final fun (): kotlin.collections/AbstractSet // com.apollographql.cache.normalized/CacheManager.Companion.ALL_KEYS.|(){}[0] } } @@ -402,6 +402,35 @@ final class com.apollographql.cache.normalized.memory/MemoryCacheFactory : com.a final fun create(): com.apollographql.cache.normalized.memory/MemoryCache // com.apollographql.cache.normalized.memory/MemoryCacheFactory.create|create(){}[0] } +final class com.apollographql.cache.normalized/ApolloStore { // com.apollographql.cache.normalized/ApolloStore|null[0] + constructor (com.apollographql.cache.normalized/CacheManager, com.apollographql.apollo.api/CustomScalarAdapters) // com.apollographql.cache.normalized/ApolloStore.|(com.apollographql.cache.normalized.CacheManager;com.apollographql.apollo.api.CustomScalarAdapters){}[0] + + final val cacheManager // com.apollographql.cache.normalized/ApolloStore.cacheManager|{}cacheManager[0] + final fun (): com.apollographql.cache.normalized/CacheManager // com.apollographql.cache.normalized/ApolloStore.cacheManager.|(){}[0] + final val changedKeys // com.apollographql.cache.normalized/ApolloStore.changedKeys|{}changedKeys[0] + final fun (): kotlinx.coroutines.flow/SharedFlow> // com.apollographql.cache.normalized/ApolloStore.changedKeys.|(){}[0] + final val customScalarAdapters // com.apollographql.cache.normalized/ApolloStore.customScalarAdapters|{}customScalarAdapters[0] + final fun (): com.apollographql.apollo.api/CustomScalarAdapters // com.apollographql.cache.normalized/ApolloStore.customScalarAdapters.|(){}[0] + + final fun <#A1: com.apollographql.apollo.api/Executable.Data> normalize(com.apollographql.apollo.api/Executable<#A1>, kotlin.collections/Map, com.apollographql.cache.normalized.api/CacheKey = ...): kotlin.collections/Map // com.apollographql.cache.normalized/ApolloStore.normalize|normalize(com.apollographql.apollo.api.Executable<0:0>;kotlin.collections.Map;com.apollographql.cache.normalized.api.CacheKey){0§}[0] + final fun <#A1: com.apollographql.apollo.api/Fragment.Data> readFragment(com.apollographql.apollo.api/Fragment<#A1>, com.apollographql.cache.normalized.api/CacheKey, com.apollographql.cache.normalized.api/CacheHeaders = ...): com.apollographql.cache.normalized/CacheManager.ReadResult<#A1> // com.apollographql.cache.normalized/ApolloStore.readFragment|readFragment(com.apollographql.apollo.api.Fragment<0:0>;com.apollographql.cache.normalized.api.CacheKey;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] + final fun <#A1: com.apollographql.apollo.api/Fragment.Data> writeFragment(com.apollographql.apollo.api/Fragment<#A1>, com.apollographql.cache.normalized.api/CacheKey, #A1, com.apollographql.cache.normalized.api/CacheHeaders = ...): kotlin.collections/Set // com.apollographql.cache.normalized/ApolloStore.writeFragment|writeFragment(com.apollographql.apollo.api.Fragment<0:0>;com.apollographql.cache.normalized.api.CacheKey;0:0;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] + final fun <#A1: com.apollographql.apollo.api/Fragment.Data> writeOptimisticUpdates(com.apollographql.apollo.api/Fragment<#A1>, com.apollographql.cache.normalized.api/CacheKey, #A1, com.benasher44.uuid/Uuid): kotlin.collections/Set // com.apollographql.cache.normalized/ApolloStore.writeOptimisticUpdates|writeOptimisticUpdates(com.apollographql.apollo.api.Fragment<0:0>;com.apollographql.cache.normalized.api.CacheKey;0:0;com.benasher44.uuid.Uuid){0§}[0] + final fun <#A1: com.apollographql.apollo.api/Operation.Data> readOperation(com.apollographql.apollo.api/Operation<#A1>, com.apollographql.cache.normalized.api/CacheHeaders = ...): com.apollographql.apollo.api/ApolloResponse<#A1> // com.apollographql.cache.normalized/ApolloStore.readOperation|readOperation(com.apollographql.apollo.api.Operation<0:0>;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] + final fun <#A1: com.apollographql.apollo.api/Operation.Data> writeOperation(com.apollographql.apollo.api/Operation<#A1>, #A1, kotlin.collections/List? = ..., com.apollographql.cache.normalized.api/CacheHeaders = ...): kotlin.collections/Set // com.apollographql.cache.normalized/ApolloStore.writeOperation|writeOperation(com.apollographql.apollo.api.Operation<0:0>;0:0;kotlin.collections.List?;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] + final fun <#A1: com.apollographql.apollo.api/Operation.Data> writeOperation(com.apollographql.apollo.api/Operation<#A1>, kotlin.collections/Map, com.apollographql.cache.normalized.api/CacheHeaders = ...): kotlin.collections/Set // com.apollographql.cache.normalized/ApolloStore.writeOperation|writeOperation(com.apollographql.apollo.api.Operation<0:0>;kotlin.collections.Map;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] + final fun <#A1: com.apollographql.apollo.api/Operation.Data> writeOptimisticUpdates(com.apollographql.apollo.api/Operation<#A1>, #A1, com.benasher44.uuid/Uuid): kotlin.collections/Set // com.apollographql.cache.normalized/ApolloStore.writeOptimisticUpdates|writeOptimisticUpdates(com.apollographql.apollo.api.Operation<0:0>;0:0;com.benasher44.uuid.Uuid){0§}[0] + final fun <#A1: kotlin/Any?> accessCache(kotlin/Function1): #A1 // com.apollographql.cache.normalized/ApolloStore.accessCache|accessCache(kotlin.Function1){0§}[0] + final fun clearAll(): kotlin/Boolean // com.apollographql.cache.normalized/ApolloStore.clearAll|clearAll(){}[0] + final fun dispose() // com.apollographql.cache.normalized/ApolloStore.dispose|dispose(){}[0] + final fun dump(): kotlin.collections/Map, kotlin.collections/Map> // com.apollographql.cache.normalized/ApolloStore.dump|dump(){}[0] + final fun remove(com.apollographql.cache.normalized.api/CacheKey, kotlin/Boolean = ...): kotlin/Boolean // com.apollographql.cache.normalized/ApolloStore.remove|remove(com.apollographql.cache.normalized.api.CacheKey;kotlin.Boolean){}[0] + final fun remove(kotlin.collections/List, kotlin/Boolean = ...): kotlin/Int // com.apollographql.cache.normalized/ApolloStore.remove|remove(kotlin.collections.List;kotlin.Boolean){}[0] + final fun rollbackOptimisticUpdates(com.benasher44.uuid/Uuid): kotlin.collections/Set // com.apollographql.cache.normalized/ApolloStore.rollbackOptimisticUpdates|rollbackOptimisticUpdates(com.benasher44.uuid.Uuid){}[0] + final fun trim(kotlin/Long, kotlin/Float = ...): kotlin/Long // com.apollographql.cache.normalized/ApolloStore.trim|trim(kotlin.Long;kotlin.Float){}[0] + final suspend fun publish(kotlin.collections/Set) // com.apollographql.cache.normalized/ApolloStore.publish|publish(kotlin.collections.Set){}[0] +} + final class com.apollographql.cache.normalized/CacheInfo : com.apollographql.apollo.api/ExecutionContext.Element { // com.apollographql.cache.normalized/CacheInfo|null[0] final val cacheEndMillis // com.apollographql.cache.normalized/CacheInfo.cacheEndMillis|{}cacheEndMillis[0] final fun (): kotlin/Long // com.apollographql.cache.normalized/CacheInfo.cacheEndMillis.|(){}[0] @@ -470,31 +499,6 @@ final class com.apollographql.cache.normalized/RemovedFieldsAndRecords { // com. final fun (): kotlin.collections/Set // com.apollographql.cache.normalized/RemovedFieldsAndRecords.removedRecords.|(){}[0] } -final class com.apollographql.cache.normalized/SimpleApolloStore { // com.apollographql.cache.normalized/SimpleApolloStore|null[0] - constructor (com.apollographql.cache.normalized/ApolloStore, com.apollographql.apollo.api/CustomScalarAdapters) // com.apollographql.cache.normalized/SimpleApolloStore.|(com.apollographql.cache.normalized.ApolloStore;com.apollographql.apollo.api.CustomScalarAdapters){}[0] - - final val changedKeys // com.apollographql.cache.normalized/SimpleApolloStore.changedKeys|{}changedKeys[0] - final fun (): kotlinx.coroutines.flow/SharedFlow> // com.apollographql.cache.normalized/SimpleApolloStore.changedKeys.|(){}[0] - - final fun <#A1: com.apollographql.apollo.api/Executable.Data> normalize(com.apollographql.apollo.api/Executable<#A1>, kotlin.collections/Map, com.apollographql.cache.normalized.api/CacheKey = ...): kotlin.collections/Map // com.apollographql.cache.normalized/SimpleApolloStore.normalize|normalize(com.apollographql.apollo.api.Executable<0:0>;kotlin.collections.Map;com.apollographql.cache.normalized.api.CacheKey){0§}[0] - final fun <#A1: com.apollographql.apollo.api/Fragment.Data> readFragment(com.apollographql.apollo.api/Fragment<#A1>, com.apollographql.cache.normalized.api/CacheKey, com.apollographql.cache.normalized.api/CacheHeaders = ...): com.apollographql.cache.normalized/ApolloStore.ReadResult<#A1> // com.apollographql.cache.normalized/SimpleApolloStore.readFragment|readFragment(com.apollographql.apollo.api.Fragment<0:0>;com.apollographql.cache.normalized.api.CacheKey;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] - final fun <#A1: com.apollographql.apollo.api/Fragment.Data> writeFragment(com.apollographql.apollo.api/Fragment<#A1>, com.apollographql.cache.normalized.api/CacheKey, #A1, com.apollographql.cache.normalized.api/CacheHeaders = ...): kotlin.collections/Set // com.apollographql.cache.normalized/SimpleApolloStore.writeFragment|writeFragment(com.apollographql.apollo.api.Fragment<0:0>;com.apollographql.cache.normalized.api.CacheKey;0:0;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] - final fun <#A1: com.apollographql.apollo.api/Fragment.Data> writeOptimisticUpdates(com.apollographql.apollo.api/Fragment<#A1>, com.apollographql.cache.normalized.api/CacheKey, #A1, com.benasher44.uuid/Uuid): kotlin.collections/Set // com.apollographql.cache.normalized/SimpleApolloStore.writeOptimisticUpdates|writeOptimisticUpdates(com.apollographql.apollo.api.Fragment<0:0>;com.apollographql.cache.normalized.api.CacheKey;0:0;com.benasher44.uuid.Uuid){0§}[0] - final fun <#A1: com.apollographql.apollo.api/Operation.Data> readOperation(com.apollographql.apollo.api/Operation<#A1>, com.apollographql.cache.normalized.api/CacheHeaders = ...): com.apollographql.apollo.api/ApolloResponse<#A1> // com.apollographql.cache.normalized/SimpleApolloStore.readOperation|readOperation(com.apollographql.apollo.api.Operation<0:0>;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] - final fun <#A1: com.apollographql.apollo.api/Operation.Data> writeOperation(com.apollographql.apollo.api/Operation<#A1>, #A1, kotlin.collections/List? = ..., com.apollographql.cache.normalized.api/CacheHeaders = ...): kotlin.collections/Set // com.apollographql.cache.normalized/SimpleApolloStore.writeOperation|writeOperation(com.apollographql.apollo.api.Operation<0:0>;0:0;kotlin.collections.List?;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] - final fun <#A1: com.apollographql.apollo.api/Operation.Data> writeOperation(com.apollographql.apollo.api/Operation<#A1>, kotlin.collections/Map, com.apollographql.cache.normalized.api/CacheHeaders = ...): kotlin.collections/Set // com.apollographql.cache.normalized/SimpleApolloStore.writeOperation|writeOperation(com.apollographql.apollo.api.Operation<0:0>;kotlin.collections.Map;com.apollographql.cache.normalized.api.CacheHeaders){0§}[0] - final fun <#A1: com.apollographql.apollo.api/Operation.Data> writeOptimisticUpdates(com.apollographql.apollo.api/Operation<#A1>, #A1, com.benasher44.uuid/Uuid): kotlin.collections/Set // com.apollographql.cache.normalized/SimpleApolloStore.writeOptimisticUpdates|writeOptimisticUpdates(com.apollographql.apollo.api.Operation<0:0>;0:0;com.benasher44.uuid.Uuid){0§}[0] - final fun <#A1: kotlin/Any?> accessCache(kotlin/Function1): #A1 // com.apollographql.cache.normalized/SimpleApolloStore.accessCache|accessCache(kotlin.Function1){0§}[0] - final fun clearAll(): kotlin/Boolean // com.apollographql.cache.normalized/SimpleApolloStore.clearAll|clearAll(){}[0] - final fun dispose() // com.apollographql.cache.normalized/SimpleApolloStore.dispose|dispose(){}[0] - final fun dump(): kotlin.collections/Map, kotlin.collections/Map> // com.apollographql.cache.normalized/SimpleApolloStore.dump|dump(){}[0] - final fun remove(com.apollographql.cache.normalized.api/CacheKey, kotlin/Boolean = ...): kotlin/Boolean // com.apollographql.cache.normalized/SimpleApolloStore.remove|remove(com.apollographql.cache.normalized.api.CacheKey;kotlin.Boolean){}[0] - final fun remove(kotlin.collections/List, kotlin/Boolean = ...): kotlin/Int // com.apollographql.cache.normalized/SimpleApolloStore.remove|remove(kotlin.collections.List;kotlin.Boolean){}[0] - final fun rollbackOptimisticUpdates(com.benasher44.uuid/Uuid): kotlin.collections/Set // com.apollographql.cache.normalized/SimpleApolloStore.rollbackOptimisticUpdates|rollbackOptimisticUpdates(com.benasher44.uuid.Uuid){}[0] - final fun trim(kotlin/Long, kotlin/Float = ...): kotlin/Long // com.apollographql.cache.normalized/SimpleApolloStore.trim|trim(kotlin.Long;kotlin.Float){}[0] - final suspend fun publish(kotlin.collections/Set) // com.apollographql.cache.normalized/SimpleApolloStore.publish|publish(kotlin.collections.Set){}[0] -} - final value class com.apollographql.cache.normalized.api/CacheKey { // com.apollographql.cache.normalized.api/CacheKey|null[0] constructor (kotlin/String) // com.apollographql.cache.normalized.api/CacheKey.|(kotlin.String){}[0] constructor (kotlin/String, kotlin.collections/List) // com.apollographql.cache.normalized.api/CacheKey.|(kotlin.String;kotlin.collections.List){}[0] @@ -582,7 +586,7 @@ final val com.apollographql.cache.normalized/NetworkFirstInterceptor // com.apol final val com.apollographql.cache.normalized/NetworkOnlyInterceptor // com.apollographql.cache.normalized/NetworkOnlyInterceptor|{}NetworkOnlyInterceptor[0] final fun (): com.apollographql.apollo.interceptor/ApolloInterceptor // com.apollographql.cache.normalized/NetworkOnlyInterceptor.|(){}[0] final val com.apollographql.cache.normalized/apolloStore // com.apollographql.cache.normalized/apolloStore|@com.apollographql.apollo.ApolloClient{}apolloStore[0] - final fun (com.apollographql.apollo/ApolloClient).(): com.apollographql.cache.normalized/SimpleApolloStore // com.apollographql.cache.normalized/apolloStore.|@com.apollographql.apollo.ApolloClient(){}[0] + final fun (com.apollographql.apollo/ApolloClient).(): com.apollographql.cache.normalized/ApolloStore // com.apollographql.cache.normalized/apolloStore.|@com.apollographql.apollo.ApolloClient(){}[0] final val com.apollographql.cache.normalized/cacheHeaders // com.apollographql.cache.normalized/cacheHeaders|@com.apollographql.apollo.api.ApolloResponse<0:0>{0§}cacheHeaders[0] final fun <#A1: com.apollographql.apollo.api/Operation.Data> (com.apollographql.apollo.api/ApolloResponse<#A1>).(): com.apollographql.cache.normalized.api/CacheHeaders // com.apollographql.cache.normalized/cacheHeaders.|@com.apollographql.apollo.api.ApolloResponse<0:0>(){0§}[0] final val com.apollographql.cache.normalized/cacheInfo // com.apollographql.cache.normalized/cacheInfo|@com.apollographql.apollo.api.ApolloResponse<0:0>{0§}cacheInfo[0] @@ -593,12 +597,10 @@ final val com.apollographql.cache.normalized/fetchFromCache // com.apollographql final fun <#A1: com.apollographql.apollo.api/Operation.Data> (com.apollographql.apollo.api/ApolloRequest<#A1>).(): kotlin/Boolean // com.apollographql.cache.normalized/fetchFromCache.|@com.apollographql.apollo.api.ApolloRequest<0:0>(){0§}[0] final val com.apollographql.cache.normalized/isFromCache // com.apollographql.cache.normalized/isFromCache|@com.apollographql.apollo.api.ApolloResponse<0:0>{0§}isFromCache[0] final fun <#A1: com.apollographql.apollo.api/Operation.Data> (com.apollographql.apollo.api/ApolloResponse<#A1>).(): kotlin/Boolean // com.apollographql.cache.normalized/isFromCache.|@com.apollographql.apollo.api.ApolloResponse<0:0>(){0§}[0] -final val com.apollographql.cache.normalized/store // com.apollographql.cache.normalized/store|@com.apollographql.apollo.ApolloClient{}store[0] - final fun (com.apollographql.apollo/ApolloClient).(): com.apollographql.cache.normalized/SimpleApolloStore // com.apollographql.cache.normalized/store.|@com.apollographql.apollo.ApolloClient(){}[0] +final fun (com.apollographql.apollo/ApolloClient.Builder).com.apollographql.cache.normalized/cacheManager(com.apollographql.cache.normalized/CacheManager, kotlin/Boolean = ...): com.apollographql.apollo/ApolloClient.Builder // com.apollographql.cache.normalized/cacheManager|cacheManager@com.apollographql.apollo.ApolloClient.Builder(com.apollographql.cache.normalized.CacheManager;kotlin.Boolean){}[0] final fun (com.apollographql.apollo/ApolloClient.Builder).com.apollographql.cache.normalized/logCacheMisses(kotlin/Function1 = ...): com.apollographql.apollo/ApolloClient.Builder // com.apollographql.cache.normalized/logCacheMisses|logCacheMisses@com.apollographql.apollo.ApolloClient.Builder(kotlin.Function1){}[0] final fun (com.apollographql.apollo/ApolloClient.Builder).com.apollographql.cache.normalized/normalizedCache(com.apollographql.cache.normalized.api/NormalizedCacheFactory, com.apollographql.cache.normalized.api/CacheKeyGenerator = ..., com.apollographql.cache.normalized.api/MetadataGenerator = ..., com.apollographql.cache.normalized.api/CacheResolver = ..., com.apollographql.cache.normalized.api/RecordMerger = ..., com.apollographql.cache.normalized.api/FieldKeyGenerator = ..., com.apollographql.cache.normalized.api/EmbeddedFieldsProvider = ..., com.apollographql.cache.normalized.api/MaxAgeProvider = ..., kotlin/Boolean = ...): com.apollographql.apollo/ApolloClient.Builder // com.apollographql.cache.normalized/normalizedCache|normalizedCache@com.apollographql.apollo.ApolloClient.Builder(com.apollographql.cache.normalized.api.NormalizedCacheFactory;com.apollographql.cache.normalized.api.CacheKeyGenerator;com.apollographql.cache.normalized.api.MetadataGenerator;com.apollographql.cache.normalized.api.CacheResolver;com.apollographql.cache.normalized.api.RecordMerger;com.apollographql.cache.normalized.api.FieldKeyGenerator;com.apollographql.cache.normalized.api.EmbeddedFieldsProvider;com.apollographql.cache.normalized.api.MaxAgeProvider;kotlin.Boolean){}[0] -final fun (com.apollographql.apollo/ApolloClient.Builder).com.apollographql.cache.normalized/store(com.apollographql.cache.normalized/ApolloStore, kotlin/Boolean = ...): com.apollographql.apollo/ApolloClient.Builder // com.apollographql.cache.normalized/store|store@com.apollographql.apollo.ApolloClient.Builder(com.apollographql.cache.normalized.ApolloStore;kotlin.Boolean){}[0] final fun (com.apollographql.cache.normalized.api/NormalizedCache).com.apollographql.cache.normalized/allRecords(): kotlin.collections/Map // com.apollographql.cache.normalized/allRecords|allRecords@com.apollographql.cache.normalized.api.NormalizedCache(){}[0] final fun (com.apollographql.cache.normalized.api/NormalizedCache).com.apollographql.cache.normalized/garbageCollect(com.apollographql.cache.normalized.api/MaxAgeProvider, kotlin.time/Duration = ...): com.apollographql.cache.normalized/GarbageCollectResult // com.apollographql.cache.normalized/garbageCollect|garbageCollect@com.apollographql.cache.normalized.api.NormalizedCache(com.apollographql.cache.normalized.api.MaxAgeProvider;kotlin.time.Duration){}[0] final fun (com.apollographql.cache.normalized.api/NormalizedCache).com.apollographql.cache.normalized/removeDanglingReferences(): com.apollographql.cache.normalized/RemovedFieldsAndRecords // com.apollographql.cache.normalized/removeDanglingReferences|removeDanglingReferences@com.apollographql.cache.normalized.api.NormalizedCache(){}[0] @@ -638,4 +640,4 @@ final fun <#A: kotlin/Any?> (com.apollographql.apollo.api/MutableExecutionOption final fun <#A: kotlin/Any?> (com.apollographql.apollo.api/MutableExecutionOptions<#A>).com.apollographql.cache.normalized/storePartialResponses(kotlin/Boolean): kotlin/Nothing // com.apollographql.cache.normalized/storePartialResponses|storePartialResponses@com.apollographql.apollo.api.MutableExecutionOptions<0:0>(kotlin.Boolean){0§}[0] final fun <#A: kotlin/Any?> (com.apollographql.apollo.api/MutableExecutionOptions<#A>).com.apollographql.cache.normalized/storeReceivedDate(kotlin/Boolean): #A // com.apollographql.cache.normalized/storeReceivedDate|storeReceivedDate@com.apollographql.apollo.api.MutableExecutionOptions<0:0>(kotlin.Boolean){0§}[0] final fun <#A: kotlin/Any?> (com.apollographql.apollo.api/MutableExecutionOptions<#A>).com.apollographql.cache.normalized/writeToCacheAsynchronously(kotlin/Boolean): #A // com.apollographql.cache.normalized/writeToCacheAsynchronously|writeToCacheAsynchronously@com.apollographql.apollo.api.MutableExecutionOptions<0:0>(kotlin.Boolean){0§}[0] -final fun com.apollographql.cache.normalized/ApolloStore(com.apollographql.cache.normalized.api/NormalizedCacheFactory, com.apollographql.cache.normalized.api/CacheKeyGenerator = ..., com.apollographql.cache.normalized.api/MetadataGenerator = ..., com.apollographql.cache.normalized.api/CacheResolver = ..., com.apollographql.cache.normalized.api/RecordMerger = ..., com.apollographql.cache.normalized.api/FieldKeyGenerator = ..., com.apollographql.cache.normalized.api/EmbeddedFieldsProvider = ..., com.apollographql.cache.normalized.api/MaxAgeProvider = ...): com.apollographql.cache.normalized/ApolloStore // com.apollographql.cache.normalized/ApolloStore|ApolloStore(com.apollographql.cache.normalized.api.NormalizedCacheFactory;com.apollographql.cache.normalized.api.CacheKeyGenerator;com.apollographql.cache.normalized.api.MetadataGenerator;com.apollographql.cache.normalized.api.CacheResolver;com.apollographql.cache.normalized.api.RecordMerger;com.apollographql.cache.normalized.api.FieldKeyGenerator;com.apollographql.cache.normalized.api.EmbeddedFieldsProvider;com.apollographql.cache.normalized.api.MaxAgeProvider){}[0] +final fun com.apollographql.cache.normalized/CacheManager(com.apollographql.cache.normalized.api/NormalizedCacheFactory, com.apollographql.cache.normalized.api/CacheKeyGenerator = ..., com.apollographql.cache.normalized.api/MetadataGenerator = ..., com.apollographql.cache.normalized.api/CacheResolver = ..., com.apollographql.cache.normalized.api/RecordMerger = ..., com.apollographql.cache.normalized.api/FieldKeyGenerator = ..., com.apollographql.cache.normalized.api/EmbeddedFieldsProvider = ..., com.apollographql.cache.normalized.api/MaxAgeProvider = ...): com.apollographql.cache.normalized/CacheManager // com.apollographql.cache.normalized/CacheManager|CacheManager(com.apollographql.cache.normalized.api.NormalizedCacheFactory;com.apollographql.cache.normalized.api.CacheKeyGenerator;com.apollographql.cache.normalized.api.MetadataGenerator;com.apollographql.cache.normalized.api.CacheResolver;com.apollographql.cache.normalized.api.RecordMerger;com.apollographql.cache.normalized.api.FieldKeyGenerator;com.apollographql.cache.normalized.api.EmbeddedFieldsProvider;com.apollographql.cache.normalized.api.MaxAgeProvider){}[0] diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ApolloStore.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ApolloStore.kt index 069d20ee..540f0264 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ApolloStore.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ApolloStore.kt @@ -6,386 +6,187 @@ import com.apollographql.apollo.api.Error import com.apollographql.apollo.api.Executable import com.apollographql.apollo.api.Fragment import com.apollographql.apollo.api.Operation -import com.apollographql.apollo.api.json.JsonNumber -import com.apollographql.apollo.interceptor.ApolloInterceptor -import com.apollographql.cache.normalized.ApolloStore.Companion.ALL_KEYS +import com.apollographql.cache.normalized.CacheManager.ReadResult import com.apollographql.cache.normalized.api.CacheHeaders import com.apollographql.cache.normalized.api.CacheKey -import com.apollographql.cache.normalized.api.CacheKeyGenerator -import com.apollographql.cache.normalized.api.CacheResolver import com.apollographql.cache.normalized.api.DataWithErrors -import com.apollographql.cache.normalized.api.DefaultEmbeddedFieldsProvider -import com.apollographql.cache.normalized.api.DefaultFieldKeyGenerator -import com.apollographql.cache.normalized.api.DefaultMaxAgeProvider -import com.apollographql.cache.normalized.api.DefaultRecordMerger -import com.apollographql.cache.normalized.api.EmbeddedFieldsProvider -import com.apollographql.cache.normalized.api.EmptyMetadataGenerator -import com.apollographql.cache.normalized.api.FieldKeyGenerator -import com.apollographql.cache.normalized.api.FieldPolicyCacheResolver -import com.apollographql.cache.normalized.api.MaxAgeProvider -import com.apollographql.cache.normalized.api.MetadataGenerator import com.apollographql.cache.normalized.api.NormalizedCache -import com.apollographql.cache.normalized.api.NormalizedCacheFactory import com.apollographql.cache.normalized.api.Record -import com.apollographql.cache.normalized.api.RecordMerger -import com.apollographql.cache.normalized.api.RecordValue -import com.apollographql.cache.normalized.api.TypePolicyCacheKeyGenerator -import com.apollographql.cache.normalized.internal.DefaultApolloStore import com.benasher44.uuid.Uuid import kotlinx.coroutines.flow.SharedFlow import kotlin.reflect.KClass /** - * ApolloStore exposes a high-level API to access a [com.apollographql.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. - * - * Note that changes are not automatically published - call [publish] to notify any watchers. + * A wrapper around [CacheManager] that provides a simplified API for reading and writing data. */ -interface ApolloStore { +class ApolloStore( + val cacheManager: CacheManager, + val customScalarAdapters: CustomScalarAdapters, +) { /** - * Exposes the record field keys that have changed. This is collected internally to notify watchers. - * - * A special value [ALL_KEYS] indicates that all records have changed. - * - * @see publish - * @see watch + * @see CacheManager.changedKeys */ val changedKeys: SharedFlow> - - companion object { - val ALL_KEYS = object : AbstractSet() { - override val size = 0 - - override fun iterator() = emptySet().iterator() - - override fun equals(other: Any?) = other === this - - override fun hashCode() = 0 - } - } + get() = cacheManager.changedKeys /** - * Reads an operation from the store. - * - * The returned [ApolloResponse.data] has `null` values for any missing fields if their type is nullable, propagating up to their parent - * otherwise. Missing fields have a corresponding [Error] - * in [ApolloResponse.errors]. - * - * This is a synchronous operation that might block if the underlying cache is doing IO. - * - * @param operation the operation to read + * @see CacheManager.readOperation */ fun readOperation( operation: Operation, - customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, cacheHeaders: CacheHeaders = CacheHeaders.NONE, - ): ApolloResponse + ): ApolloResponse = cacheManager.readOperation( + operation = operation, + cacheHeaders = cacheHeaders, + customScalarAdapters = customScalarAdapters, + ) /** - * Reads a fragment from the store. - * - * This is a synchronous operation that might block if the underlying cache is doing IO. - * - * @param fragment the fragment to read - * @param cacheKey the root where to read the fragment data from - * - * @throws [com.apollographql.apollo.exception.CacheMissException] on cache miss - * @throws [com.apollographql.apollo.exception.ApolloException] on other cache read errors - * - * @return the fragment data with optional headers from the [NormalizedCache] + * @see CacheManager.readFragment */ fun readFragment( fragment: Fragment, cacheKey: CacheKey, - customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, cacheHeaders: CacheHeaders = CacheHeaders.NONE, - ): ReadResult + ): ReadResult = cacheManager.readFragment( + fragment = fragment, + cacheKey = cacheKey, + customScalarAdapters = customScalarAdapters, + cacheHeaders = cacheHeaders, + ) /** - * Writes an operation to the store. - * - * This is a synchronous operation that might block if the underlying cache is doing IO. - * - * Call [publish] with the returned keys to notify any watchers. - * - * @param operation the operation to write - * @param data the operation data to write - * @param errors the operation errors to write - * @return the changed field keys - * - * @see publish + * @see CacheManager.writeOperation */ fun writeOperation( operation: Operation, data: D, errors: List? = null, - customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, cacheHeaders: CacheHeaders = CacheHeaders.NONE, - ): Set + ): Set = cacheManager.writeOperation( + operation = operation, + data = data, + errors = errors, + cacheHeaders = cacheHeaders, + customScalarAdapters = customScalarAdapters, + ) /** - * Writes an operation to the store. - * - * This is a synchronous operation that might block if the underlying cache is doing IO. - * - * Call [publish] with the returned keys to notify any watchers. - * - * @param operation the operation to write - * @param dataWithErrors the operation data to write as a [DataWithErrors] object - * @return the changed field keys - * - * @see publish + * @see CacheManager.writeFragment */ fun writeOperation( operation: Operation, dataWithErrors: DataWithErrors, - customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, cacheHeaders: CacheHeaders = CacheHeaders.NONE, - ): Set + ): Set = cacheManager.writeOperation( + operation = operation, + dataWithErrors = dataWithErrors, + cacheHeaders = cacheHeaders, + customScalarAdapters = customScalarAdapters, + ) /** - * Writes a fragment to the store. - * - * This is a synchronous operation that might block if the underlying cache is doing IO. - * - * Call [publish] with the returned keys to notify any watchers. - * - * @param fragment the fragment to write - * @param cacheKey the root where to write the fragment data to - * @param data the fragment data to write - * @return the changed field keys - * - * @see publish + * @see CacheManager.writeFragment */ fun writeFragment( fragment: Fragment, cacheKey: CacheKey, data: D, - customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, cacheHeaders: CacheHeaders = CacheHeaders.NONE, - ): Set + ): Set = cacheManager.writeFragment( + fragment = fragment, + cacheKey = cacheKey, + data = data, + cacheHeaders = cacheHeaders, + customScalarAdapters = customScalarAdapters, + ) /** - * Writes an operation to the optimistic store. - * - * This is a synchronous operation that might block if the underlying cache is doing IO. - * - * Call [publish] with the returned keys to notify any watchers. - * - * @param operation the operation to write - * @param data the operation data to write - * @param mutationId a unique identifier for this optimistic update - * @return the changed field keys - * - * @see publish + * @see CacheManager.writeOptimisticUpdates */ fun writeOptimisticUpdates( operation: Operation, data: D, mutationId: Uuid, - customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, - ): Set + ): Set = cacheManager.writeOptimisticUpdates( + operation = operation, + data = data, + mutationId = mutationId, + customScalarAdapters = customScalarAdapters, + ) /** - * Writes a fragment to the optimistic store. - * - * This is a synchronous operation that might block if the underlying cache is doing IO. - * - * Call [publish] with the returned keys to notify any watchers. - * - * @param fragment the fragment to write - * @param cacheKey the root where to write the fragment data to - * @param data the fragment data to write - * @param mutationId a unique identifier for this optimistic update - * @return the changed field keys - * - * @see publish + * @see CacheManager.writeOptimisticUpdates */ fun writeOptimisticUpdates( fragment: Fragment, cacheKey: CacheKey, data: D, mutationId: Uuid, - customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, - ): Set + ): Set = cacheManager.writeOptimisticUpdates( + fragment = fragment, + cacheKey = cacheKey, + data = data, + mutationId = mutationId, + customScalarAdapters = customScalarAdapters, + ) /** - * Rollbacks optimistic updates. - * - * This is a synchronous operation that might block if the underlying cache is doing IO. - * - * Call [publish] with the returned keys to notify any watchers. - * - * @param mutationId the unique identifier of the optimistic update to rollback - * @return the changed field keys - * - * @see publish + * @see CacheManager.rollbackOptimisticUpdates */ - fun rollbackOptimisticUpdates( - mutationId: Uuid, - ): Set + fun rollbackOptimisticUpdates(mutationId: Uuid): Set = cacheManager.rollbackOptimisticUpdates(mutationId) /** - * Clears all records. - * - * This is a synchronous operation that might block if the underlying cache is doing IO. - * - * Call [publish] with [ALL_KEYS] to notify any watchers. - * - * @return `true` if all records were successfully removed, `false` otherwise + * @see CacheManager.clearAll */ - fun clearAll(): Boolean + fun clearAll(): Boolean = cacheManager.clearAll() /** - * Removes a record by its key. - * - * This is a synchronous operation that might block if the underlying cache is doing IO. - * - * Call [publish] with [ALL_KEYS] to notify any watchers. - * - * @param cacheKey the key of the record to remove - * @param cascade whether referenced records should also be removed - * @return `true` if the record was successfully removed, `false` otherwise + * @see CacheManager.remove */ - fun remove(cacheKey: CacheKey, cascade: Boolean = true): Boolean + fun remove(cacheKey: CacheKey, cascade: Boolean = true): Boolean = cacheManager.remove(cacheKey, cascade) /** - * Removes a list of records by their keys. - * 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. - * - * Call [publish] with [ALL_KEYS] to notify any watchers. - * - * @param cacheKeys the keys of the records to remove - * @param cascade whether referenced records should also be removed - * @return the number of records that have been removed + * @see CacheManager.remove */ - fun remove(cacheKeys: List, cascade: Boolean = true): Int + fun remove(cacheKeys: List, cascade: Boolean = true): Int = cacheManager.remove(cacheKeys, cascade) /** - * Trims the store if its size exceeds [maxSizeBytes]. The amount of data to remove is determined by [trimFactor]. - * The oldest records are removed according to their updated date. - * - * This may not be supported by all cache implementations (currently this is implemented by the SQL cache). - * - * @param maxSizeBytes the size of the cache in bytes above which the cache should be trimmed. - * @param trimFactor the factor of the cache size to trim. - * @return the cache size in bytes after trimming or -1 if the operation is not supported. + * @see CacheManager.trim */ - fun trim(maxSizeBytes: Long, trimFactor: Float = 0.1f): Long + fun trim(maxSizeBytes: Long, trimFactor: Float = 0.1f): Long = cacheManager.trim(maxSizeBytes, trimFactor) /** - * Normalizes executable data to a map of [Record] keyed by [Record.key]. + * @see CacheManager.normalize */ fun normalize( executable: Executable, dataWithErrors: DataWithErrors, rootKey: CacheKey = CacheKey.QUERY_ROOT, - customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, - ): Map + ): Map = cacheManager.normalize( + executable = executable, + dataWithErrors = dataWithErrors, + rootKey = rootKey, + customScalarAdapters = customScalarAdapters, + ) /** - * Publishes a set of keys of record fields that have changed. This will notify watchers and any subscribers of [changedKeys]. - * - * Pass [ALL_KEYS] to indicate that all records have changed, for instance after a [clearAll] operation. - * - * @see changedKeys - * @see watch - * - * @param keys A set of keys of [Record] fields which have changed. + * @see CacheManager.publish */ - suspend fun publish(keys: Set) + suspend fun publish(keys: Set) = cacheManager.publish(keys) /** - * Direct access to the cache. - * - * This is a synchronous operation that might block if the underlying cache is doing IO. - * - * @param block a function that can access the cache. + * @see CacheManager.publish */ - fun accessCache(block: (NormalizedCache) -> R): R + fun accessCache(block: (NormalizedCache) -> R): R = cacheManager.accessCache(block) /** - * Dumps the content of the store for debugging purposes. - * - * This is a synchronous operation that might block if the underlying cache is doing IO. + * @see CacheManager.dump */ - fun dump(): Map, Map> + fun dump(): Map, Map> = cacheManager.dump() /** - * Releases resources associated with this store. + * @see CacheManager.dispose */ - fun dispose() - - class ReadResult( - val data: D, - val cacheHeaders: CacheHeaders, - ) + fun dispose() = cacheManager.dispose() } - -fun ApolloStore( - normalizedCacheFactory: NormalizedCacheFactory, - cacheKeyGenerator: CacheKeyGenerator = TypePolicyCacheKeyGenerator, - metadataGenerator: MetadataGenerator = EmptyMetadataGenerator, - cacheResolver: CacheResolver = FieldPolicyCacheResolver, - recordMerger: RecordMerger = DefaultRecordMerger, - fieldKeyGenerator: FieldKeyGenerator = DefaultFieldKeyGenerator, - embeddedFieldsProvider: EmbeddedFieldsProvider = DefaultEmbeddedFieldsProvider, - maxAgeProvider: MaxAgeProvider = DefaultMaxAgeProvider, -): ApolloStore = DefaultApolloStore( - normalizedCacheFactory = normalizedCacheFactory, - cacheKeyGenerator = cacheKeyGenerator, - metadataGenerator = metadataGenerator, - cacheResolver = cacheResolver, - recordMerger = recordMerger, - fieldKeyGenerator = fieldKeyGenerator, - embeddedFieldsProvider = embeddedFieldsProvider, - maxAgeProvider = maxAgeProvider, -) - -/** - * Interface that marks all interceptors added when configuring a `store()` on ApolloClient.Builder. - */ -internal interface ApolloStoreInterceptor : ApolloInterceptor - -internal fun ApolloStore.cacheDumpProvider(): () -> Map>>> { - return { - dump().map { (cacheClass, cacheRecords) -> - cacheClass.normalizedCacheName() to cacheRecords - .mapKeys { (key, _) -> key.keyToString() } - .mapValues { (_, record) -> - record.size to record.fields.mapValues { (_, value) -> - value.toExternal() - } - } - }.toMap() - } -} - -private fun RecordValue.toExternal(): Any? { - return when (this) { - null -> null - is String -> this - is Boolean -> this - is Int -> this - is Long -> this - is Double -> this - is JsonNumber -> this - is CacheKey -> "ApolloCacheReference{${this.keyToString()}}" - is Error -> "ApolloCacheError{${this.message}}" - is List<*> -> { - map { it.toExternal() } - } - - is Map<*, *> -> { - mapValues { it.value.toExternal() } - } - - else -> error("Unsupported record value type: '$this'") - } -} - -internal expect fun KClass<*>.normalizedCacheName(): String diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/CacheManager.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/CacheManager.kt new file mode 100644 index 00000000..2464616c --- /dev/null +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/CacheManager.kt @@ -0,0 +1,385 @@ +package com.apollographql.cache.normalized + +import com.apollographql.apollo.api.ApolloResponse +import com.apollographql.apollo.api.CustomScalarAdapters +import com.apollographql.apollo.api.Error +import com.apollographql.apollo.api.Executable +import com.apollographql.apollo.api.Fragment +import com.apollographql.apollo.api.Operation +import com.apollographql.apollo.api.json.JsonNumber +import com.apollographql.cache.normalized.CacheManager.Companion.ALL_KEYS +import com.apollographql.cache.normalized.api.CacheHeaders +import com.apollographql.cache.normalized.api.CacheKey +import com.apollographql.cache.normalized.api.CacheKeyGenerator +import com.apollographql.cache.normalized.api.CacheResolver +import com.apollographql.cache.normalized.api.DataWithErrors +import com.apollographql.cache.normalized.api.DefaultEmbeddedFieldsProvider +import com.apollographql.cache.normalized.api.DefaultFieldKeyGenerator +import com.apollographql.cache.normalized.api.DefaultMaxAgeProvider +import com.apollographql.cache.normalized.api.DefaultRecordMerger +import com.apollographql.cache.normalized.api.EmbeddedFieldsProvider +import com.apollographql.cache.normalized.api.EmptyMetadataGenerator +import com.apollographql.cache.normalized.api.FieldKeyGenerator +import com.apollographql.cache.normalized.api.FieldPolicyCacheResolver +import com.apollographql.cache.normalized.api.MaxAgeProvider +import com.apollographql.cache.normalized.api.MetadataGenerator +import com.apollographql.cache.normalized.api.NormalizedCache +import com.apollographql.cache.normalized.api.NormalizedCacheFactory +import com.apollographql.cache.normalized.api.Record +import com.apollographql.cache.normalized.api.RecordMerger +import com.apollographql.cache.normalized.api.RecordValue +import com.apollographql.cache.normalized.api.TypePolicyCacheKeyGenerator +import com.apollographql.cache.normalized.internal.DefaultCacheManager +import com.benasher44.uuid.Uuid +import kotlinx.coroutines.flow.SharedFlow +import kotlin.reflect.KClass + +/** + * CacheManager exposes a high-level API to access a [com.apollographql.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. + * + * Note that changes are not automatically published - call [publish] to notify any watchers. + */ +interface CacheManager { + /** + * Exposes the record field keys that have changed. This is collected internally to notify watchers. + * + * A special value [ALL_KEYS] indicates that all records have changed. + * + * @see publish + * @see watch + */ + val changedKeys: SharedFlow> + + companion object { + val ALL_KEYS = object : AbstractSet() { + override val size = 0 + + override fun iterator() = emptySet().iterator() + + override fun equals(other: Any?) = other === this + + override fun hashCode() = 0 + } + } + + /** + * Reads an operation from the store. + * + * The returned [ApolloResponse.data] has `null` values for any missing fields if their type is nullable, propagating up to their parent + * otherwise. Missing fields have a corresponding [Error] + * in [ApolloResponse.errors]. + * + * This is a synchronous operation that might block if the underlying cache is doing IO. + * + * @param operation the operation to read + */ + fun readOperation( + operation: Operation, + customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, + cacheHeaders: CacheHeaders = CacheHeaders.NONE, + ): ApolloResponse + + /** + * Reads a fragment from the store. + * + * This is a synchronous operation that might block if the underlying cache is doing IO. + * + * @param fragment the fragment to read + * @param cacheKey the root where to read the fragment data from + * + * @throws [com.apollographql.apollo.exception.CacheMissException] on cache miss + * @throws [com.apollographql.apollo.exception.ApolloException] on other cache read errors + * + * @return the fragment data with optional headers from the [NormalizedCache] + */ + fun readFragment( + fragment: Fragment, + cacheKey: CacheKey, + customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, + cacheHeaders: CacheHeaders = CacheHeaders.NONE, + ): ReadResult + + /** + * Writes an operation to the store. + * + * This is a synchronous operation that might block if the underlying cache is doing IO. + * + * Call [publish] with the returned keys to notify any watchers. + * + * @param operation the operation to write + * @param data the operation data to write + * @param errors the operation errors to write + * @return the changed field keys + * + * @see publish + */ + fun writeOperation( + operation: Operation, + data: D, + errors: List? = null, + customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, + cacheHeaders: CacheHeaders = CacheHeaders.NONE, + ): Set + + /** + * Writes an operation to the store. + * + * This is a synchronous operation that might block if the underlying cache is doing IO. + * + * Call [publish] with the returned keys to notify any watchers. + * + * @param operation the operation to write + * @param dataWithErrors the operation data to write as a [DataWithErrors] object + * @return the changed field keys + * + * @see publish + */ + fun writeOperation( + operation: Operation, + dataWithErrors: DataWithErrors, + customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, + cacheHeaders: CacheHeaders = CacheHeaders.NONE, + ): Set + + /** + * Writes a fragment to the store. + * + * This is a synchronous operation that might block if the underlying cache is doing IO. + * + * Call [publish] with the returned keys to notify any watchers. + * + * @param fragment the fragment to write + * @param cacheKey the root where to write the fragment data to + * @param data the fragment data to write + * @return the changed field keys + * + * @see publish + */ + fun writeFragment( + fragment: Fragment, + cacheKey: CacheKey, + data: D, + customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, + cacheHeaders: CacheHeaders = CacheHeaders.NONE, + ): Set + + /** + * Writes an operation to the optimistic store. + * + * This is a synchronous operation that might block if the underlying cache is doing IO. + * + * Call [publish] with the returned keys to notify any watchers. + * + * @param operation the operation to write + * @param data the operation data to write + * @param mutationId a unique identifier for this optimistic update + * @return the changed field keys + * + * @see publish + */ + fun writeOptimisticUpdates( + operation: Operation, + data: D, + mutationId: Uuid, + customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, + ): Set + + /** + * Writes a fragment to the optimistic store. + * + * This is a synchronous operation that might block if the underlying cache is doing IO. + * + * Call [publish] with the returned keys to notify any watchers. + * + * @param fragment the fragment to write + * @param cacheKey the root where to write the fragment data to + * @param data the fragment data to write + * @param mutationId a unique identifier for this optimistic update + * @return the changed field keys + * + * @see publish + */ + fun writeOptimisticUpdates( + fragment: Fragment, + cacheKey: CacheKey, + data: D, + mutationId: Uuid, + customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, + ): Set + + /** + * Rollbacks optimistic updates. + * + * This is a synchronous operation that might block if the underlying cache is doing IO. + * + * Call [publish] with the returned keys to notify any watchers. + * + * @param mutationId the unique identifier of the optimistic update to rollback + * @return the changed field keys + * + * @see publish + */ + fun rollbackOptimisticUpdates( + mutationId: Uuid, + ): Set + + /** + * Clears all records. + * + * This is a synchronous operation that might block if the underlying cache is doing IO. + * + * Call [publish] with [ALL_KEYS] to notify any watchers. + * + * @return `true` if all records were successfully removed, `false` otherwise + */ + fun clearAll(): Boolean + + /** + * Removes a record by its key. + * + * This is a synchronous operation that might block if the underlying cache is doing IO. + * + * Call [publish] with [ALL_KEYS] to notify any watchers. + * + * @param cacheKey the key of the record to remove + * @param cascade whether referenced records should also be removed + * @return `true` if the record was successfully removed, `false` otherwise + */ + fun remove(cacheKey: CacheKey, cascade: Boolean = true): Boolean + + /** + * Removes a list of records by their keys. + * 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. + * + * Call [publish] with [ALL_KEYS] to notify any watchers. + * + * @param cacheKeys the keys of the records to remove + * @param cascade whether referenced records should also be removed + * @return the number of records that have been removed + */ + fun remove(cacheKeys: List, cascade: Boolean = true): Int + + /** + * Trims the store if its size exceeds [maxSizeBytes]. The amount of data to remove is determined by [trimFactor]. + * The oldest records are removed according to their updated date. + * + * This may not be supported by all cache implementations (currently this is implemented by the SQL cache). + * + * @param maxSizeBytes the size of the cache in bytes above which the cache should be trimmed. + * @param trimFactor the factor of the cache size to trim. + * @return the cache size in bytes after trimming or -1 if the operation is not supported. + */ + fun trim(maxSizeBytes: Long, trimFactor: Float = 0.1f): Long + + /** + * Normalizes executable data to a map of [Record] keyed by [Record.key]. + */ + fun normalize( + executable: Executable, + dataWithErrors: DataWithErrors, + rootKey: CacheKey = CacheKey.QUERY_ROOT, + customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, + ): Map + + /** + * Publishes a set of keys of record fields that have changed. This will notify watchers and any subscribers of [changedKeys]. + * + * Pass [ALL_KEYS] to indicate that all records have changed, for instance after a [clearAll] operation. + * + * @see changedKeys + * @see watch + * + * @param keys A set of keys of [Record] fields which have changed. + */ + suspend fun publish(keys: Set) + + /** + * Direct access to the cache. + * + * This is a synchronous operation that might block if the underlying cache is doing IO. + * + * @param block a function that can access the cache. + */ + fun accessCache(block: (NormalizedCache) -> R): R + + /** + * Dumps the content of the store for debugging purposes. + * + * This is a synchronous operation that might block if the underlying cache is doing IO. + */ + fun dump(): Map, Map> + + /** + * Releases resources associated with this store. + */ + fun dispose() + + class ReadResult( + val data: D, + val cacheHeaders: CacheHeaders, + ) +} + +fun CacheManager( + normalizedCacheFactory: NormalizedCacheFactory, + cacheKeyGenerator: CacheKeyGenerator = TypePolicyCacheKeyGenerator, + metadataGenerator: MetadataGenerator = EmptyMetadataGenerator, + cacheResolver: CacheResolver = FieldPolicyCacheResolver, + recordMerger: RecordMerger = DefaultRecordMerger, + fieldKeyGenerator: FieldKeyGenerator = DefaultFieldKeyGenerator, + embeddedFieldsProvider: EmbeddedFieldsProvider = DefaultEmbeddedFieldsProvider, + maxAgeProvider: MaxAgeProvider = DefaultMaxAgeProvider, +): CacheManager = DefaultCacheManager( + normalizedCacheFactory = normalizedCacheFactory, + cacheKeyGenerator = cacheKeyGenerator, + metadataGenerator = metadataGenerator, + cacheResolver = cacheResolver, + recordMerger = recordMerger, + fieldKeyGenerator = fieldKeyGenerator, + embeddedFieldsProvider = embeddedFieldsProvider, + maxAgeProvider = maxAgeProvider, +) + +internal fun CacheManager.cacheDumpProvider(): () -> Map>>> { + return { + dump().map { (cacheClass, cacheRecords) -> + cacheClass.normalizedCacheName() to cacheRecords + .mapKeys { (key, _) -> key.keyToString() } + .mapValues { (_, record) -> + record.size to record.fields.mapValues { (_, value) -> + value.toExternal() + } + } + }.toMap() + } +} + +private fun RecordValue.toExternal(): Any? { + return when (this) { + null -> null + is String -> this + is Boolean -> this + is Int -> this + is Long -> this + is Double -> this + is JsonNumber -> this + is CacheKey -> "ApolloCacheReference{${this.keyToString()}}" + is Error -> "ApolloCacheError{${this.message}}" + is List<*> -> { + map { it.toExternal() } + } + + is Map<*, *> -> { + mapValues { it.value.toExternal() } + } + + else -> error("Unsupported record value type: '$this'") + } +} + +internal expect fun KClass<*>.normalizedCacheName(): String diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ClientCacheExtensions.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ClientCacheExtensions.kt index ff9063bf..ac7a5884 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ClientCacheExtensions.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ClientCacheExtensions.kt @@ -74,8 +74,8 @@ fun ApolloClient.Builder.normalizedCache( maxAgeProvider: MaxAgeProvider = DefaultMaxAgeProvider, writeToCacheAsynchronously: Boolean = false, ): ApolloClient.Builder { - return store( - ApolloStore( + return cacheManager( + CacheManager( normalizedCacheFactory = normalizedCacheFactory, cacheKeyGenerator = cacheKeyGenerator, metadataGenerator = metadataGenerator, @@ -123,11 +123,11 @@ private fun ApolloInterceptorChain.asInterceptor(): ApolloInterceptor { } } -internal class CacheInterceptor(val store: ApolloStore) : ApolloInterceptor { +internal class CacheInterceptor(val cacheManager: CacheManager) : ApolloInterceptor { private val delegates = listOf( - WatcherInterceptor(store), + WatcherInterceptor(cacheManager), FetchPolicyRouterInterceptor, - ApolloCacheInterceptor(store), + ApolloCacheInterceptor(cacheManager), StoreExpirationDateInterceptor, ) @@ -139,10 +139,10 @@ internal class CacheInterceptor(val store: ApolloStore) : ApolloInterceptor { } } -fun ApolloClient.Builder.store(store: ApolloStore, writeToCacheAsynchronously: Boolean = false): ApolloClient.Builder { - return cacheInterceptor(CacheInterceptor(store)) +fun ApolloClient.Builder.cacheManager(cacheManager: CacheManager, writeToCacheAsynchronously: Boolean = false): ApolloClient.Builder { + return cacheInterceptor(CacheInterceptor(cacheManager)) .writeToCacheAsynchronously(writeToCacheAsynchronously) - .addExecutionContext(CacheDumpProviderContext(store.cacheDumpProvider())) + .addExecutionContext(CacheDumpProviderContext(cacheManager.cacheDumpProvider())) } /** @@ -222,14 +222,10 @@ internal fun ApolloCall.watchInternal(data: D?): Flow ApolloResponse.errorsAsException(): ApolloResponse intercept(request: ApolloRequest, chain: ApolloInterceptorChain): Flow> { if (request.operation !is Query) { // Subscriptions and Mutations do not support fetchPolicies diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/SimpleApolloStore.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/SimpleApolloStore.kt deleted file mode 100644 index 5721dd6f..00000000 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/SimpleApolloStore.kt +++ /dev/null @@ -1,192 +0,0 @@ -package com.apollographql.cache.normalized - -import com.apollographql.apollo.api.ApolloResponse -import com.apollographql.apollo.api.CustomScalarAdapters -import com.apollographql.apollo.api.Error -import com.apollographql.apollo.api.Executable -import com.apollographql.apollo.api.Fragment -import com.apollographql.apollo.api.Operation -import com.apollographql.cache.normalized.ApolloStore.ReadResult -import com.apollographql.cache.normalized.api.CacheHeaders -import com.apollographql.cache.normalized.api.CacheKey -import com.apollographql.cache.normalized.api.DataWithErrors -import com.apollographql.cache.normalized.api.NormalizedCache -import com.apollographql.cache.normalized.api.Record -import com.benasher44.uuid.Uuid -import kotlinx.coroutines.flow.SharedFlow -import kotlin.reflect.KClass - -/** - * A wrapper around [ApolloStore] that provides a simplified API for reading and writing data. - */ -class SimpleApolloStore( - private val apolloStore: ApolloStore, - private val customScalarAdapters: CustomScalarAdapters, -) { - /** - * @see ApolloStore.changedKeys - */ - val changedKeys: SharedFlow> - get() = apolloStore.changedKeys - - /** - * @see ApolloStore.readOperation - */ - fun readOperation( - operation: Operation, - cacheHeaders: CacheHeaders = CacheHeaders.NONE, - ): ApolloResponse = apolloStore.readOperation( - operation = operation, - cacheHeaders = cacheHeaders, - customScalarAdapters = customScalarAdapters, - ) - - /** - * @see ApolloStore.readFragment - */ - fun readFragment( - fragment: Fragment, - cacheKey: CacheKey, - cacheHeaders: CacheHeaders = CacheHeaders.NONE, - ): ReadResult = apolloStore.readFragment( - fragment = fragment, - cacheKey = cacheKey, - customScalarAdapters = customScalarAdapters, - cacheHeaders = cacheHeaders, - ) - - /** - * @see ApolloStore.writeOperation - */ - fun writeOperation( - operation: Operation, - data: D, - errors: List? = null, - cacheHeaders: CacheHeaders = CacheHeaders.NONE, - ): Set = apolloStore.writeOperation( - operation = operation, - data = data, - errors = errors, - cacheHeaders = cacheHeaders, - customScalarAdapters = customScalarAdapters, - ) - - /** - * @see ApolloStore.writeFragment - */ - fun writeOperation( - operation: Operation, - dataWithErrors: DataWithErrors, - cacheHeaders: CacheHeaders = CacheHeaders.NONE, - ): Set = apolloStore.writeOperation( - operation = operation, - dataWithErrors = dataWithErrors, - cacheHeaders = cacheHeaders, - customScalarAdapters = customScalarAdapters, - ) - - /** - * @see ApolloStore.writeFragment - */ - fun writeFragment( - fragment: Fragment, - cacheKey: CacheKey, - data: D, - cacheHeaders: CacheHeaders = CacheHeaders.NONE, - ): Set = apolloStore.writeFragment( - fragment = fragment, - cacheKey = cacheKey, - data = data, - cacheHeaders = cacheHeaders, - customScalarAdapters = customScalarAdapters, - ) - - /** - * @see ApolloStore.writeOptimisticUpdates - */ - fun writeOptimisticUpdates( - operation: Operation, - data: D, - mutationId: Uuid, - ): Set = apolloStore.writeOptimisticUpdates( - operation = operation, - data = data, - mutationId = mutationId, - customScalarAdapters = customScalarAdapters, - ) - - /** - * @see ApolloStore.writeOptimisticUpdates - */ - fun writeOptimisticUpdates( - fragment: Fragment, - cacheKey: CacheKey, - data: D, - mutationId: Uuid, - ): Set = apolloStore.writeOptimisticUpdates( - fragment = fragment, - cacheKey = cacheKey, - data = data, - mutationId = mutationId, - customScalarAdapters = customScalarAdapters, - ) - - /** - * @see ApolloStore.rollbackOptimisticUpdates - */ - fun rollbackOptimisticUpdates(mutationId: Uuid): Set = apolloStore.rollbackOptimisticUpdates(mutationId) - - /** - * @see ApolloStore.clearAll - */ - fun clearAll(): Boolean = apolloStore.clearAll() - - /** - * @see ApolloStore.remove - */ - fun remove(cacheKey: CacheKey, cascade: Boolean = true): Boolean = apolloStore.remove(cacheKey, cascade) - - /** - * @see ApolloStore.remove - */ - fun remove(cacheKeys: List, cascade: Boolean = true): Int = apolloStore.remove(cacheKeys, cascade) - - /** - * @see ApolloStore.trim - */ - fun trim(maxSizeBytes: Long, trimFactor: Float = 0.1f): Long = apolloStore.trim(maxSizeBytes, trimFactor) - - /** - * @see ApolloStore.normalize - */ - fun normalize( - executable: Executable, - dataWithErrors: DataWithErrors, - rootKey: CacheKey = CacheKey.QUERY_ROOT, - ): Map = apolloStore.normalize( - executable = executable, - dataWithErrors = dataWithErrors, - rootKey = rootKey, - customScalarAdapters = customScalarAdapters, - ) - - /** - * @see ApolloStore.publish - */ - suspend fun publish(keys: Set) = apolloStore.publish(keys) - - /** - * @see ApolloStore.publish - */ - fun accessCache(block: (NormalizedCache) -> R): R = apolloStore.accessCache(block) - - /** - * @see ApolloStore.dump - */ - fun dump(): Map, Map> = apolloStore.dump() - - /** - * @see ApolloStore.dispose - */ - fun dispose() = apolloStore.dispose() -} diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/ApolloCacheInterceptor.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/ApolloCacheInterceptor.kt index e2b546e0..1a46d835 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/ApolloCacheInterceptor.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/ApolloCacheInterceptor.kt @@ -14,9 +14,8 @@ import com.apollographql.apollo.exception.apolloExceptionHandler import com.apollographql.apollo.interceptor.ApolloInterceptor import com.apollographql.apollo.interceptor.ApolloInterceptorChain import com.apollographql.apollo.mpp.currentTimeMillis -import com.apollographql.cache.normalized.ApolloStore -import com.apollographql.cache.normalized.ApolloStoreInterceptor import com.apollographql.cache.normalized.CacheInfo +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.ApolloCacheHeaders import com.apollographql.cache.normalized.api.CacheHeaders import com.apollographql.cache.normalized.cacheHeaders @@ -36,8 +35,8 @@ import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch internal class ApolloCacheInterceptor( - val store: ApolloStore, -) : ApolloInterceptor, ApolloStoreInterceptor { + val cacheManager: CacheManager, +) : ApolloInterceptor { private suspend fun maybeAsync(request: ApolloRequest, block: suspend () -> Unit) { if (request.writeToCacheAsynchronously) { val scope = request.executionContext[ConcurrencyInfo]!!.coroutineScope @@ -80,11 +79,11 @@ internal class ApolloCacheInterceptor( if (request.errorsReplaceCachedValues) { cacheHeaders += CacheHeaders.Builder().addHeader(ApolloCacheHeaders.ERRORS_REPLACE_CACHED_VALUES, "true").build() } - store.writeOperation(request.operation, response.data!!, response.errors, customScalarAdapters, cacheHeaders) + cacheManager.writeOperation(request.operation, response.data!!, response.errors, customScalarAdapters, cacheHeaders) } else { emptySet() } - store.publish(cacheKeys + extraKeys) + cacheManager.publish(cacheKeys + extraKeys) } } @@ -139,12 +138,12 @@ internal class ApolloCacheInterceptor( val optimisticData = request.optimisticData if (optimisticData != null) { @Suppress("UNCHECKED_CAST") - store.writeOptimisticUpdates( + cacheManager.writeOptimisticUpdates( operation = request.operation, data = optimisticData as D, mutationId = request.requestUuid, customScalarAdapters = customScalarAdapters, - ).also { store.publish(it) } + ).also { cacheManager.publish(it) } } /** @@ -165,7 +164,7 @@ internal class ApolloCacheInterceptor( } previousResponse = response if (optimisticKeys == null) optimisticKeys = if (optimisticData != null) { - store.rollbackOptimisticUpdates(request.requestUuid) + cacheManager.rollbackOptimisticUpdates(request.requestUuid) } else { emptySet() } @@ -176,12 +175,12 @@ internal class ApolloCacheInterceptor( if (networkException != null) { if (optimisticKeys == null) optimisticKeys = if (optimisticData != null) { - store.rollbackOptimisticUpdates(request.requestUuid) + cacheManager.rollbackOptimisticUpdates(request.requestUuid) } else { emptySet() } - store.publish(optimisticKeys) + cacheManager.publish(optimisticKeys) } } } @@ -208,7 +207,7 @@ internal class ApolloCacheInterceptor( cacheHeaders += CacheHeaders.Builder().addHeader(ApolloCacheHeaders.MEMORY_CACHE_ONLY, "true").build() } val startMillis = currentTimeMillis() - val response = store.readOperation( + val response = cacheManager.readOperation( operation = request.operation, customScalarAdapters = customScalarAdapters, cacheHeaders = cacheHeaders, diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/DefaultApolloStore.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/DefaultCacheManager.kt similarity index 98% rename from normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/DefaultApolloStore.kt rename to normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/DefaultCacheManager.kt index d4e4e99b..16b6c83c 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/DefaultApolloStore.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/DefaultCacheManager.kt @@ -9,9 +9,9 @@ import com.apollographql.apollo.api.Operation import com.apollographql.apollo.api.json.ApolloJsonElement import com.apollographql.apollo.api.json.jsonReader import com.apollographql.apollo.api.variables -import com.apollographql.cache.normalized.ApolloStore -import com.apollographql.cache.normalized.ApolloStore.ReadResult import com.apollographql.cache.normalized.CacheInfo +import com.apollographql.cache.normalized.CacheManager +import com.apollographql.cache.normalized.CacheManager.ReadResult import com.apollographql.cache.normalized.api.ApolloCacheHeaders import com.apollographql.cache.normalized.api.CacheHeaders import com.apollographql.cache.normalized.api.CacheKey @@ -38,7 +38,7 @@ import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.asSharedFlow import kotlin.reflect.KClass -internal class DefaultApolloStore( +internal class DefaultCacheManager( normalizedCacheFactory: NormalizedCacheFactory, private val cacheKeyGenerator: CacheKeyGenerator, private val fieldKeyGenerator: FieldKeyGenerator, @@ -47,7 +47,7 @@ internal class DefaultApolloStore( private val recordMerger: RecordMerger, private val embeddedFieldsProvider: EmbeddedFieldsProvider, private val maxAgeProvider: MaxAgeProvider, -) : ApolloStore { +) : CacheManager { private val changedKeysEvents = MutableSharedFlow>( /** * The '64' magic number here is a potential code smell @@ -78,7 +78,7 @@ internal class DefaultApolloStore( } override suspend fun publish(keys: Set) { - if (keys.isEmpty() && keys !== ApolloStore.ALL_KEYS) { + if (keys.isEmpty() && keys !== CacheManager.ALL_KEYS) { return } diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/WatcherInterceptor.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/WatcherInterceptor.kt index 2af3ad45..4eabe158 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/WatcherInterceptor.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/WatcherInterceptor.kt @@ -8,8 +8,7 @@ import com.apollographql.apollo.api.Query import com.apollographql.apollo.exception.DefaultApolloException import com.apollographql.apollo.interceptor.ApolloInterceptor import com.apollographql.apollo.interceptor.ApolloInterceptorChain -import com.apollographql.cache.normalized.ApolloStore -import com.apollographql.cache.normalized.ApolloStoreInterceptor +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.dependentKeys import com.apollographql.cache.normalized.api.withErrors @@ -26,7 +25,7 @@ import kotlinx.coroutines.flow.onSubscription internal val WatcherSentinel = DefaultApolloException("The watcher has started") -internal class WatcherInterceptor(val store: ApolloStore) : ApolloInterceptor, ApolloStoreInterceptor { +internal class WatcherInterceptor(val cacheManager: CacheManager) : ApolloInterceptor { override fun intercept(request: ApolloRequest, chain: ApolloInterceptorChain): Flow> { val watchContext = request.watchContext ?: return chain.proceed(request) @@ -44,7 +43,7 @@ internal class WatcherInterceptor(val store: ApolloStore) : ApolloInterceptor, A errors = null, customScalarAdapters = customScalarAdapters, ) - store.normalize( + cacheManager.normalize( executable = request.operation, dataWithErrors = dataWithErrors, rootKey = CacheKey.QUERY_ROOT, @@ -52,13 +51,13 @@ internal class WatcherInterceptor(val store: ApolloStore) : ApolloInterceptor, A ).values.dependentKeys() } - return (store.changedKeys as SharedFlow) + return (cacheManager.changedKeys as SharedFlow) .onSubscription { emit(Unit) } .filter { changedKeys -> changedKeys !is Set<*> || - changedKeys === ApolloStore.ALL_KEYS || + changedKeys === CacheManager.ALL_KEYS || watchedKeys == null || changedKeys.intersect(watchedKeys!!).isNotEmpty() }.map { @@ -73,7 +72,7 @@ internal class WatcherInterceptor(val store: ApolloStore) : ApolloInterceptor, A errors = response.errors, customScalarAdapters = customScalarAdapters, ) - watchedKeys = store.normalize( + watchedKeys = cacheManager.normalize( executable = request.operation, dataWithErrors = dataWithErrors, rootKey = CacheKey.QUERY_ROOT, diff --git a/normalized-cache/src/commonTest/kotlin/com/apollographql/cache/normalized/MemoryCacheTest.kt b/normalized-cache/src/commonTest/kotlin/com/apollographql/cache/normalized/MemoryCacheTest.kt index b2fbb5b1..37d5e92e 100644 --- a/normalized-cache/src/commonTest/kotlin/com/apollographql/cache/normalized/MemoryCacheTest.kt +++ b/normalized-cache/src/commonTest/kotlin/com/apollographql/cache/normalized/MemoryCacheTest.kt @@ -278,8 +278,8 @@ class MemoryCacheTest { return MemoryCache(maxSizeBytes = maxSizeBytes, expireAfterMillis = expireAfterMillis, nextCache = nextCache) } - private fun assertTestRecordPresentAndAccurate(testRecord: Record, store: NormalizedCache) { - val cacheRecord = checkNotNull(store.loadRecord(testRecord.key, CacheHeaders.NONE)) + private fun assertTestRecordPresentAndAccurate(testRecord: Record, cache: NormalizedCache) { + val cacheRecord = checkNotNull(cache.loadRecord(testRecord.key, CacheHeaders.NONE)) assertEquals(testRecord.key, cacheRecord.key) assertEquals(testRecord.fields, cacheRecord.fields) } diff --git a/samples/pagination/pagination-support/README.md b/samples/pagination/pagination-support/README.md index f08a2b9f..1a68ef2d 100644 --- a/samples/pagination/pagination-support/README.md +++ b/samples/pagination/pagination-support/README.md @@ -17,8 +17,8 @@ Note: to execute the app, provide a [GitHub access token](https://developer.gith ``` and the cache declaration in `Apollo.kt`: ```kotlin - .store( - ApolloStore( + .cacheManager( + CacheManager( normalizedCacheFactory = memoryThenSqlCache, cacheKeyGenerator = TypePolicyCacheKeyGenerator, metadataGenerator = ConnectionMetadataGenerator(Pagination.connectionTypes), // Use the generated Pagination class diff --git a/tests/cache-control/src/commonTest/kotlin/ClientAndServerSideCacheControlTest.kt b/tests/cache-control/src/commonTest/kotlin/ClientAndServerSideCacheControlTest.kt index 157054ca..c6e354d1 100644 --- a/tests/cache-control/src/commonTest/kotlin/ClientAndServerSideCacheControlTest.kt +++ b/tests/cache-control/src/commonTest/kotlin/ClientAndServerSideCacheControlTest.kt @@ -11,6 +11,7 @@ import com.apollographql.cache.normalized.api.GlobalMaxAgeProvider import com.apollographql.cache.normalized.api.MaxAge import com.apollographql.cache.normalized.api.NormalizedCacheFactory import com.apollographql.cache.normalized.api.SchemaCoordinatesMaxAgeProvider +import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.cacheHeaders import com.apollographql.cache.normalized.cacheInfo import com.apollographql.cache.normalized.fetchPolicy @@ -19,7 +20,6 @@ import com.apollographql.cache.normalized.maxStale import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.normalizedCache import com.apollographql.cache.normalized.sql.SqlNormalizedCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.storeExpirationDate import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockResponse @@ -69,7 +69,7 @@ class ClientAndServerSideCacheControlTest { .storeExpirationDate(true) .serverUrl(mockServer.url()) .build() - client.store.clearAll() + client.apolloStore.clearAll() val data = """ { @@ -148,7 +148,7 @@ class ClientAndServerSideCacheControlTest { .storeExpirationDate(true) .serverUrl(mockServer.url()) .build() - client.store.clearAll() + client.apolloStore.clearAll() val data = """ { @@ -220,7 +220,7 @@ class ClientAndServerSideCacheControlTest { ) .serverUrl(mockServer.url()) .build() - client.store.clearAll() + client.apolloStore.clearAll() val data = """ { diff --git a/tests/cache-control/src/commonTest/kotlin/ClientSideCacheControlTest.kt b/tests/cache-control/src/commonTest/kotlin/ClientSideCacheControlTest.kt index 106efaba..e511719c 100644 --- a/tests/cache-control/src/commonTest/kotlin/ClientSideCacheControlTest.kt +++ b/tests/cache-control/src/commonTest/kotlin/ClientSideCacheControlTest.kt @@ -12,13 +12,13 @@ import com.apollographql.cache.normalized.api.GlobalMaxAgeProvider import com.apollographql.cache.normalized.api.MaxAge import com.apollographql.cache.normalized.api.NormalizedCacheFactory import com.apollographql.cache.normalized.api.SchemaCoordinatesMaxAgeProvider +import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.internal.normalized import com.apollographql.cache.normalized.maxStale import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.normalizedCache import com.apollographql.cache.normalized.sql.SqlNormalizedCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import programmatic.GetCompanyQuery import programmatic.GetUserAdminQuery @@ -85,14 +85,14 @@ class ClientSideCacheControlTest { ) .serverUrl("unused") .build() - client.store.clearAll() + client.apolloStore.clearAll() val query = GetUserQuery() val data = GetUserQuery.Data(GetUserQuery.User("John", "john@doe.com", true)) val records = data.normalized(query).values - client.store.accessCache { + client.apolloStore.accessCache { // store records in the past it.merge(records, receivedDate(currentTimeSeconds() - 15), DefaultRecordMerger) } @@ -106,7 +106,7 @@ class ClientSideCacheControlTest { .execute() assertTrue(response1.data?.user?.name == "John") - client.store.accessCache { + client.apolloStore.accessCache { // update records to be in the present it.merge(records, receivedDate(currentTimeSeconds()), DefaultRecordMerger) } @@ -132,7 +132,7 @@ class ClientSideCacheControlTest { ) .serverUrl("unused") .build() - client.store.clearAll() + client.apolloStore.clearAll() // Store records 25 seconds ago, more than default max age: should cache miss mergeCompanyQueryResults(client, 25) @@ -182,7 +182,7 @@ class ClientSideCacheControlTest { private fun mergeCompanyQueryResults(client: ApolloClient, secondsAgo: Int) { val data = GetCompanyQuery.Data(GetCompanyQuery.Company("42")) val records = data.normalized(GetCompanyQuery()).values - client.store.accessCache { + client.apolloStore.accessCache { it.merge(records, receivedDate(currentTimeSeconds() - secondsAgo), DefaultRecordMerger) } } @@ -200,7 +200,7 @@ class ClientSideCacheControlTest { ) .serverUrl("unused") .build() - client.store.clearAll() + client.apolloStore.clearAll() // Store records 25 seconds ago, more than default max age: should cache miss mergeCompanyQueryResults(client, 25) @@ -260,7 +260,7 @@ class ClientSideCacheControlTest { private fun mergeUserQueryResults(client: ApolloClient, secondsAgo: Int) { val data = GetUserQuery.Data(GetUserQuery.User("John", "john@doe.com", true)) val records = data.normalized(GetUserQuery()).values - client.store.accessCache { + client.apolloStore.accessCache { it.merge(records, receivedDate(currentTimeSeconds() - secondsAgo), DefaultRecordMerger) } } @@ -268,7 +268,7 @@ class ClientSideCacheControlTest { private fun mergeProjectQueryResults(client: ApolloClient, secondsAgo: Int) { val data = declarative.GetProjectQuery.Data(declarative.GetProjectQuery.Project("42", "Stardust")) val records = data.normalized(declarative.GetProjectQuery()).values - client.store.accessCache { + client.apolloStore.accessCache { it.merge(records, receivedDate(currentTimeSeconds() - secondsAgo), DefaultRecordMerger) } } diff --git a/tests/cache-control/src/commonTest/kotlin/DoNotStoreTest.kt b/tests/cache-control/src/commonTest/kotlin/DoNotStoreTest.kt index 8b770d95..569328f5 100644 --- a/tests/cache-control/src/commonTest/kotlin/DoNotStoreTest.kt +++ b/tests/cache-control/src/commonTest/kotlin/DoNotStoreTest.kt @@ -15,13 +15,13 @@ import com.apollographql.cache.normalized.api.FieldKeyContext import com.apollographql.cache.normalized.api.FieldKeyGenerator import com.apollographql.cache.normalized.api.NormalizedCacheFactory import com.apollographql.cache.normalized.api.SchemaCoordinatesMaxAgeProvider +import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.fetchFromCache import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.fetchPolicyInterceptor import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.normalizedCache import com.apollographql.cache.normalized.sql.SqlNormalizedCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.append import com.apollographql.cache.normalized.testing.assertErrorsEquals import com.apollographql.cache.normalized.testing.keyToString @@ -99,7 +99,7 @@ class DoNotStoreTest { ) .build() .use { apolloClient -> - apolloClient.store.clearAll() + apolloClient.apolloStore.clearAll() val networkResponse = apolloClient.query(GetUserQuery()) .fetchPolicy(FetchPolicy.NetworkOnly) .execute() @@ -195,7 +195,7 @@ class DoNotStoreTest { ) .build() .use { apolloClient -> - apolloClient.store.clearAll() + apolloClient.apolloStore.clearAll() val networkResponse = apolloClient.mutation(SignInMutation("scott", "tiger")) .fetchPolicy(FetchPolicy.NetworkOnly) .execute() @@ -221,7 +221,7 @@ class DoNotStoreTest { networkResponse.data ) - apolloClient.store.accessCache { cache -> + apolloClient.apolloStore.accessCache { cache -> val authRecord = cache.loadRecord(CacheKey.MUTATION_ROOT.append("auth"), CacheHeaders.NONE)!! // No password in field key assertContentEquals(listOf("signIn"), authRecord.fields.keys) diff --git a/tests/cache-control/src/commonTest/kotlin/ServerSideCacheControlTest.kt b/tests/cache-control/src/commonTest/kotlin/ServerSideCacheControlTest.kt index 241f10e2..e3dc07ee 100644 --- a/tests/cache-control/src/commonTest/kotlin/ServerSideCacheControlTest.kt +++ b/tests/cache-control/src/commonTest/kotlin/ServerSideCacheControlTest.kt @@ -6,12 +6,12 @@ import com.apollographql.apollo.exception.CacheMissException import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.CacheControlCacheResolver import com.apollographql.cache.normalized.api.NormalizedCacheFactory +import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.maxStale import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.normalizedCache import com.apollographql.cache.normalized.sql.SqlNormalizedCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.storeExpirationDate import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockResponse @@ -48,7 +48,7 @@ class ServerSideCacheControlTest { .storeExpirationDate(true) .serverUrl(mockServer.url()) .build() - client.store.clearAll() + client.apolloStore.clearAll() val query = GetUserQuery() val data = """ diff --git a/tests/cache-variables-arguments/src/commonTest/kotlin/test/IncludeTest.kt b/tests/cache-variables-arguments/src/commonTest/kotlin/test/IncludeTest.kt index 084597a1..7fe5b2ee 100644 --- a/tests/cache-variables-arguments/src/commonTest/kotlin/test/IncludeTest.kt +++ b/tests/cache-variables-arguments/src/commonTest/kotlin/test/IncludeTest.kt @@ -3,10 +3,10 @@ package test import cache.include.GetUserQuery import com.apollographql.apollo.ApolloClient import com.apollographql.cache.normalized.FetchPolicy +import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.normalizedCache -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import kotlin.test.Test import kotlin.test.assertEquals @@ -25,7 +25,7 @@ class IncludeTest { user = GetUserQuery.User(__typename = "User", id = "42", userDetails = null) ) - client.store.writeOperation(operation, data) + client.apolloStore.writeOperation(operation, data) val response = client.query(operation).fetchPolicy(FetchPolicy.CacheOnly).execute() diff --git a/tests/defer/src/commonTest/kotlin/test/DeferNormalizedCacheTest.kt b/tests/defer/src/commonTest/kotlin/test/DeferNormalizedCacheTest.kt index 183c7b97..e19b4807 100644 --- a/tests/defer/src/commonTest/kotlin/test/DeferNormalizedCacheTest.kt +++ b/tests/defer/src/commonTest/kotlin/test/DeferNormalizedCacheTest.kt @@ -11,14 +11,15 @@ import com.apollographql.apollo.exception.ApolloHttpException import com.apollographql.apollo.exception.ApolloNetworkException import com.apollographql.apollo.exception.CacheMissException import com.apollographql.apollo.network.NetworkTransport -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.CacheHeaders import com.apollographql.cache.normalized.api.CacheKey +import com.apollographql.cache.normalized.apolloStore +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.optimisticUpdates -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.Platform import com.apollographql.cache.normalized.testing.append import com.apollographql.cache.normalized.testing.keyToString @@ -54,12 +55,12 @@ import kotlin.test.assertTrue class DeferNormalizedCacheTest { private lateinit var mockServer: MockServer private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private suspend fun setUp() { - store = ApolloStore(MemoryCacheFactory()) + cacheManager = CacheManager(MemoryCacheFactory()) mockServer = MockServer() - apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).store(store).build() + apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() } private fun tearDown() { @@ -421,7 +422,7 @@ class DeferNormalizedCacheTest { ) apolloClient = ApolloClient.Builder() - .store(store) + .cacheManager(cacheManager) .fetchPolicy(FetchPolicy.NetworkFirst) .networkTransport( object : NetworkTransport { @@ -496,7 +497,7 @@ class DeferNormalizedCacheTest { assertEquals(networkExpected, networkActual) // Now cache is not empty - val cacheActual = store.readFragment(ComputerFieldsImpl(), CacheKey.MUTATION_ROOT.append("computers", "0")).data + val cacheActual = cacheManager.readFragment(ComputerFieldsImpl(), CacheKey.MUTATION_ROOT.append("computers", "0")).data println(cacheActual) // We get the last/fully formed data @@ -542,7 +543,7 @@ class DeferNormalizedCacheTest { val multipartBody = mockServer.enqueueMultipart("application/json") multipartBody.enqueuePart(jsonList[0].encodeUtf8(), false) val recordFields = apolloClient.query(SimpleDeferQuery()).fetchPolicy(FetchPolicy.NetworkOnly).toFlow().map { - apolloClient.store.accessCache { it.loadRecord(CacheKey("computers").append("0"), CacheHeaders.NONE)!!.fields }.also { + apolloClient.apolloStore.accessCache { it.loadRecord(CacheKey("computers").append("0"), CacheHeaders.NONE)!!.fields }.also { multipartBody.enqueuePart(jsonList[1].encodeUtf8(), true) } }.toList() diff --git a/tests/garbage-collection/src/commonTest/kotlin/DanglingReferencesTest.kt b/tests/garbage-collection/src/commonTest/kotlin/DanglingReferencesTest.kt index c9cfed79..85cae628 100644 --- a/tests/garbage-collection/src/commonTest/kotlin/DanglingReferencesTest.kt +++ b/tests/garbage-collection/src/commonTest/kotlin/DanglingReferencesTest.kt @@ -1,15 +1,16 @@ package test import com.apollographql.apollo.ApolloClient -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.allRecords import com.apollographql.cache.normalized.api.CacheKey +import com.apollographql.cache.normalized.apolloStore +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.removeDanglingReferences import com.apollographql.cache.normalized.sql.SqlNormalizedCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.append import com.apollographql.cache.normalized.testing.fieldKey import com.apollographql.cache.normalized.testing.runTest @@ -24,22 +25,22 @@ import kotlin.test.assertTrue class DanglingReferencesTest { @Test - fun simpleMemory() = simple(ApolloStore(MemoryCacheFactory())) + fun simpleMemory() = simple(CacheManager(MemoryCacheFactory())) @Test - fun simpleSql() = simple(ApolloStore(SqlNormalizedCacheFactory())) + fun simpleSql() = simple(CacheManager(SqlNormalizedCacheFactory())) @Test fun simpleChained(): TestResult { - return simple(ApolloStore(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) + return simple(CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) } - private fun simple(apolloStore: ApolloStore) = runTest { + private fun simple(cacheManager: CacheManager) = runTest { val mockServer = MockServer() - val store = apolloStore.also { it.clearAll() } + cacheManager.clearAll() ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .build() .use { apolloClient -> mockServer.enqueueString(REPOSITORY_LIST_RESPONSE) @@ -47,12 +48,12 @@ class DanglingReferencesTest { .fetchPolicy(FetchPolicy.NetworkOnly) .execute() - var allRecords = store.accessCache { it.allRecords() } + var allRecords = cacheManager.accessCache { it.allRecords() } assertTrue(allRecords[CacheKey("Repository:0")]!!.fields.containsKey("starGazers")) // Remove User 1, now Repository 0.starGazers is a dangling reference - store.remove(CacheKey("User:1"), cascade = false) - val removedFieldsAndRecords = store.removeDanglingReferences() + cacheManager.remove(CacheKey("User:1"), cascade = false) + val removedFieldsAndRecords = apolloClient.apolloStore.removeDanglingReferences() assertEquals( setOf(CacheKey("Repository:0").fieldKey("starGazers")), removedFieldsAndRecords.removedFields @@ -61,26 +62,26 @@ class DanglingReferencesTest { emptySet(), removedFieldsAndRecords.removedRecords ) - allRecords = store.accessCache { it.allRecords() } + allRecords = cacheManager.accessCache { it.allRecords() } assertFalse(allRecords[CacheKey("Repository:0")]!!.fields.containsKey("starGazers")) } } @Test - fun multipleMemory() = multiple(ApolloStore(MemoryCacheFactory())) + fun multipleMemory() = multiple(CacheManager(MemoryCacheFactory())) @Test - fun multipleSql() = multiple(ApolloStore(SqlNormalizedCacheFactory())) + fun multipleSql() = multiple(CacheManager(SqlNormalizedCacheFactory())) @Test - fun multipleChained() = multiple(ApolloStore(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) + fun multipleChained() = multiple(CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) - private fun multiple(apolloStore: ApolloStore) = runTest { + private fun multiple(cacheManager: CacheManager) = runTest { val mockServer = MockServer() - val store = apolloStore.also { it.clearAll() } + cacheManager.clearAll() ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .build() .use { apolloClient -> mockServer.enqueueString(META_PROJECT_LIST_RESPONSE) @@ -95,8 +96,8 @@ class DanglingReferencesTest { // thus (metaProjects.0.0) is empty and removed // thus (QUERY_ROOT).metaProjects is a dangling reference // thus QUERY_ROOT is empty and removed - store.remove(CacheKey("User:0"), cascade = false) - val removedFieldsAndRecords = store.removeDanglingReferences() + cacheManager.remove(CacheKey("User:0"), cascade = false) + val removedFieldsAndRecords = apolloClient.apolloStore.removeDanglingReferences() assertEquals( setOf( CacheKey("metaProjects").append("0", "0", "type").fieldKey("owners"), @@ -113,7 +114,7 @@ class DanglingReferencesTest { ), removedFieldsAndRecords.removedRecords ) - val allRecords = store.accessCache { it.allRecords() } + val allRecords = cacheManager.accessCache { it.allRecords() } assertFalse(allRecords.containsKey(CacheKey("QUERY_ROOT"))) assertFalse(allRecords.containsKey(CacheKey("metaProjects").append("0", "0"))) assertFalse(allRecords.containsKey(CacheKey("metaProjects").append("0", "0", "type"))) diff --git a/tests/garbage-collection/src/commonTest/kotlin/GarbageCollectTest.kt b/tests/garbage-collection/src/commonTest/kotlin/GarbageCollectTest.kt index fe646c1a..8388cfc0 100644 --- a/tests/garbage-collection/src/commonTest/kotlin/GarbageCollectTest.kt +++ b/tests/garbage-collection/src/commonTest/kotlin/GarbageCollectTest.kt @@ -1,17 +1,18 @@ package test import com.apollographql.apollo.ApolloClient -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.allRecords import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.SchemaCoordinatesMaxAgeProvider +import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.cacheHeaders +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.garbageCollect import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.sql.SqlNormalizedCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.append import com.apollographql.cache.normalized.testing.fieldKey import com.apollographql.cache.normalized.testing.runTest @@ -25,20 +26,20 @@ import kotlin.time.Duration.Companion.seconds class GarbageCollectTest { @Test - fun garbageCollectMemory() = garbageCollect(ApolloStore(MemoryCacheFactory())) + fun garbageCollectMemory() = garbageCollect(CacheManager(MemoryCacheFactory())) @Test - fun garbageCollectSql() = garbageCollect(ApolloStore(SqlNormalizedCacheFactory())) + fun garbageCollectSql() = garbageCollect(CacheManager(SqlNormalizedCacheFactory())) @Test - fun garbageCollectChained() = garbageCollect(ApolloStore(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) + fun garbageCollectChained() = garbageCollect(CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) - private fun garbageCollect(apolloStore: ApolloStore) = runTest { + private fun garbageCollect(cacheManager: CacheManager) = runTest { val mockServer = MockServer() - val store = apolloStore.also { it.clearAll() } + cacheManager.clearAll() ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .build() .use { apolloClient -> mockServer.enqueueString(META_PROJECT_LIST_RESPONSE) @@ -58,7 +59,7 @@ class GarbageCollectTest { Cache.maxAges, defaultMaxAge = 120.seconds, ) - val garbageCollectResult = store.garbageCollect(maxAgeProvider) + val garbageCollectResult = apolloClient.apolloStore.garbageCollect(maxAgeProvider) assertEquals( setOf( CacheKey("metaProjects").append("0", "0", "type").fieldKey("owners"), @@ -104,7 +105,7 @@ class GarbageCollectTest { garbageCollectResult.removedUnreachableRecords ) - val allRecords = store.accessCache { it.allRecords() } + val allRecords = cacheManager.accessCache { it.allRecords() } assertEquals(emptyMap(), allRecords) } } diff --git a/tests/garbage-collection/src/commonTest/kotlin/ReachableCacheKeysTest.kt b/tests/garbage-collection/src/commonTest/kotlin/ReachableCacheKeysTest.kt index 4c71f5e0..be7b2a7b 100644 --- a/tests/garbage-collection/src/commonTest/kotlin/ReachableCacheKeysTest.kt +++ b/tests/garbage-collection/src/commonTest/kotlin/ReachableCacheKeysTest.kt @@ -1,16 +1,17 @@ package test import com.apollographql.apollo.ApolloClient -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.allRecords import com.apollographql.cache.normalized.api.CacheKey +import com.apollographql.cache.normalized.apolloStore +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.getReachableCacheKeys import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.removeUnreachableRecords import com.apollographql.cache.normalized.sql.SqlNormalizedCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.storeReceivedDate import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockServer @@ -23,20 +24,20 @@ import kotlin.test.assertEquals class ReachableCacheKeysTest { @Test - fun getReachableCacheKeysMemory() = getReachableCacheKeys(ApolloStore(MemoryCacheFactory())) + fun getReachableCacheKeysMemory() = getReachableCacheKeys(CacheManager(MemoryCacheFactory())) @Test - fun getReachableCacheKeysSql() = getReachableCacheKeys(ApolloStore(SqlNormalizedCacheFactory())) + fun getReachableCacheKeysSql() = getReachableCacheKeys(CacheManager(SqlNormalizedCacheFactory())) @Test - fun getReachableCacheKeysChained() = getReachableCacheKeys(ApolloStore(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) + fun getReachableCacheKeysChained() = getReachableCacheKeys(CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) - private fun getReachableCacheKeys(apolloStore: ApolloStore) = runTest { + private fun getReachableCacheKeys(cacheManager: CacheManager) = runTest { val mockServer = MockServer() - val store = apolloStore.also { it.clearAll() } + cacheManager.clearAll() ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .storeReceivedDate(true) .build() .use { apolloClient -> @@ -133,7 +134,7 @@ class ReachableCacheKeysTest { ) apolloClient.query(query).fetchPolicy(FetchPolicy.NetworkOnly).execute() - var reachableCacheKeys = store.accessCache { it.allRecords().getReachableCacheKeys() } + var reachableCacheKeys = cacheManager.accessCache { it.allRecords().getReachableCacheKeys() } assertEquals( setOf( CacheKey("QUERY_ROOT"), @@ -153,8 +154,8 @@ class ReachableCacheKeysTest { ) // Remove User 43, now Repositories 5 and 6 should not be reachable / 7 should still be reachable - store.remove(CacheKey("User:43"), cascade = false) - reachableCacheKeys = store.accessCache { it.allRecords().getReachableCacheKeys() } + cacheManager.remove(CacheKey("User:43"), cascade = false) + reachableCacheKeys = cacheManager.accessCache { it.allRecords().getReachableCacheKeys() } assertEquals( setOf( CacheKey("QUERY_ROOT"), @@ -171,12 +172,12 @@ class ReachableCacheKeysTest { ) // Add a non-reachable Repository, reachableCacheKeys should not change - store.writeFragment( + cacheManager.writeFragment( RepositoryFragmentImpl(), CacheKey("Repository:500"), RepositoryFragment(id = "500", __typename = "Repository", starGazers = emptyList()), ) - reachableCacheKeys = store.accessCache { it.allRecords().getReachableCacheKeys() } + reachableCacheKeys = cacheManager.accessCache { it.allRecords().getReachableCacheKeys() } assertEquals( setOf( CacheKey("QUERY_ROOT"), @@ -206,11 +207,11 @@ class ReachableCacheKeysTest { CacheKey("Repository:500"), CacheKey("Repository:7"), ), - store.accessCache { it.allRecords() }.keys.toSet() + cacheManager.accessCache { it.allRecords() }.keys.toSet() ) // Remove unreachable records, should remove Repositories 5, 6, and 500 - val removedKeys = store.removeUnreachableRecords() + val removedKeys = apolloClient.apolloStore.removeUnreachableRecords() assertEquals( setOf( CacheKey("QUERY_ROOT"), @@ -223,7 +224,7 @@ class ReachableCacheKeysTest { CacheKey("Repository:2"), CacheKey("Repository:1"), ), - store.accessCache { it.allRecords() }.keys.toSet() + cacheManager.accessCache { it.allRecords() }.keys.toSet() ) assertEquals( setOf( diff --git a/tests/garbage-collection/src/commonTest/kotlin/StaleFieldsTest.kt b/tests/garbage-collection/src/commonTest/kotlin/StaleFieldsTest.kt index 13f22189..c06f1058 100644 --- a/tests/garbage-collection/src/commonTest/kotlin/StaleFieldsTest.kt +++ b/tests/garbage-collection/src/commonTest/kotlin/StaleFieldsTest.kt @@ -2,7 +2,7 @@ package test import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.mpp.currentTimeMillis -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.allRecords import com.apollographql.cache.normalized.api.ApolloCacheHeaders @@ -10,12 +10,13 @@ import com.apollographql.cache.normalized.api.CacheHeaders import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.GlobalMaxAgeProvider import com.apollographql.cache.normalized.api.SchemaCoordinatesMaxAgeProvider +import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.cacheHeaders +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.removeStaleFields import com.apollographql.cache.normalized.sql.SqlNormalizedCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.append import com.apollographql.cache.normalized.testing.fieldKey import com.apollographql.cache.normalized.testing.runTest @@ -32,21 +33,21 @@ import kotlin.time.Duration.Companion.seconds class StaleFieldsTest { @Test - fun clientControlledRemoveFieldsMemory() = clientControlledRemoveFields(ApolloStore(MemoryCacheFactory())) + fun clientControlledRemoveFieldsMemory() = clientControlledRemoveFields(CacheManager(MemoryCacheFactory())) @Test - fun clientControlledRemoveFieldsSql() = clientControlledRemoveFields(ApolloStore(SqlNormalizedCacheFactory())) + fun clientControlledRemoveFieldsSql() = clientControlledRemoveFields(CacheManager(SqlNormalizedCacheFactory())) @Test fun clientControlledRemoveFieldsChained() = - clientControlledRemoveFields(ApolloStore(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) + clientControlledRemoveFields(CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) - private fun clientControlledRemoveFields(apolloStore: ApolloStore) = runTest { + private fun clientControlledRemoveFields(cacheManager: CacheManager) = runTest { val mockServer = MockServer() - val store = apolloStore.also { it.clearAll() } + cacheManager.clearAll() ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .build() .use { apolloClient -> mockServer.enqueueString(REPOSITORY_LIST_RESPONSE) @@ -55,7 +56,7 @@ class StaleFieldsTest { .cacheHeaders(receivedDate(currentTimeSeconds() - 60)) .execute() - var allRecords = store.accessCache { it.allRecords() } + var allRecords = cacheManager.accessCache { it.allRecords() } assertTrue(allRecords[CacheKey("Repository:0")]!!.fields.containsKey("stars")) assertTrue(allRecords[CacheKey("Repository:0")]!!.fields.containsKey("starGazers")) assertTrue(allRecords[CacheKey("Repository:1")]!!.fields.containsKey("stars")) @@ -65,7 +66,7 @@ class StaleFieldsTest { Cache.maxAges, defaultMaxAge = 120.seconds, ) - var removedFieldsAndRecords = store.removeStaleFields(maxAgeProvider) + var removedFieldsAndRecords = apolloClient.apolloStore.removeStaleFields(maxAgeProvider) // Repository.stars has a max age of 60 seconds, so they should be removed / User has a max age of 90 seconds, so Repository.starGazers should be kept assertEquals( setOf( @@ -76,7 +77,7 @@ class StaleFieldsTest { assertEquals( emptySet(), removedFieldsAndRecords.removedRecords ) - allRecords = store.accessCache { it.allRecords() } + allRecords = cacheManager.accessCache { it.allRecords() } assertFalse(allRecords[CacheKey("Repository:0")]!!.fields.containsKey("stars")) assertTrue(allRecords[CacheKey("Repository:0")]!!.fields.containsKey("starGazers")) assertFalse(allRecords[CacheKey("Repository:1")]!!.fields.containsKey("stars")) @@ -87,7 +88,7 @@ class StaleFieldsTest { .fetchPolicy(FetchPolicy.NetworkOnly) .cacheHeaders(receivedDate(currentTimeSeconds() - 90)) .execute() - removedFieldsAndRecords = store.removeStaleFields(maxAgeProvider) + removedFieldsAndRecords = apolloClient.apolloStore.removeStaleFields(maxAgeProvider) // Repository.stars and Repository.starGazers should be removed assertEquals( setOf( @@ -100,7 +101,7 @@ class StaleFieldsTest { assertEquals( emptySet(), removedFieldsAndRecords.removedRecords ) - allRecords = store.accessCache { it.allRecords() } + allRecords = cacheManager.accessCache { it.allRecords() } assertFalse(allRecords[CacheKey("Repository:0")]!!.fields.containsKey("stars")) assertFalse(allRecords[CacheKey("Repository:0")]!!.fields.containsKey("starGazers")) assertFalse(allRecords[CacheKey("Repository:1")]!!.fields.containsKey("stars")) @@ -109,21 +110,21 @@ class StaleFieldsTest { } @Test - fun clientControlledRemoveRecordsMemory() = clientControlledRemoveRecords(ApolloStore(MemoryCacheFactory())) + fun clientControlledRemoveRecordsMemory() = clientControlledRemoveRecords(CacheManager(MemoryCacheFactory())) @Test - fun clientControlledRemoveRecordsSql() = clientControlledRemoveRecords(ApolloStore(SqlNormalizedCacheFactory())) + fun clientControlledRemoveRecordsSql() = clientControlledRemoveRecords(CacheManager(SqlNormalizedCacheFactory())) @Test fun clientControlledRemoveRecordsChained() = - clientControlledRemoveRecords(ApolloStore(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) + clientControlledRemoveRecords(CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) - private fun clientControlledRemoveRecords(apolloStore: ApolloStore) = runTest { + private fun clientControlledRemoveRecords(cacheManager: CacheManager) = runTest { val mockServer = MockServer() - val store = apolloStore.also { it.clearAll() } + cacheManager.clearAll() ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .build() .use { apolloClient -> mockServer.enqueueString(PROJECT_LIST_RESPONSE) @@ -132,7 +133,7 @@ class StaleFieldsTest { .cacheHeaders(receivedDate(currentTimeSeconds() - 60)) .execute() - var allRecords = store.accessCache { it.allRecords() } + var allRecords = cacheManager.accessCache { it.allRecords() } assertTrue(allRecords[CacheKey("projects").append("0")]!!.fields.containsKey("velocity")) assertTrue(allRecords[CacheKey("projects").append("0")]!!.fields.containsKey("isUrgent")) assertTrue(allRecords[CacheKey("projects").append("1")]!!.fields.containsKey("velocity")) @@ -142,7 +143,7 @@ class StaleFieldsTest { Cache.maxAges, defaultMaxAge = 120.seconds, ) - var removedFieldsAndRecords = store.removeStaleFields(maxAgeProvider) + var removedFieldsAndRecords = apolloClient.apolloStore.removeStaleFields(maxAgeProvider) // Project.velocity has a max age of 60 seconds, so they should be removed / Project.isUrgent has a max age of 90 seconds, so they should be kept assertEquals( setOf( @@ -153,7 +154,7 @@ class StaleFieldsTest { assertEquals( emptySet(), removedFieldsAndRecords.removedRecords ) - allRecords = store.accessCache { it.allRecords() } + allRecords = cacheManager.accessCache { it.allRecords() } assertFalse(allRecords[CacheKey("projects").append("0")]!!.fields.containsKey("velocity")) assertTrue(allRecords[CacheKey("projects").append("0")]!!.fields.containsKey("isUrgent")) assertFalse(allRecords[CacheKey("projects").append("1")]!!.fields.containsKey("velocity")) @@ -164,7 +165,7 @@ class StaleFieldsTest { .fetchPolicy(FetchPolicy.NetworkOnly) .cacheHeaders(receivedDate(currentTimeSeconds() - 90)) .execute() - removedFieldsAndRecords = store.removeStaleFields(maxAgeProvider) + removedFieldsAndRecords = apolloClient.apolloStore.removeStaleFields(maxAgeProvider) // Project.velocity and Project.isUrgent should be removed, their records being empty they should be removed assertEquals( setOf( @@ -180,28 +181,28 @@ class StaleFieldsTest { CacheKey("projects").append("1"), ), removedFieldsAndRecords.removedRecords ) - allRecords = store.accessCache { it.allRecords() } + allRecords = cacheManager.accessCache { it.allRecords() } assertFalse(allRecords.containsKey(CacheKey("projects").append("0"))) assertFalse(allRecords.containsKey(CacheKey("projects").append("1"))) } } @Test - fun serverControlledRemoveFieldsMemory() = serverControlledRemoveFields(ApolloStore(MemoryCacheFactory())) + fun serverControlledRemoveFieldsMemory() = serverControlledRemoveFields(CacheManager(MemoryCacheFactory())) @Test - fun serverControlledRemoveFieldsSql() = serverControlledRemoveFields(ApolloStore(SqlNormalizedCacheFactory())) + fun serverControlledRemoveFieldsSql() = serverControlledRemoveFields(CacheManager(SqlNormalizedCacheFactory())) @Test fun serverControlledRemoveFieldsChained() = - serverControlledRemoveFields(ApolloStore(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) + serverControlledRemoveFields(CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) - private fun serverControlledRemoveFields(apolloStore: ApolloStore) = runTest { + private fun serverControlledRemoveFields(cacheManager: CacheManager) = runTest { val mockServer = MockServer() - val store = apolloStore.also { it.clearAll() } + cacheManager.clearAll() ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .build() .use { apolloClient -> mockServer.enqueueString(REPOSITORY_LIST_RESPONSE) @@ -210,13 +211,13 @@ class StaleFieldsTest { .cacheHeaders(expirationDate(currentTimeSeconds() - 60)) .execute() - var allRecords = store.accessCache { it.allRecords() } + var allRecords = cacheManager.accessCache { it.allRecords() } assertTrue(allRecords[CacheKey("Repository:0")]!!.fields.containsKey("stars")) assertTrue(allRecords[CacheKey("Repository:0")]!!.fields.containsKey("starGazers")) assertTrue(allRecords[CacheKey("Repository:1")]!!.fields.containsKey("stars")) assertTrue(allRecords[CacheKey("Repository:1")]!!.fields.containsKey("starGazers")) - var removedFieldsAndRecords = store.removeStaleFields(GlobalMaxAgeProvider(Duration.INFINITE)) + var removedFieldsAndRecords = apolloClient.apolloStore.removeStaleFields(GlobalMaxAgeProvider(Duration.INFINITE)) // Everything is stale assertEquals( setOf( @@ -250,7 +251,7 @@ class StaleFieldsTest { CacheKey("QUERY_ROOT"), ), removedFieldsAndRecords.removedRecords ) - allRecords = store.accessCache { it.allRecords() } + allRecords = cacheManager.accessCache { it.allRecords() } assertTrue(allRecords.isEmpty()) mockServer.enqueueString(REPOSITORY_LIST_RESPONSE) @@ -259,7 +260,8 @@ class StaleFieldsTest { .cacheHeaders(expirationDate(currentTimeSeconds() - 60)) .execute() - removedFieldsAndRecords = store.removeStaleFields(GlobalMaxAgeProvider(Duration.INFINITE), maxStale = 70.seconds) + removedFieldsAndRecords = + apolloClient.apolloStore.removeStaleFields(GlobalMaxAgeProvider(Duration.INFINITE), maxStale = 70.seconds) // Nothing is stale assertEquals( emptySet(), @@ -269,7 +271,7 @@ class StaleFieldsTest { emptySet(), removedFieldsAndRecords.removedRecords ) - allRecords = store.accessCache { it.allRecords() } + allRecords = cacheManager.accessCache { it.allRecords() } assertTrue(allRecords[CacheKey("Repository:0")]!!.fields.containsKey("stars")) assertTrue(allRecords[CacheKey("Repository:0")]!!.fields.containsKey("starGazers")) assertTrue(allRecords[CacheKey("Repository:1")]!!.fields.containsKey("stars")) diff --git a/tests/migration/src/commonTest/kotlin/MigrationTest.kt b/tests/migration/src/commonTest/kotlin/MigrationTest.kt index eeb6c37d..89350225 100644 --- a/tests/migration/src/commonTest/kotlin/MigrationTest.kt +++ b/tests/migration/src/commonTest/kotlin/MigrationTest.kt @@ -3,17 +3,17 @@ package test import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.exception.CacheMissException import com.apollographql.apollo.mpp.currentTimeMillis -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.CacheHeaders import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.DefaultRecordMerger import com.apollographql.cache.normalized.api.Record import com.apollographql.cache.normalized.api.RecordValue +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.sql.SqlNormalizedCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockServer import com.apollographql.mockserver.enqueueString @@ -91,10 +91,10 @@ class MigrationTest { } // Open the legacy store which empties it. Add/read some data to make sure it works. - val store = ApolloStore(MemoryCacheFactory().chain(SqlNormalizedCacheFactory(name = name))) + val cacheManager = CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory(name = name))) ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .build() .use { apolloClient -> // Expected cache miss: the db has been cleared @@ -116,7 +116,7 @@ class MigrationTest { assertEquals(REPOSITORY_LIST_DATA, response.data) // Clean up - store.clearAll() + cacheManager.clearAll() } } @@ -137,13 +137,13 @@ class MigrationTest { } // Create a modern store and migrate the legacy data - val store = ApolloStore(SqlNormalizedCacheFactory(name = "modern.db")).also { it.clearAll() } - store.migrateFrom(legacyStore) + val cacheManager = CacheManager(SqlNormalizedCacheFactory(name = "modern.db")).also { it.clearAll() } + cacheManager.migrateFrom(legacyStore) // Read the data back ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .build() .use { apolloClient -> val response = apolloClient.query(RepositoryListQuery()) @@ -154,7 +154,7 @@ class MigrationTest { } } -private fun ApolloStore.migrateFrom(legacyStore: LegacyApolloStore) { +private fun CacheManager.migrateFrom(legacyStore: LegacyApolloStore) { accessCache { cache -> cache.merge( records = legacyStore.accessCache { it.allRecords() }.map { it.toRecord() }, diff --git a/tests/models-operation-based-with-interfaces/src/commonTest/kotlin/test/BasicTest.kt b/tests/models-operation-based-with-interfaces/src/commonTest/kotlin/test/BasicTest.kt index d0596f1f..d814e66a 100644 --- a/tests/models-operation-based-with-interfaces/src/commonTest/kotlin/test/BasicTest.kt +++ b/tests/models-operation-based-with-interfaces/src/commonTest/kotlin/test/BasicTest.kt @@ -7,12 +7,12 @@ import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.api.ApolloResponse import com.apollographql.apollo.api.Optional import com.apollographql.apollo.api.Query -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.IdCacheKeyGenerator +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockServer import com.apollographql.mockserver.enqueueString @@ -25,15 +25,15 @@ import kotlin.test.assertTrue class BasicTest { private lateinit var mockServer: MockServer private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private suspend fun setUp() { - store = ApolloStore( + cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator() ) mockServer = MockServer() - apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).store(store).build() + apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() } private suspend fun tearDown() { diff --git a/tests/models-operation-based-with-interfaces/src/commonTest/kotlin/test/StoreTest.kt b/tests/models-operation-based-with-interfaces/src/commonTest/kotlin/test/StoreTest.kt index b1072ac0..24cdff90 100644 --- a/tests/models-operation-based-with-interfaces/src/commonTest/kotlin/test/StoreTest.kt +++ b/tests/models-operation-based-with-interfaces/src/commonTest/kotlin/test/StoreTest.kt @@ -7,11 +7,11 @@ import codegen.models.fragment.HeroWithFriendsFragmentImpl import codegen.models.fragment.HumanWithIdFragment import codegen.models.fragment.HumanWithIdFragmentImpl import com.apollographql.apollo.ApolloClient -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.IdCacheKeyGenerator +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.memory.MemoryCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockServer import com.apollographql.mockserver.enqueueString @@ -22,15 +22,15 @@ import kotlin.test.assertEquals class StoreTest { private lateinit var mockServer: MockServer private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private suspend fun setUp() { - store = ApolloStore( + cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator() ) mockServer = MockServer() - apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).store(store).build() + apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() } private suspend fun tearDown() { @@ -42,7 +42,7 @@ class StoreTest { mockServer.enqueueString(testFixtureToUtf8("HeroAndFriendsWithTypename.json")) apolloClient.query(HeroAndFriendsWithTypenameQuery()).execute() - val heroWithFriendsFragment = store.readFragment( + val heroWithFriendsFragment = cacheManager.readFragment( HeroWithFriendsFragmentImpl(), CacheKey("Character:2001"), ).data @@ -56,7 +56,7 @@ class StoreTest { assertEquals(heroWithFriendsFragment.friends?.get(2)?.humanWithIdFragment?.id, "1003") assertEquals(heroWithFriendsFragment.friends?.get(2)?.humanWithIdFragment?.name, "Leia Organa") - var fragment = store.readFragment( + var fragment = cacheManager.readFragment( HumanWithIdFragmentImpl(), CacheKey("Character:1000"), ).data @@ -64,14 +64,14 @@ class StoreTest { assertEquals(fragment.id, "1000") assertEquals(fragment.name, "Luke Skywalker") - fragment = store.readFragment( + fragment = cacheManager.readFragment( HumanWithIdFragmentImpl(), CacheKey("Character:1002"), ).data assertEquals(fragment.id, "1002") assertEquals(fragment.name, "Han Solo") - fragment = store.readFragment( + fragment = cacheManager.readFragment( HumanWithIdFragmentImpl(), CacheKey("Character:1003"), ).data @@ -98,7 +98,7 @@ class StoreTest { assertEquals(response.data?.hero?.heroWithFriendsFragment?.friends?.get(2)?.humanWithIdFragment?.id, "1003") assertEquals(response.data?.hero?.heroWithFriendsFragment?.friends?.get(2)?.humanWithIdFragment?.name, "Leia Organa") - store.writeFragment( + cacheManager.writeFragment( HeroWithFriendsFragmentImpl(), CacheKey("Character:2001"), HeroWithFriendsFragment( @@ -123,7 +123,7 @@ class StoreTest { ), ) - store.writeFragment( + cacheManager.writeFragment( HumanWithIdFragmentImpl(), CacheKey("Character:1002"), HumanWithIdFragment( diff --git a/tests/models-operation-based/src/commonTest/kotlin/test/BasicTest.kt b/tests/models-operation-based/src/commonTest/kotlin/test/BasicTest.kt index d0596f1f..d814e66a 100644 --- a/tests/models-operation-based/src/commonTest/kotlin/test/BasicTest.kt +++ b/tests/models-operation-based/src/commonTest/kotlin/test/BasicTest.kt @@ -7,12 +7,12 @@ import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.api.ApolloResponse import com.apollographql.apollo.api.Optional import com.apollographql.apollo.api.Query -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.IdCacheKeyGenerator +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockServer import com.apollographql.mockserver.enqueueString @@ -25,15 +25,15 @@ import kotlin.test.assertTrue class BasicTest { private lateinit var mockServer: MockServer private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private suspend fun setUp() { - store = ApolloStore( + cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator() ) mockServer = MockServer() - apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).store(store).build() + apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() } private suspend fun tearDown() { diff --git a/tests/models-operation-based/src/commonTest/kotlin/test/StoreTest.kt b/tests/models-operation-based/src/commonTest/kotlin/test/StoreTest.kt index a2f0ade8..6f5997ef 100644 --- a/tests/models-operation-based/src/commonTest/kotlin/test/StoreTest.kt +++ b/tests/models-operation-based/src/commonTest/kotlin/test/StoreTest.kt @@ -7,11 +7,11 @@ import codegen.models.fragment.HeroWithFriendsFragmentImpl import codegen.models.fragment.HumanWithIdFragment import codegen.models.fragment.HumanWithIdFragmentImpl import com.apollographql.apollo.ApolloClient -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.IdCacheKeyGenerator +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.memory.MemoryCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockServer import com.apollographql.mockserver.enqueueString @@ -22,15 +22,15 @@ import kotlin.test.assertEquals class StoreTest { private lateinit var mockServer: MockServer private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private suspend fun setUp() { - store = ApolloStore( + cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator() ) mockServer = MockServer() - apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).store(store).build() + apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() } private suspend fun tearDown() { @@ -42,7 +42,7 @@ class StoreTest { mockServer.enqueueString(testFixtureToUtf8("HeroAndFriendsWithTypename.json")) apolloClient.query(HeroAndFriendsWithTypenameQuery()).execute() - val heroWithFriendsFragment = store.readFragment( + val heroWithFriendsFragment = cacheManager.readFragment( HeroWithFriendsFragmentImpl(), CacheKey("Character:2001"), ).data @@ -56,7 +56,7 @@ class StoreTest { assertEquals(heroWithFriendsFragment.friends?.get(2)?.humanWithIdFragment?.id, "1003") assertEquals(heroWithFriendsFragment.friends?.get(2)?.humanWithIdFragment?.name, "Leia Organa") - var fragment = store.readFragment( + var fragment = cacheManager.readFragment( HumanWithIdFragmentImpl(), CacheKey("Character:1000"), ).data @@ -64,14 +64,14 @@ class StoreTest { assertEquals(fragment.id, "1000") assertEquals(fragment.name, "Luke Skywalker") - fragment = store.readFragment( + fragment = cacheManager.readFragment( HumanWithIdFragmentImpl(), CacheKey("Character:1002"), ).data assertEquals(fragment.id, "1002") assertEquals(fragment.name, "Han Solo") - fragment = store.readFragment( + fragment = cacheManager.readFragment( HumanWithIdFragmentImpl(), CacheKey("Character:1003"), ).data @@ -98,7 +98,7 @@ class StoreTest { assertEquals(response.data?.hero?.heroWithFriendsFragment?.friends?.get(2)?.humanWithIdFragment?.id, "1003") assertEquals(response.data?.hero?.heroWithFriendsFragment?.friends?.get(2)?.humanWithIdFragment?.name, "Leia Organa") - store.writeFragment( + cacheManager.writeFragment( HeroWithFriendsFragmentImpl(), CacheKey("Character:2001"), HeroWithFriendsFragment( @@ -123,7 +123,7 @@ class StoreTest { ), ) - store.writeFragment( + cacheManager.writeFragment( HumanWithIdFragmentImpl(), CacheKey("Character:1002"), HumanWithIdFragment( diff --git a/tests/models-response-based/src/commonTest/kotlin/test/BasicTest.kt b/tests/models-response-based/src/commonTest/kotlin/test/BasicTest.kt index ed9b252f..18a02df7 100644 --- a/tests/models-response-based/src/commonTest/kotlin/test/BasicTest.kt +++ b/tests/models-response-based/src/commonTest/kotlin/test/BasicTest.kt @@ -12,12 +12,12 @@ import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.api.ApolloResponse import com.apollographql.apollo.api.Optional import com.apollographql.apollo.api.Query -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.IdCacheKeyGenerator +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockServer import com.apollographql.mockserver.enqueueString @@ -30,15 +30,15 @@ import kotlin.test.assertTrue class BasicTest { private lateinit var mockServer: MockServer private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private suspend fun setUp() { - store = ApolloStore( + cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator() ) mockServer = MockServer() - apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).store(store).build() + apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() } private suspend fun tearDown() { diff --git a/tests/models-response-based/src/commonTest/kotlin/test/StoreTest.kt b/tests/models-response-based/src/commonTest/kotlin/test/StoreTest.kt index 917b9bb3..ff444562 100644 --- a/tests/models-response-based/src/commonTest/kotlin/test/StoreTest.kt +++ b/tests/models-response-based/src/commonTest/kotlin/test/StoreTest.kt @@ -8,11 +8,11 @@ import codegen.models.fragment.HeroWithFriendsFragment.Friend.Companion.humanWit import codegen.models.fragment.HeroWithFriendsFragmentImpl import codegen.models.fragment.HumanWithIdFragmentImpl import com.apollographql.apollo.ApolloClient -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.IdCacheKeyGenerator +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.memory.MemoryCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockServer import com.apollographql.mockserver.enqueueString @@ -23,15 +23,15 @@ import kotlin.test.assertEquals class StoreTest { private lateinit var mockServer: MockServer private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private suspend fun setUp() { - store = ApolloStore( + cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator() ) mockServer = MockServer() - apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).store(store).build() + apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() } private suspend fun tearDown() { @@ -43,7 +43,7 @@ class StoreTest { mockServer.enqueueString(testFixtureToUtf8("HeroAndFriendsWithTypename.json")) apolloClient.query(HeroAndFriendsWithTypenameQuery()).execute() - val heroWithFriendsFragment = store.readFragment( + val heroWithFriendsFragment = cacheManager.readFragment( HeroWithFriendsFragmentImpl(), CacheKey("Character:2001"), ).data @@ -57,7 +57,7 @@ class StoreTest { assertEquals(heroWithFriendsFragment.friends?.get(2)?.asHuman()?.id, "1003") assertEquals(heroWithFriendsFragment.friends?.get(2)?.asHuman()?.name, "Leia Organa") - var fragment = store.readFragment( + var fragment = cacheManager.readFragment( HumanWithIdFragmentImpl(), CacheKey("Character:1000"), ).data @@ -65,14 +65,14 @@ class StoreTest { assertEquals(fragment.id, "1000") assertEquals(fragment.name, "Luke Skywalker") - fragment = store.readFragment( + fragment = cacheManager.readFragment( HumanWithIdFragmentImpl(), CacheKey("Character:1002"), ).data assertEquals(fragment.id, "1002") assertEquals(fragment.name, "Han Solo") - fragment = store.readFragment( + fragment = cacheManager.readFragment( HumanWithIdFragmentImpl(), CacheKey("Character:1003"), ).data @@ -99,7 +99,7 @@ class StoreTest { assertEquals(response.data?.hero?.heroWithFriendsFragment()?.friends?.get(2)?.humanWithIdFragment()?.id, "1003") assertEquals(response.data?.hero?.heroWithFriendsFragment()?.friends?.get(2)?.humanWithIdFragment()?.name, "Leia Organa") - store.writeFragment( + cacheManager.writeFragment( HeroWithFriendsFragmentImpl(), CacheKey("Character:2001"), HeroWithFriendsFragmentImpl.Data( @@ -120,7 +120,7 @@ class StoreTest { ), ) - store.writeFragment( + cacheManager.writeFragment( HumanWithIdFragmentImpl(), CacheKey("Character:1002"), HumanWithIdFragmentImpl.Data( diff --git a/tests/normalization-tests/src/commonTest/kotlin/com/example/NormalizationTest.kt b/tests/normalization-tests/src/commonTest/kotlin/com/example/NormalizationTest.kt index 3272c1a3..b5166c42 100644 --- a/tests/normalization-tests/src/commonTest/kotlin/com/example/NormalizationTest.kt +++ b/tests/normalization-tests/src/commonTest/kotlin/com/example/NormalizationTest.kt @@ -4,7 +4,7 @@ import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.api.CustomScalarAdapters import com.apollographql.apollo.api.json.jsonReader import com.apollographql.apollo.api.toApolloResponse -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.CacheKeyGenerator @@ -14,10 +14,10 @@ import com.apollographql.cache.normalized.api.CacheResolver import com.apollographql.cache.normalized.api.FieldPolicyCacheResolver import com.apollographql.cache.normalized.api.ResolverContext import com.apollographql.cache.normalized.api.TypePolicyCacheKeyGenerator +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.normalizedCache -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockServer import com.apollographql.mockserver.enqueueString @@ -50,7 +50,7 @@ internal object IdBasedCacheKeyResolver : CacheResolver, CacheKeyGenerator { class NormalizationTest { @Test fun issue3672() = runTest { - val store = ApolloStore( + val cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdBasedCacheKeyResolver, cacheResolver = IdBasedCacheKeyResolver @@ -61,15 +61,15 @@ class NormalizationTest { val data1 = Buffer().writeUtf8(nestedResponse).jsonReader().toApolloResponse(operation = query, customScalarAdapters = CustomScalarAdapters.Empty) .dataOrThrow() - store.writeOperation(query, data1) + cacheManager.writeOperation(query, data1) - val data2 = store.readOperation(query).data + val data2 = cacheManager.readOperation(query).data assertEquals(data2, data1) } @Test fun issue3672_2() = runTest { - val store = ApolloStore( + val cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdBasedCacheKeyResolver, cacheResolver = IdBasedCacheKeyResolver @@ -79,21 +79,21 @@ class NormalizationTest { val data1 = Buffer().writeUtf8(nestedResponse_list).jsonReader() .toApolloResponse(operation = query, customScalarAdapters = CustomScalarAdapters.Empty).dataOrThrow() - store.writeOperation(query, data1) + cacheManager.writeOperation(query, data1) - val data2 = store.readOperation(query).data + val data2 = cacheManager.readOperation(query).data assertEquals(data2, data1) } @Test fun issue2818() = runTest { - val apolloStore = ApolloStore( + val cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdBasedCacheKeyResolver, cacheResolver = IdBasedCacheKeyResolver ) - apolloStore.writeOperation( + cacheManager.writeOperation( Issue2818Query(), Issue2818Query.Data( Issue2818Query.Home( @@ -111,7 +111,7 @@ class NormalizationTest { ), ) - val data = apolloStore.readOperation(Issue2818Query()).data!! + val data = cacheManager.readOperation(Issue2818Query()).data!! assertEquals("section-name", data.home.sectionA?.name) assertEquals("section-id", data.home.sectionFragment.sectionA?.id) assertEquals("https://...", data.home.sectionFragment.sectionA?.imageUrl) @@ -148,8 +148,8 @@ class NormalizationTest { val mockserver = MockServer() val apolloClient = ApolloClient.Builder() .serverUrl(mockserver.url()) - .store( - ApolloStore( + .cacheManager( + CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator, cacheResolver = object : CacheKeyResolver() { @@ -222,8 +222,8 @@ class NormalizationTest { val mockserver = MockServer() val apolloClient = ApolloClient.Builder() .serverUrl(mockserver.url()) - .store( - ApolloStore( + .cacheManager( + CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator, cacheResolver = object : CacheResolver { @@ -295,7 +295,7 @@ class NormalizationTest { // Fetch from network apolloClient.query(GetBooksByIdsPaginatedQuery(listOf("book-1", "book-2"))).fetchPolicy(FetchPolicy.NetworkOnly).execute() - // println(NormalizedCache.prettifyDump(apolloClient.apolloStore.dump())) + // println(NormalizedCache.prettifyDump(apolloClient.cacheManager.dump())) // Fetch from the cache val fromCache1 = apolloClient.query(GetBooksByIdsPaginatedNoCursorsQuery(listOf("book-1"))).fetchPolicy(FetchPolicy.CacheOnly).execute() diff --git a/tests/normalized-cache/src/commonTest/kotlin/BasicTest.kt b/tests/normalized-cache/src/commonTest/kotlin/BasicTest.kt index 4cfc164d..a14bcab3 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/BasicTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/BasicTest.kt @@ -3,12 +3,12 @@ package test import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.api.ApolloResponse import com.apollographql.apollo.api.Query -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.IdCacheKeyGenerator +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockServer import com.apollographql.mockserver.enqueueString @@ -36,15 +36,15 @@ import kotlin.test.assertNull class BasicTest { private lateinit var mockServer: MockServer private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private suspend fun setUp() { - store = ApolloStore( + cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator() ) mockServer = MockServer() - apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).store(store).build() + apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() } private suspend fun tearDown() { diff --git a/tests/normalized-cache/src/commonTest/kotlin/CacheFlagsTest.kt b/tests/normalized-cache/src/commonTest/kotlin/CacheFlagsTest.kt index f3dc8800..c8923d9d 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/CacheFlagsTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/CacheFlagsTest.kt @@ -9,15 +9,15 @@ import com.apollographql.apollo.exception.CacheMissException import com.apollographql.apollo.network.NetworkTransport import com.apollographql.apollo.testing.QueueTestNetworkTransport import com.apollographql.apollo.testing.enqueueTestResponse -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.ApolloCacheHeaders import com.apollographql.cache.normalized.api.CacheHeaders import com.apollographql.cache.normalized.cacheHeaders +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.doNotStore import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.benasher44.uuid.uuid4 import kotlinx.coroutines.flow.Flow @@ -29,11 +29,11 @@ import kotlin.test.assertNotNull class CacheFlagsTest { private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private fun setUp() { - store = ApolloStore(MemoryCacheFactory()) - apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).store(store).build() + cacheManager = CacheManager(MemoryCacheFactory()) + apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).cacheManager(cacheManager).build() } @Test @@ -75,10 +75,10 @@ class CacheFlagsTest { val query = HeroNameQuery() val data = HeroNameQuery.Data(HeroNameQuery.Hero("R2-D2")) - store = ApolloStore(MemoryCacheFactory()) + cacheManager = CacheManager(MemoryCacheFactory()) val queueTestNetworkTransport = QueueTestNetworkTransport() apolloClient = ApolloClient.Builder() - .store(store) + .cacheManager(cacheManager) .networkTransport(object : NetworkTransport { val delegate = queueTestNetworkTransport override fun execute(request: ApolloRequest): Flow> { diff --git a/tests/normalized-cache/src/commonTest/kotlin/CacheResolverTest.kt b/tests/normalized-cache/src/commonTest/kotlin/CacheResolverTest.kt index b000da08..897b2b2f 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/CacheResolverTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/CacheResolverTest.kt @@ -1,12 +1,12 @@ package test import com.apollographql.apollo.ApolloClient -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.CacheResolver import com.apollographql.cache.normalized.api.DefaultCacheResolver import com.apollographql.cache.normalized.api.ResolverContext +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.memory.MemoryCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import normalizer.HeroNameQuery import kotlin.test.Test @@ -24,8 +24,8 @@ class CacheResolverTest { } } val apolloClient = ApolloClient.Builder().serverUrl(serverUrl = "") - .store( - ApolloStore( + .cacheManager( + CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheResolver = resolver ) diff --git a/tests/normalized-cache/src/commonTest/kotlin/FetchPolicyTest.kt b/tests/normalized-cache/src/commonTest/kotlin/FetchPolicyTest.kt index d7931b97..f2b0d8c3 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/FetchPolicyTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/FetchPolicyTest.kt @@ -18,16 +18,16 @@ import com.apollographql.apollo.exception.CacheMissException import com.apollographql.apollo.exception.JsonEncodingException import com.apollographql.apollo.interceptor.ApolloInterceptor import com.apollographql.apollo.interceptor.ApolloInterceptorChain -import com.apollographql.cache.normalized.ApolloStore import com.apollographql.cache.normalized.CacheFirstInterceptor +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.CacheOnlyInterceptor import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.CacheKey +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.isFromCache import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.refetchPolicyInterceptor -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.assertNoElement import com.apollographql.cache.normalized.testing.fieldKey import com.apollographql.cache.normalized.testing.runTest @@ -58,12 +58,12 @@ import kotlin.test.fail class FetchPolicyTest { private lateinit var mockServer: MockServer private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private suspend fun setUp() { - store = ApolloStore(MemoryCacheFactory()) + cacheManager = CacheManager(MemoryCacheFactory()) mockServer = MockServer() - apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).store(store = store).build() + apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager = cacheManager).build() } private fun tearDown() { @@ -92,7 +92,7 @@ class FetchPolicyTest { assertTrue(response.isFromCache) // Clear the store and offer a malformed response, we should get a composite error - store.clearAll() + cacheManager.clearAll() mockServer.enqueueString("malformed") apolloClient.query(query).execute().exception.let { assertIs(it) @@ -125,7 +125,7 @@ class FetchPolicyTest { assertTrue(response.isFromCache) // Clear the store and offer a malformed response, we should get a composite error - store.clearAll() + cacheManager.clearAll() mockServer.enqueueString("malformed") try { @Suppress("DEPRECATION") @@ -173,7 +173,7 @@ class FetchPolicyTest { } // Clear the store and offer a malformed response, we should get a composite error - store.clearAll() + cacheManager.clearAll() mockServer.enqueueString("malformed") @Suppress("DEPRECATION") responses = apolloClient.query(query) @@ -215,7 +215,7 @@ class FetchPolicyTest { // Network error and no cache -> we should get an error mockServer.enqueueString("malformed") - store.clearAll() + cacheManager.clearAll() call.execute().exception.let { assertIs(it) @@ -254,7 +254,7 @@ class FetchPolicyTest { // Network error and no cache -> we should get an error mockServer.enqueueString("malformed") - store.clearAll() + cacheManager.clearAll() try { @Suppress("DEPRECATION") call.executeV3() @@ -308,7 +308,7 @@ class FetchPolicyTest { // Network error and no cache -> we should get an error mockServer.enqueueString("malformed") - store.clearAll() + cacheManager.clearAll() @Suppress("DEPRECATION") responses = call.toFlowV3() responses.test { @@ -589,7 +589,7 @@ class FetchPolicyTest { /** * clear the cache and trigger the watcher again */ - store.clearAll() + cacheManager.clearAll() mockServer.enqueueString( buildJsonString { @@ -603,7 +603,7 @@ class FetchPolicyTest { ) } ) - store.publish(setOf(CacheKey.QUERY_ROOT.fieldKey("hero"))) + cacheManager.publish(setOf(CacheKey.QUERY_ROOT.fieldKey("hero"))) /** * This time the watcher should do a network request @@ -644,7 +644,7 @@ class FetchPolicyTest { assertTrue(response.isFromCache) // CacheOnly / miss - store.clearAll() + cacheManager.clearAll() response = apolloClient.query(query) .fetchPolicy(FetchPolicy.CacheOnly) .execute() @@ -660,7 +660,7 @@ class FetchPolicyTest { assertFalse(response.isFromCache) // CacheFirst / miss / miss - store.clearAll() + cacheManager.clearAll() mockServer.enqueueString("malformed") var responses = apolloClient.query(query) .fetchPolicy(FetchPolicy.CacheFirst) @@ -670,7 +670,7 @@ class FetchPolicyTest { assertFalse(responses[1].isFromCache) // NetworkFirst / miss / miss - store.clearAll() + cacheManager.clearAll() mockServer.enqueueString("malformed") responses = apolloClient.query(query) .fetchPolicy(FetchPolicy.NetworkFirst) diff --git a/tests/normalized-cache/src/commonTest/kotlin/IdCacheKeyGeneratorTest.kt b/tests/normalized-cache/src/commonTest/kotlin/IdCacheKeyGeneratorTest.kt index 31ec420e..682cdf75 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/IdCacheKeyGeneratorTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/IdCacheKeyGeneratorTest.kt @@ -3,13 +3,13 @@ package test import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.testing.QueueTestNetworkTransport import com.apollographql.apollo.testing.enqueueTestResponse -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.IdCacheKeyGenerator import com.apollographql.cache.normalized.api.IdCacheKeyResolver +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import main.GetUser2Query import main.GetUserByIdQuery @@ -21,12 +21,12 @@ import kotlin.test.assertEquals class IdCacheKeyGeneratorTest { @Test fun defaultValues() = runTest { - val store = ApolloStore( + val cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheKeyResolver(), ) - val apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).store(store).build() + val apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).cacheManager(cacheManager).build() val query = GetUser2Query("42") apolloClient.enqueueTestResponse(query, GetUser2Query.Data(GetUser2Query.User2(id = "42", name = "John", email = "a@a.com"))) apolloClient.query(query).fetchPolicy(FetchPolicy.NetworkOnly).execute() @@ -37,12 +37,12 @@ class IdCacheKeyGeneratorTest { @Test fun customIdField() = runTest { - val store = ApolloStore( + val cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator("userId"), cacheResolver = IdCacheKeyResolver(idFields = listOf("userId")), ) - val apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).store(store).build() + val apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).cacheManager(cacheManager).build() val query = GetUserByIdQuery("42") apolloClient.enqueueTestResponse(query, GetUserByIdQuery.Data(GetUserByIdQuery.UserById(userId = "42", name = "John", email = "a@a.com"))) apolloClient.query(query).fetchPolicy(FetchPolicy.NetworkOnly).execute() @@ -53,12 +53,12 @@ class IdCacheKeyGeneratorTest { @Test fun lists() = runTest { - val store = ApolloStore( + val cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator("id"), cacheResolver = IdCacheKeyResolver(idListFields = listOf("ids", "userIds")), ) - val apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).store(store).build() + val apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).cacheManager(cacheManager).build() val query1 = GetUsersQuery(listOf("42", "43")) apolloClient.enqueueTestResponse( query1, diff --git a/tests/normalized-cache/src/commonTest/kotlin/JsonScalarTest.kt b/tests/normalized-cache/src/commonTest/kotlin/JsonScalarTest.kt index f4c85cf3..e1a832c9 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/JsonScalarTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/JsonScalarTest.kt @@ -2,11 +2,11 @@ package test import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.api.AnyAdapter -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockServer import com.apollographql.mockserver.enqueueString @@ -19,13 +19,13 @@ import kotlin.test.assertFalse class JsonScalarTest { private lateinit var mockServer: MockServer private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private suspend fun setUp() { - store = ApolloStore(MemoryCacheFactory()) + cacheManager = CacheManager(MemoryCacheFactory()) mockServer = MockServer() apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .addCustomScalarAdapter(Json.type, AnyAdapter) .build() } diff --git a/tests/normalized-cache/src/commonTest/kotlin/OptimisticCacheTest.kt b/tests/normalized-cache/src/commonTest/kotlin/OptimisticCacheTest.kt index d42656b3..41833cd7 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/OptimisticCacheTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/OptimisticCacheTest.kt @@ -2,15 +2,15 @@ package test import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.api.Optional -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.IdCacheKeyGenerator +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.optimisticUpdates import com.apollographql.cache.normalized.refetchPolicy -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.apollographql.cache.normalized.watch import com.apollographql.mockserver.MockServer @@ -34,12 +34,12 @@ import kotlin.test.assertEquals class OptimisticCacheTest { private lateinit var mockServer: MockServer private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private suspend fun setUp() { - store = ApolloStore(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator()) + cacheManager = CacheManager(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator()) mockServer = MockServer() - apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).store(store).build() + apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() } private suspend fun tearDown() { @@ -70,12 +70,12 @@ class OptimisticCacheTest { ) ) ) - store.writeOptimisticUpdates( + cacheManager.writeOptimisticUpdates( operation = query, data = data, mutationId = mutationId, ).also { - store.publish(it) + cacheManager.publish(it) } var response = apolloClient.query(query).fetchPolicy(FetchPolicy.CacheOnly).execute() @@ -85,7 +85,7 @@ class OptimisticCacheTest { assertEquals("SuperMan", response.data?.hero?.friends?.get(0)?.name) assertEquals("Batman", response.data?.hero?.friends?.get(1)?.name) - store.rollbackOptimisticUpdates(mutationId) + cacheManager.rollbackOptimisticUpdates(mutationId) response = apolloClient.query(query).fetchPolicy(FetchPolicy.CacheOnly).execute() assertEquals("R2-D2", response.data?.hero?.name) @@ -118,13 +118,13 @@ class OptimisticCacheTest { ) ) ) - store.writeOptimisticUpdates( + cacheManager.writeOptimisticUpdates( HeroAndFriendsNamesFragmentImpl(), mutationId = mutationId, cacheKey = CacheKey("""hero({"episode":"JEDI"})"""), data = data, ).also { - store.publish(it) + cacheManager.publish(it) } var response = apolloClient.query(query).fetchPolicy(FetchPolicy.CacheOnly).execute() @@ -134,7 +134,7 @@ class OptimisticCacheTest { assertEquals("SuperMan", response.data?.hero?.friends?.get(0)?.name) assertEquals("Batman", response.data?.hero?.friends?.get(1)?.name) - store.rollbackOptimisticUpdates(mutationId) + cacheManager.rollbackOptimisticUpdates(mutationId) response = apolloClient.query(query).fetchPolicy(FetchPolicy.CacheOnly).execute() assertEquals("R2-D2", response.data?.hero?.name) @@ -173,12 +173,12 @@ class OptimisticCacheTest { ) ) ) - store.writeOptimisticUpdates( + cacheManager.writeOptimisticUpdates( operation = query1, data = data1, mutationId = mutationId1, ).also { - store.publish(it) + cacheManager.publish(it) } // check if query1 see optimistic updates @@ -204,12 +204,12 @@ class OptimisticCacheTest { "Beast" ) ) - store.writeOptimisticUpdates( + cacheManager.writeOptimisticUpdates( operation = query2, data = data2, mutationId = mutationId2, ).also { - store.publish(it) + cacheManager.publish(it) } // check if query1 sees data2 @@ -228,7 +228,7 @@ class OptimisticCacheTest { assertEquals("Beast", response2.data?.hero?.name) // rollback data1 - store.rollbackOptimisticUpdates(mutationId1) + cacheManager.rollbackOptimisticUpdates(mutationId1) // check if query2 sees the rollback response1 = apolloClient.query(query1).fetchPolicy(FetchPolicy.CacheOnly).execute() @@ -248,7 +248,7 @@ class OptimisticCacheTest { assertEquals("Beast", response2.data?.hero?.name) // rollback query2 optimistic updates - store.rollbackOptimisticUpdates(mutationId2) + cacheManager.rollbackOptimisticUpdates(mutationId2) // check if query2 see the latest optimistic updates response2 = apolloClient.query(query2).fetchPolicy(FetchPolicy.CacheOnly).execute() @@ -375,24 +375,24 @@ class OptimisticCacheTest { ) ) ) - store.writeOptimisticUpdates( + cacheManager.writeOptimisticUpdates( operation = query1, data = data1, mutationId = mutationId1, ).also { - store.publish(it) + cacheManager.publish(it) } val data2 = HeroNameWithIdQuery.Data(HeroNameWithIdQuery.Hero( "1000", "Spiderman" ) ) - store.writeOptimisticUpdates( + cacheManager.writeOptimisticUpdates( operation = query2, data = data2, mutationId = mutationId2, ).also { - store.publish(it) + cacheManager.publish(it) } // check if query1 see optimistic updates @@ -412,7 +412,7 @@ class OptimisticCacheTest { assertEquals("Spiderman", response2.data?.hero?.name) // rollback query2 optimistic updates - store.rollbackOptimisticUpdates(mutationId2) + cacheManager.rollbackOptimisticUpdates(mutationId2) // check if query1 see the latest optimistic updates response1 = apolloClient.query(query1).fetchPolicy(FetchPolicy.CacheOnly).execute() @@ -431,7 +431,7 @@ class OptimisticCacheTest { assertEquals("Robocop", response2.data?.hero?.name) // rollback query1 optimistic updates - store.rollbackOptimisticUpdates(mutationId1) + cacheManager.rollbackOptimisticUpdates(mutationId1) // check if query1 see the latest non-optimistic updates response1 = apolloClient.query(query1).fetchPolicy(FetchPolicy.CacheOnly).execute() diff --git a/tests/normalized-cache/src/commonTest/kotlin/OtherCacheTest.kt b/tests/normalized-cache/src/commonTest/kotlin/OtherCacheTest.kt index 1b2b7d0b..475076f2 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/OtherCacheTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/OtherCacheTest.kt @@ -3,14 +3,14 @@ package test import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.api.composeJsonResponse import com.apollographql.apollo.exception.CacheMissException -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.IdCacheKeyGenerator import com.apollographql.cache.normalized.api.IdCacheKeyResolver +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.keyToString import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockServer @@ -34,12 +34,12 @@ import kotlin.test.assertTrue class OtherCacheTest { private lateinit var mockServer: MockServer private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private suspend fun setUp() { - store = ApolloStore(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheKeyResolver()) + cacheManager = CacheManager(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheKeyResolver()) mockServer = MockServer() - apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).store(store).build() + apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() } private suspend fun tearDown() { @@ -186,7 +186,7 @@ class OtherCacheTest { mockServer.enqueueString(mutation.composeJsonResponse(data)) apolloClient.mutation(mutation).execute() - val storeData = store.readOperation(mutation).data + val storeData = cacheManager.readOperation(mutation).data assertEquals(data, storeData) } } diff --git a/tests/normalized-cache/src/commonTest/kotlin/StoreTest.kt b/tests/normalized-cache/src/commonTest/kotlin/StoreTest.kt index 1d2e8eb7..cbce9527 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/StoreTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/StoreTest.kt @@ -6,16 +6,16 @@ import com.apollographql.apollo.api.StringAdapter import com.apollographql.apollo.exception.CacheMissException import com.apollographql.apollo.testing.QueueTestNetworkTransport import com.apollographql.apollo.testing.enqueueTestResponse -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.IdCacheKeyGenerator import com.apollographql.cache.normalized.api.IdCacheKeyResolver +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.isFromCache import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.normalizedCache -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import normalizer.CharacterNameByIdQuery import normalizer.ColorQuery @@ -33,11 +33,11 @@ import kotlin.test.assertIs */ class StoreTest { private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private fun setUp() { - store = ApolloStore(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheKeyResolver()) - apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).store(store).build() + cacheManager = CacheManager(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheKeyResolver()) + apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).cacheManager(cacheManager).build() } @Test @@ -46,7 +46,7 @@ class StoreTest { assertFriendIsCached("1002", "Han Solo") // remove the root query object - var removed = store.remove(CacheKey("Character:2001")) + var removed = cacheManager.remove(CacheKey("Character:2001")) assertEquals(true, removed) // Trying to get the full response should fail @@ -57,7 +57,7 @@ class StoreTest { assertFriendIsCached("1002", "Han Solo") // remove a single object from the list - removed = store.remove(CacheKey("Character:1002")) + removed = cacheManager.remove(CacheKey("Character:1002")) assertEquals(true, removed) // Trying to get the full response should fail @@ -79,7 +79,7 @@ class StoreTest { assertFriendIsCached("1003", "Leia Organa") // Now remove multiple keys - val removed = store.remove(listOf(CacheKey("Character:1002"), CacheKey("Character:1000"))) + val removed = cacheManager.remove(listOf(CacheKey("Character:1002"), CacheKey("Character:1000"))) assertEquals(2, removed) @@ -100,7 +100,7 @@ class StoreTest { assertFriendIsCached("1003", "Leia Organa") // test remove root query object - val removed = store.remove(CacheKey("Character:2001"), true) + val removed = cacheManager.remove(CacheKey("Character:2001"), true) assertEquals(true, removed) // Nothing should be cached anymore @@ -116,7 +116,7 @@ class StoreTest { // put everything in the cache storeAllFriends() - store.accessCache { + cacheManager.accessCache { it.remove(CacheKey("Character:1000"), false) } assertFriendIsNotCached("1000") @@ -127,8 +127,8 @@ class StoreTest { storeAllFriends() assertFriendIsCached("1000", "Luke Skywalker") - val newStore = ApolloStore(MemoryCacheFactory()) - val newClient = apolloClient.newBuilder().store(newStore).build() + val newCacheManager = CacheManager(MemoryCacheFactory()) + val newClient = apolloClient.newBuilder().cacheManager(newCacheManager).build() assertFriendIsNotCached("1000", newClient) } diff --git a/tests/normalized-cache/src/commonTest/kotlin/WatcherErrorHandlingTest.kt b/tests/normalized-cache/src/commonTest/kotlin/WatcherErrorHandlingTest.kt index 20165e5a..7658a6fa 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/WatcherErrorHandlingTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/WatcherErrorHandlingTest.kt @@ -5,13 +5,13 @@ import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.api.ApolloResponse import com.apollographql.apollo.exception.ApolloHttpException import com.apollographql.apollo.exception.CacheMissException -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.IdCacheKeyGenerator +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.refetchPolicy -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.apollographql.cache.normalized.watch import com.apollographql.mockserver.MockServer @@ -31,12 +31,12 @@ import kotlin.test.assertNull class WatcherErrorHandlingTest { private lateinit var mockServer: MockServer private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private suspend fun setUp() { - store = ApolloStore(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator()) + cacheManager = CacheManager(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator()) mockServer = MockServer() - apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).store(store).build() + apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() } private fun tearDown() { diff --git a/tests/normalized-cache/src/commonTest/kotlin/WatcherTest.kt b/tests/normalized-cache/src/commonTest/kotlin/WatcherTest.kt index aa93c918..bed32232 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/WatcherTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/WatcherTest.kt @@ -9,14 +9,14 @@ import com.apollographql.apollo.exception.CacheMissException import com.apollographql.apollo.testing.QueueTestNetworkTransport import com.apollographql.apollo.testing.enqueueTestNetworkError import com.apollographql.apollo.testing.enqueueTestResponse -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.IdCacheKeyGenerator +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.normalizedCache import com.apollographql.cache.normalized.refetchPolicy -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.apollographql.cache.normalized.watch import com.apollographql.mockserver.MockResponse @@ -47,11 +47,11 @@ import kotlin.time.Duration.Companion.minutes class WatcherTest { private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private fun setUp() { - store = ApolloStore(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator()) - apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).store(store).build() + cacheManager = CacheManager(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator()) + apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).cacheManager(cacheManager).build() } private val episodeHeroNameData = EpisodeHeroNameQuery.Data(EpisodeHeroNameQuery.Hero("R2-D2")) @@ -177,8 +177,8 @@ class WatcherTest { ) ) - store.writeOperation(operation, data).also { - store.publish(it) + cacheManager.writeOperation(operation, data).also { + cacheManager.publish(it) } assertEquals(channel.awaitElement()?.hero?.name, "Artoo") @@ -657,8 +657,8 @@ class WatcherTest { assertEquals("R2-D2", awaitItem().data?.hero?.name) // Clear the cache - store.clearAll() - store.publish(ApolloStore.ALL_KEYS) + cacheManager.clearAll() + cacheManager.publish(CacheManager.ALL_KEYS) assertIs(awaitItem().exception) } } diff --git a/tests/normalized-cache/src/commonTest/kotlin/circular/CircularCacheReadTest.kt b/tests/normalized-cache/src/commonTest/kotlin/circular/CircularCacheReadTest.kt index 0b01fcb7..cb3b3a2a 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/circular/CircularCacheReadTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/circular/CircularCacheReadTest.kt @@ -1,7 +1,7 @@ package test.circular import circular.GetUserQuery -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.testing.runTest import kotlin.test.Test @@ -10,7 +10,7 @@ import kotlin.test.assertEquals class CircularCacheReadTest { @Test fun circularReferenceDoesNotStackOverflow() = runTest { - val store = ApolloStore(MemoryCacheFactory()) + val cacheManager = CacheManager(MemoryCacheFactory()) val operation = GetUserQuery() @@ -28,8 +28,8 @@ class CircularCacheReadTest { ) ) - store.writeOperation(operation, data) - val result = store.readOperation(operation).data!! + cacheManager.writeOperation(operation, data) + val result = cacheManager.readOperation(operation).data!! assertEquals("42", result.user.friend.id) } } diff --git a/tests/normalized-cache/src/commonTest/kotlin/declarativecache/DeclarativeCacheTest.kt b/tests/normalized-cache/src/commonTest/kotlin/declarativecache/DeclarativeCacheTest.kt index bc2b4308..97fd64f7 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/declarativecache/DeclarativeCacheTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/declarativecache/DeclarativeCacheTest.kt @@ -1,6 +1,6 @@ package test.declarativecache -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.CacheResolver import com.apollographql.cache.normalized.api.FieldPolicyCacheResolver @@ -22,54 +22,54 @@ class DeclarativeCacheTest { @Test fun typePolicyIsWorking() = runTest { - val store = ApolloStore(MemoryCacheFactory()) + val cacheManager = CacheManager(MemoryCacheFactory()) // Write a book at the "promo" path val promoOperation = GetPromoBookQuery() val promoData = GetPromoBookQuery.Data(GetPromoBookQuery.PromoBook("Promo", "42", "Book")) - store.writeOperation(promoOperation, promoData) + cacheManager.writeOperation(promoOperation, promoData) // Overwrite the book title through the "other" path val otherOperation = GetOtherBookQuery() val otherData = GetOtherBookQuery.Data(GetOtherBookQuery.OtherBook("42", "Other", "Book")) - store.writeOperation(otherOperation, otherData) + cacheManager.writeOperation(otherOperation, otherData) // Get the "promo" book again, the title must be updated - val data = store.readOperation(promoOperation).data!! + val data = cacheManager.readOperation(promoOperation).data!! assertEquals("Other", data.promoBook?.title) } @Test fun fallbackIdIsWorking() = runTest { - val store = ApolloStore(MemoryCacheFactory()) + val cacheManager = CacheManager(MemoryCacheFactory()) // Write a library at the "promo" path val promoOperation = GetPromoLibraryQuery() val promoData = GetPromoLibraryQuery.Data(GetPromoLibraryQuery.PromoLibrary("PromoAddress", "3", "Library")) - store.writeOperation(promoOperation, promoData) + cacheManager.writeOperation(promoOperation, promoData) // Overwrite the library address through the "other" path val otherOperation = GetOtherLibraryQuery() val otherData = GetOtherLibraryQuery.Data(GetOtherLibraryQuery.OtherLibrary("3", "OtherAddress", "Library")) - store.writeOperation(otherOperation, otherData) + cacheManager.writeOperation(otherOperation, otherData) // Get the "promo" library again, the address must be updated - val data = store.readOperation(promoOperation).data!! + val data = cacheManager.readOperation(promoOperation).data!! assertEquals("OtherAddress", data.promoLibrary?.address) } @Test fun fieldPolicyIsWorking() = runTest { - val store = ApolloStore(MemoryCacheFactory()) + val cacheManager = CacheManager(MemoryCacheFactory()) val bookQuery1 = GetPromoBookQuery() val bookData1 = GetPromoBookQuery.Data(GetPromoBookQuery.PromoBook("Promo", "42", "Book")) - store.writeOperation(bookQuery1, bookData1) + cacheManager.writeOperation(bookQuery1, bookData1) val bookQuery2 = GetBookQuery("42") - val bookData2 = store.readOperation(bookQuery2).data!! + val bookData2 = cacheManager.readOperation(bookQuery2).data!! assertEquals("Promo", bookData2.book?.title) @@ -82,10 +82,10 @@ class DeclarativeCacheTest { ) ) - store.writeOperation(authorQuery1, authorData1) + cacheManager.writeOperation(authorQuery1, authorData1) val authorQuery2 = GetAuthorQuery("Pierre", "Bordage") - val authorData2 = store.readOperation(authorQuery2).data!! + val authorData2 = cacheManager.readOperation(authorQuery2).data!! assertEquals("Pierre", authorData2.author?.firstName) assertEquals("Bordage", authorData2.author?.lastName) @@ -107,22 +107,22 @@ class DeclarativeCacheTest { return FieldPolicyCacheResolver.resolveField(context) } } - val store = ApolloStore(MemoryCacheFactory(), cacheResolver = cacheResolver) + val cacheManager = CacheManager(MemoryCacheFactory(), cacheResolver = cacheResolver) val promoOperation = GetPromoBookQuery() - store.writeOperation(promoOperation, GetPromoBookQuery.Data(GetPromoBookQuery.PromoBook("Title1", "1", "Book"))) - store.writeOperation(promoOperation, GetPromoBookQuery.Data(GetPromoBookQuery.PromoBook("Title2", "2", "Book"))) - store.writeOperation(promoOperation, GetPromoBookQuery.Data(GetPromoBookQuery.PromoBook("Title3", "3", "Book"))) - store.writeOperation(promoOperation, GetPromoBookQuery.Data(GetPromoBookQuery.PromoBook("Title4", "4", "Book"))) + cacheManager.writeOperation(promoOperation, GetPromoBookQuery.Data(GetPromoBookQuery.PromoBook("Title1", "1", "Book"))) + cacheManager.writeOperation(promoOperation, GetPromoBookQuery.Data(GetPromoBookQuery.PromoBook("Title2", "2", "Book"))) + cacheManager.writeOperation(promoOperation, GetPromoBookQuery.Data(GetPromoBookQuery.PromoBook("Title3", "3", "Book"))) + cacheManager.writeOperation(promoOperation, GetPromoBookQuery.Data(GetPromoBookQuery.PromoBook("Title4", "4", "Book"))) var operation = GetBooksQuery(listOf("4", "1")) - var data = store.readOperation(operation).data!! + var data = cacheManager.readOperation(operation).data!! assertEquals("Title4", data.books.get(0).title) assertEquals("Title1", data.books.get(1).title) operation = GetBooksQuery(listOf("3")) - data = store.readOperation(operation).data!! + data = cacheManager.readOperation(operation).data!! assertEquals("Title3", data.books.get(0).title) } diff --git a/tests/normalized-cache/src/commonTest/kotlin/fragmentnormalizer/FragmentNormalizerTest.kt b/tests/normalized-cache/src/commonTest/kotlin/fragmentnormalizer/FragmentNormalizerTest.kt index 43e21e81..8f8e6ba4 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/fragmentnormalizer/FragmentNormalizerTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/fragmentnormalizer/FragmentNormalizerTest.kt @@ -3,10 +3,10 @@ package test.fragmentnormalizer import com.apollographql.apollo.ApolloClient import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.IdCacheKeyGenerator +import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.internal.normalized import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.normalizedCache -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.append import com.apollographql.cache.normalized.testing.runTest import fragmentnormalizer.fragment.ConversationFragment @@ -61,19 +61,19 @@ class FragmentNormalizerTest { ), true ) - apolloClient.store.writeFragment( + apolloClient.apolloStore.writeFragment( ConversationFragmentImpl(), CacheKey(fragment1.id), fragment1Read, ) - apolloClient.store.writeFragment( + apolloClient.apolloStore.writeFragment( ConversationFragmentImpl(), CacheKey(fragment2.id), fragment2Read, ) - fragment1 = apolloClient.store.readFragment( + fragment1 = apolloClient.apolloStore.readFragment( ConversationFragmentImpl(), CacheKey(fragment1.id), ).data diff --git a/tests/normalized-cache/src/concurrentTest/kotlin/MemoryCacheOnlyTest.kt b/tests/normalized-cache/src/concurrentTest/kotlin/MemoryCacheOnlyTest.kt index a7b10204..b9b700af 100644 --- a/tests/normalized-cache/src/concurrentTest/kotlin/MemoryCacheOnlyTest.kt +++ b/tests/normalized-cache/src/concurrentTest/kotlin/MemoryCacheOnlyTest.kt @@ -2,17 +2,17 @@ import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.exception.CacheMissException import com.apollographql.apollo.testing.QueueTestNetworkTransport import com.apollographql.apollo.testing.enqueueTestResponse -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.Record +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCache import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.memoryCacheOnly import com.apollographql.cache.normalized.sql.SqlNormalizedCache import com.apollographql.cache.normalized.sql.SqlNormalizedCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import main.GetUserQuery import kotlin.reflect.KClass @@ -23,24 +23,24 @@ import kotlin.test.assertIs class MemoryCacheOnlyTest { @Test fun memoryCacheOnlyDoesNotStoreInSqlCache() = runTest { - val store = ApolloStore(MemoryCacheFactory().chain(SqlNormalizedCacheFactory())).also { it.clearAll() } - val apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).store(store).build() + val cacheManager = CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory())).also { it.clearAll() } + val apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).cacheManager(cacheManager).build() val query = GetUserQuery() apolloClient.enqueueTestResponse(query, GetUserQuery.Data(GetUserQuery.User("John", "a@a.com"))) apolloClient.query(query).memoryCacheOnly(true).execute() - val dump: Map, Map> = store.dump() + val dump: Map, Map> = cacheManager.dump() assertEquals(2, dump[MemoryCache::class]!!.size) assertEquals(0, dump[SqlNormalizedCache::class]!!.size) } @Test fun memoryCacheOnlyDoesNotReadFromSqlCache() = runTest { - val store = ApolloStore(MemoryCacheFactory().chain(SqlNormalizedCacheFactory())).also { it.clearAll() } + val cacheManager = CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory())).also { it.clearAll() } val query = GetUserQuery() - store.writeOperation(query, GetUserQuery.Data(GetUserQuery.User("John", "a@a.com"))) + cacheManager.writeOperation(query, GetUserQuery.Data(GetUserQuery.User("John", "a@a.com"))) - val store2 = ApolloStore(MemoryCacheFactory().chain(SqlNormalizedCacheFactory())) - val apolloClient = ApolloClient.Builder().serverUrl("unused").store(store2).build() + val store2 = CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory())) + val apolloClient = ApolloClient.Builder().serverUrl("unused").cacheManager(store2).build() // The record in is in the SQL cache, but we request not to access it assertIs( apolloClient.query(query).fetchPolicy(FetchPolicy.CacheOnly).memoryCacheOnly(true).execute().exception diff --git a/tests/normalized-cache/src/jvmTest/kotlin/CacheConcurrencyTest.kt b/tests/normalized-cache/src/jvmTest/kotlin/CacheConcurrencyTest.kt index b4df802e..f7aafbba 100644 --- a/tests/normalized-cache/src/jvmTest/kotlin/CacheConcurrencyTest.kt +++ b/tests/normalized-cache/src/jvmTest/kotlin/CacheConcurrencyTest.kt @@ -3,9 +3,9 @@ package test import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.testing.QueueTestNetworkTransport import com.apollographql.apollo.testing.enqueueTestResponse -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.memory.MemoryCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.joinAll @@ -18,13 +18,13 @@ class CacheConcurrencyTest { @Test fun storeConcurrently() = runTest { - val store = ApolloStore(MemoryCacheFactory(maxSizeBytes = 1000)) + val cacheManager = CacheManager(MemoryCacheFactory(maxSizeBytes = 1000)) val executor = Executors.newFixedThreadPool(10) val dispatcher = executor.asCoroutineDispatcher() val apolloClient = ApolloClient.Builder() .networkTransport(QueueTestNetworkTransport()) - .store(store) + .cacheManager(cacheManager) .dispatcher(dispatcher) .build() @@ -39,6 +39,6 @@ class CacheConcurrencyTest { }.joinAll() executor.shutdown() - println(store.dump().values.toList()[1].map { (k, v) -> "$k -> ${v.fields}" }.joinToString("\n")) + println(cacheManager.dump().values.toList()[1].map { (k, v) -> "$k -> ${v.fields}" }.joinToString("\n")) } } diff --git a/tests/normalized-cache/src/jvmTest/kotlin/WriteToCacheAsynchronouslyTest.kt b/tests/normalized-cache/src/jvmTest/kotlin/WriteToCacheAsynchronouslyTest.kt index 8f6eccb4..250a8330 100644 --- a/tests/normalized-cache/src/jvmTest/kotlin/WriteToCacheAsynchronouslyTest.kt +++ b/tests/normalized-cache/src/jvmTest/kotlin/WriteToCacheAsynchronouslyTest.kt @@ -1,11 +1,11 @@ package test import com.apollographql.apollo.ApolloClient -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.CacheHeaders import com.apollographql.cache.normalized.api.CacheKey +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.memory.MemoryCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import com.apollographql.cache.normalized.writeToCacheAsynchronously import com.apollographql.mockserver.MockServer @@ -26,16 +26,16 @@ import kotlin.test.assertNull class WriteToCacheAsynchronouslyTest { private lateinit var mockServer: MockServer private lateinit var apolloClient: ApolloClient - private lateinit var store: ApolloStore + private lateinit var cacheManager: CacheManager private var dispatcher = Executors.newSingleThreadExecutor().asCoroutineDispatcher() private suspend fun setUp() { - store = ApolloStore(MemoryCacheFactory()) + cacheManager = CacheManager(MemoryCacheFactory()) mockServer = MockServer() apolloClient = ApolloClient.Builder() .serverUrl(mockServer.url()) .dispatcher(dispatcher) - .store(store) + .cacheManager(cacheManager) .build() } @@ -58,7 +58,7 @@ class WriteToCacheAsynchronouslyTest { .execute() - val record = store.accessCache { it.loadRecord(QUERY_ROOT_KEY, CacheHeaders.NONE) } + val record = cacheManager.accessCache { it.loadRecord(QUERY_ROOT_KEY, CacheHeaders.NONE) } assertNull(record) } } @@ -76,7 +76,7 @@ class WriteToCacheAsynchronouslyTest { .writeToCacheAsynchronously(false) .execute() - val record = store.accessCache { it.loadRecord(QUERY_ROOT_KEY, CacheHeaders.NONE) } + val record = cacheManager.accessCache { it.loadRecord(QUERY_ROOT_KEY, CacheHeaders.NONE) } assertNotNull(record) } } diff --git a/tests/pagination/src/commonTest/kotlin/ConnectionPaginationTest.kt b/tests/pagination/src/commonTest/kotlin/ConnectionPaginationTest.kt index e42d466f..d87fc127 100644 --- a/tests/pagination/src/commonTest/kotlin/ConnectionPaginationTest.kt +++ b/tests/pagination/src/commonTest/kotlin/ConnectionPaginationTest.kt @@ -2,7 +2,7 @@ package pagination import com.apollographql.apollo.api.Error import com.apollographql.apollo.api.Optional -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.ConnectionMetadataGenerator import com.apollographql.cache.normalized.api.ConnectionRecordMerger import com.apollographql.cache.normalized.api.FieldPolicyCacheResolver @@ -37,14 +37,14 @@ class ConnectionPaginationTest { } private fun test(cacheFactory: NormalizedCacheFactory) = runTest { - val apolloStore = ApolloStore( + val cacheManager = CacheManager( normalizedCacheFactory = cacheFactory, cacheKeyGenerator = TypePolicyCacheKeyGenerator, metadataGenerator = ConnectionMetadataGenerator(Pagination.connectionTypes), cacheResolver = FieldPolicyCacheResolver, recordMerger = ConnectionRecordMerger ) - apolloStore.clearAll() + cacheManager.clearAll() // First page val query1 = UsersQuery(first = Optional.Present(2)) @@ -70,10 +70,10 @@ class ConnectionPaginationTest { ) } } - apolloStore.writeOperation(query1, data1) - var dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query1, data1) + var dataFromStore = cacheManager.readOperation(query1).data assertEquals(data1, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page after val query2 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx43")) @@ -99,8 +99,8 @@ class ConnectionPaginationTest { ) } } - apolloStore.writeOperation(query2, data2) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query2, data2) + dataFromStore = cacheManager.readOperation(query1).data var expectedData = UsersQuery.Data { users = buildUserConnection { pageInfo = buildPageInfo { @@ -136,7 +136,7 @@ class ConnectionPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page after val query3 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx45")) @@ -162,8 +162,8 @@ class ConnectionPaginationTest { ) } } - apolloStore.writeOperation(query3, data3) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query3, data3) + dataFromStore = cacheManager.readOperation(query1).data expectedData = UsersQuery.Data { users = buildUserConnection { pageInfo = buildPageInfo { @@ -211,7 +211,7 @@ class ConnectionPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page before val query4 = UsersQuery(last = Optional.Present(2), before = Optional.Present("xx42")) @@ -237,8 +237,8 @@ class ConnectionPaginationTest { ) } } - apolloStore.writeOperation(query4, data4) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query4, data4) + dataFromStore = cacheManager.readOperation(query1).data expectedData = UsersQuery.Data { users = buildUserConnection { pageInfo = buildPageInfo { @@ -298,7 +298,7 @@ class ConnectionPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Non-contiguous page (should reset) val query5 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx50")) @@ -324,10 +324,10 @@ class ConnectionPaginationTest { ) } } - apolloStore.writeOperation(query5, data5) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query5, data5) + dataFromStore = cacheManager.readOperation(query1).data assertEquals(data5, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Empty page (should keep previous result) val query6 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx51")) @@ -340,10 +340,10 @@ class ConnectionPaginationTest { edges = emptyList() } } - apolloStore.writeOperation(query6, data6) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query6, data6) + dataFromStore = cacheManager.readOperation(query1).data assertEquals(data5, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) } @Test @@ -362,21 +362,21 @@ class ConnectionPaginationTest { } private fun errorTest(cacheFactory: NormalizedCacheFactory) = runTest { - val apolloStore = ApolloStore( + val cacheManager = CacheManager( normalizedCacheFactory = cacheFactory, cacheKeyGenerator = TypePolicyCacheKeyGenerator, metadataGenerator = ConnectionMetadataGenerator(Pagination.connectionTypes), cacheResolver = FieldPolicyCacheResolver, recordMerger = ConnectionRecordMerger ) - apolloStore.clearAll() + cacheManager.clearAll() val query = UsersQuery(first = Optional.Present(2)) - apolloStore.writeOperation( + cacheManager.writeOperation( operation = query, data = UsersQuery.Data { users = null }, errors = listOf(Error.Builder("An error occurred.").path(listOf("users")).build()) ) - val responseFromStore = apolloStore.readOperation(query) + val responseFromStore = cacheManager.readOperation(query) assertEquals(UsersQuery.Data { users = null }, responseFromStore.data) assertEquals(1, responseFromStore.errors?.size) assertEquals("An error occurred.", responseFromStore.errors?.firstOrNull()?.message) diff --git a/tests/pagination/src/commonTest/kotlin/ConnectionProgrammaticPaginationTest.kt b/tests/pagination/src/commonTest/kotlin/ConnectionProgrammaticPaginationTest.kt index 65511788..45ce8825 100644 --- a/tests/pagination/src/commonTest/kotlin/ConnectionProgrammaticPaginationTest.kt +++ b/tests/pagination/src/commonTest/kotlin/ConnectionProgrammaticPaginationTest.kt @@ -1,7 +1,7 @@ package pagination import com.apollographql.apollo.api.Optional -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.ConnectionEmbeddedFieldsProvider import com.apollographql.cache.normalized.api.ConnectionFieldKeyGenerator import com.apollographql.cache.normalized.api.ConnectionMetadataGenerator @@ -41,7 +41,7 @@ class ConnectionProgrammaticPaginationTest { private fun test(cacheFactory: NormalizedCacheFactory) = runTest { val connectionTypes = setOf(UserConnection.type.name) val connectionFields = mapOf(Query.type.name to listOf("users")) - val apolloStore = ApolloStore( + val cacheManager = CacheManager( normalizedCacheFactory = cacheFactory, cacheKeyGenerator = TypePolicyCacheKeyGenerator, metadataGenerator = ConnectionMetadataGenerator(connectionTypes), @@ -53,7 +53,7 @@ class ConnectionProgrammaticPaginationTest { connectionFields = connectionFields ), ) - apolloStore.clearAll() + cacheManager.clearAll() // First page val query1 = UsersQuery(first = Optional.Present(2)) @@ -79,10 +79,10 @@ class ConnectionProgrammaticPaginationTest { ) } } - apolloStore.writeOperation(query1, data1) - var dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query1, data1) + var dataFromStore = cacheManager.readOperation(query1).data assertEquals(data1, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page after val query2 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx43")) @@ -108,8 +108,8 @@ class ConnectionProgrammaticPaginationTest { ) } } - apolloStore.writeOperation(query2, data2) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query2, data2) + dataFromStore = cacheManager.readOperation(query1).data var expectedData = UsersQuery.Data { users = buildUserConnection { pageInfo = buildPageInfo { @@ -145,7 +145,7 @@ class ConnectionProgrammaticPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page after val query3 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx45")) @@ -171,8 +171,8 @@ class ConnectionProgrammaticPaginationTest { ) } } - apolloStore.writeOperation(query3, data3) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query3, data3) + dataFromStore = cacheManager.readOperation(query1).data expectedData = UsersQuery.Data { users = buildUserConnection { pageInfo = buildPageInfo { @@ -220,7 +220,7 @@ class ConnectionProgrammaticPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page before val query4 = UsersQuery(last = Optional.Present(2), before = Optional.Present("xx42")) @@ -246,8 +246,8 @@ class ConnectionProgrammaticPaginationTest { ) } } - apolloStore.writeOperation(query4, data4) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query4, data4) + dataFromStore = cacheManager.readOperation(query1).data expectedData = UsersQuery.Data { users = buildUserConnection { pageInfo = buildPageInfo { @@ -307,7 +307,7 @@ class ConnectionProgrammaticPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Non-contiguous page (should reset) val query5 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx50")) @@ -333,10 +333,10 @@ class ConnectionProgrammaticPaginationTest { ) } } - apolloStore.writeOperation(query5, data5) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query5, data5) + dataFromStore = cacheManager.readOperation(query1).data assertEquals(data5, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Empty page (should keep previous result) val query6 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx51")) @@ -349,10 +349,10 @@ class ConnectionProgrammaticPaginationTest { edges = emptyList() } } - apolloStore.writeOperation(query6, data6) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query6, data6) + dataFromStore = cacheManager.readOperation(query1).data assertEquals(data5, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) } } diff --git a/tests/pagination/src/commonTest/kotlin/ConnectionWithNodesPaginationTest.kt b/tests/pagination/src/commonTest/kotlin/ConnectionWithNodesPaginationTest.kt index 43cc0e2c..9c2d7bdb 100644 --- a/tests/pagination/src/commonTest/kotlin/ConnectionWithNodesPaginationTest.kt +++ b/tests/pagination/src/commonTest/kotlin/ConnectionWithNodesPaginationTest.kt @@ -1,7 +1,7 @@ package pagination import com.apollographql.apollo.api.Optional -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.ConnectionMetadataGenerator import com.apollographql.cache.normalized.api.ConnectionRecordMerger import com.apollographql.cache.normalized.api.FieldPolicyCacheResolver @@ -35,14 +35,14 @@ class ConnectionWithNodesPaginationTest { } private fun test(cacheFactory: NormalizedCacheFactory) = runTest { - val apolloStore = ApolloStore( + val cacheManager = CacheManager( normalizedCacheFactory = cacheFactory, cacheKeyGenerator = TypePolicyCacheKeyGenerator, metadataGenerator = ConnectionMetadataGenerator(Pagination.connectionTypes), cacheResolver = FieldPolicyCacheResolver, recordMerger = ConnectionRecordMerger ) - apolloStore.clearAll() + cacheManager.clearAll() // First page val query1 = UsersQuery(first = Optional.Present(2)) @@ -62,10 +62,10 @@ class ConnectionWithNodesPaginationTest { ) } } - apolloStore.writeOperation(query1, data1) - var dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query1, data1) + var dataFromStore = cacheManager.readOperation(query1).data assertEquals(data1, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page after val query2 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx43")) @@ -85,8 +85,8 @@ class ConnectionWithNodesPaginationTest { ) } } - apolloStore.writeOperation(query2, data2) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query2, data2) + dataFromStore = cacheManager.readOperation(query1).data var expectedData = UsersQuery.Data { users = buildUserConnection { pageInfo = buildPageInfo { @@ -110,7 +110,7 @@ class ConnectionWithNodesPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page after val query3 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx45")) @@ -130,8 +130,8 @@ class ConnectionWithNodesPaginationTest { ) } } - apolloStore.writeOperation(query3, data3) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query3, data3) + dataFromStore = cacheManager.readOperation(query1).data expectedData = UsersQuery.Data { users = buildUserConnection { pageInfo = buildPageInfo { @@ -161,7 +161,7 @@ class ConnectionWithNodesPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page before val query4 = UsersQuery(last = Optional.Present(2), before = Optional.Present("xx42")) @@ -181,8 +181,8 @@ class ConnectionWithNodesPaginationTest { ) } } - apolloStore.writeOperation(query4, data4) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query4, data4) + dataFromStore = cacheManager.readOperation(query1).data expectedData = UsersQuery.Data { users = buildUserConnection { pageInfo = buildPageInfo { @@ -218,7 +218,7 @@ class ConnectionWithNodesPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Non-contiguous page (should reset) val query5 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx50")) @@ -238,10 +238,10 @@ class ConnectionWithNodesPaginationTest { ) } } - apolloStore.writeOperation(query5, data5) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query5, data5) + dataFromStore = cacheManager.readOperation(query1).data assertEquals(data5, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Empty page (should keep previous result) val query6 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx51")) @@ -255,10 +255,10 @@ class ConnectionWithNodesPaginationTest { } } - apolloStore.writeOperation(query6, data6) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query6, data6) + dataFromStore = cacheManager.readOperation(query1).data assertEquals(data5, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) } } diff --git a/tests/pagination/src/commonTest/kotlin/CursorBasedPaginationTest.kt b/tests/pagination/src/commonTest/kotlin/CursorBasedPaginationTest.kt index 95ce8023..b7cc4046 100644 --- a/tests/pagination/src/commonTest/kotlin/CursorBasedPaginationTest.kt +++ b/tests/pagination/src/commonTest/kotlin/CursorBasedPaginationTest.kt @@ -4,7 +4,7 @@ import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.api.Optional import com.apollographql.apollo.testing.QueueTestNetworkTransport import com.apollographql.apollo.testing.enqueueTestResponse -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.ConnectionMetadataGenerator import com.apollographql.cache.normalized.api.ConnectionRecordMerger @@ -43,14 +43,14 @@ class CursorBasedPaginationTest { } private fun test(cacheFactory: NormalizedCacheFactory) = runTest { - val apolloStore = ApolloStore( + val cacheManager = CacheManager( normalizedCacheFactory = cacheFactory, cacheKeyGenerator = TypePolicyCacheKeyGenerator, metadataGenerator = ConnectionMetadataGenerator(setOf("UserConnection")), cacheResolver = FieldPolicyCacheResolver, recordMerger = ConnectionRecordMerger ) - apolloStore.clearAll() + cacheManager.clearAll() // First page val query1 = UsersQuery(first = Optional.Present(2)) @@ -76,10 +76,10 @@ class CursorBasedPaginationTest { ) } } - apolloStore.writeOperation(query1, data1) - var dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query1, data1) + var dataFromStore = cacheManager.readOperation(query1).data assertEquals(data1, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page after val query2 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx43")) @@ -105,8 +105,8 @@ class CursorBasedPaginationTest { ) } } - apolloStore.writeOperation(query2, data2) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query2, data2) + dataFromStore = cacheManager.readOperation(query1).data var expectedData = UsersQuery.Data { users = buildUserConnection { pageInfo = buildPageInfo { @@ -142,7 +142,7 @@ class CursorBasedPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page after val query3 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx45")) @@ -168,8 +168,8 @@ class CursorBasedPaginationTest { ) } } - apolloStore.writeOperation(query3, data3) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query3, data3) + dataFromStore = cacheManager.readOperation(query1).data expectedData = UsersQuery.Data { users = buildUserConnection { pageInfo = buildPageInfo { @@ -217,7 +217,7 @@ class CursorBasedPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page before val query4 = UsersQuery(last = Optional.Present(2), before = Optional.Present("xx42")) @@ -243,8 +243,8 @@ class CursorBasedPaginationTest { ) } } - apolloStore.writeOperation(query4, data4) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query4, data4) + dataFromStore = cacheManager.readOperation(query1).data expectedData = UsersQuery.Data { users = buildUserConnection { pageInfo = buildPageInfo { @@ -304,7 +304,7 @@ class CursorBasedPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Non-contiguous page (should reset) val query5 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx50")) @@ -330,10 +330,10 @@ class CursorBasedPaginationTest { ) } } - apolloStore.writeOperation(query5, data5) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query5, data5) + dataFromStore = cacheManager.readOperation(query1).data assertEquals(data5, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Empty page (should keep previous result) val query6 = UsersQuery(first = Optional.Present(2), after = Optional.Present("xx51")) @@ -346,10 +346,10 @@ class CursorBasedPaginationTest { edges = emptyList() } } - apolloStore.writeOperation(query6, data6) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query6, data6) + dataFromStore = cacheManager.readOperation(query1).data assertEquals(data5, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) } @Test diff --git a/tests/pagination/src/commonTest/kotlin/EmbedTest.kt b/tests/pagination/src/commonTest/kotlin/EmbedTest.kt index c529a68f..4263092d 100644 --- a/tests/pagination/src/commonTest/kotlin/EmbedTest.kt +++ b/tests/pagination/src/commonTest/kotlin/EmbedTest.kt @@ -4,10 +4,10 @@ import com.apollographql.apollo.ApolloClient import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.CacheKeyGenerator import com.apollographql.cache.normalized.api.CacheKeyGeneratorContext +import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.internal.normalized import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.normalizedCache -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.runTest import embed.GetHeroQuery import kotlin.test.Test @@ -47,8 +47,8 @@ class EmbedTest { listOf(GetHeroQuery.Friend("Luke", GetHeroQuery.Pet("Snoopy")), GetHeroQuery.Friend("Leia", GetHeroQuery.Pet("Fluffy"))) ) ) - client.store.writeOperation(query, data) - val dataFromStore = client.store.readOperation(query).data + client.apolloStore.writeOperation(query, data) + val dataFromStore = client.apolloStore.readOperation(query).data assertEquals(data, dataFromStore) } } diff --git a/tests/pagination/src/commonTest/kotlin/OffsetBasedWithArrayPaginationTest.kt b/tests/pagination/src/commonTest/kotlin/OffsetBasedWithArrayPaginationTest.kt index b5789422..60ed12d5 100644 --- a/tests/pagination/src/commonTest/kotlin/OffsetBasedWithArrayPaginationTest.kt +++ b/tests/pagination/src/commonTest/kotlin/OffsetBasedWithArrayPaginationTest.kt @@ -2,7 +2,7 @@ package pagination import com.apollographql.apollo.api.Optional import com.apollographql.apollo.api.json.ApolloJsonElement -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.FieldPolicyCacheResolver import com.apollographql.cache.normalized.api.FieldRecordMerger import com.apollographql.cache.normalized.api.MetadataGenerator @@ -36,14 +36,14 @@ class OffsetBasedWithArrayPaginationTest { } private fun test(cacheFactory: NormalizedCacheFactory) = runTest { - val apolloStore = ApolloStore( + val cacheManager = CacheManager( normalizedCacheFactory = cacheFactory, cacheKeyGenerator = TypePolicyCacheKeyGenerator, metadataGenerator = OffsetPaginationMetadataGenerator("users"), cacheResolver = FieldPolicyCacheResolver, recordMerger = FieldRecordMerger(OffsetPaginationFieldMerger()) ) - apolloStore.clearAll() + cacheManager.clearAll() // First page val query1 = UsersQuery(offset = Optional.Present(42), limit = Optional.Present(2)) @@ -53,10 +53,10 @@ class OffsetBasedWithArrayPaginationTest { buildUser { id = "43" }, ) } - apolloStore.writeOperation(query1, data1) - var dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query1, data1) + var dataFromStore = cacheManager.readOperation(query1).data assertEquals(data1, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page after val query2 = UsersQuery(offset = Optional.Present(44), limit = Optional.Present(2)) @@ -66,8 +66,8 @@ class OffsetBasedWithArrayPaginationTest { buildUser { id = "45" }, ) } - apolloStore.writeOperation(query2, data2) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query2, data2) + dataFromStore = cacheManager.readOperation(query1).data var expectedData = UsersQuery.Data { users = listOf( buildUser { id = "42" }, @@ -77,7 +77,7 @@ class OffsetBasedWithArrayPaginationTest { ) } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page in the middle val query3 = UsersQuery(offset = Optional.Present(44), limit = Optional.Present(3)) @@ -88,8 +88,8 @@ class OffsetBasedWithArrayPaginationTest { buildUser { id = "46" }, ) } - apolloStore.writeOperation(query3, data3) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query3, data3) + dataFromStore = cacheManager.readOperation(query1).data expectedData = UsersQuery.Data { users = listOf( buildUser { id = "42" }, @@ -100,7 +100,7 @@ class OffsetBasedWithArrayPaginationTest { ) } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page before val query4 = UsersQuery(offset = Optional.Present(40), limit = Optional.Present(2)) @@ -110,8 +110,8 @@ class OffsetBasedWithArrayPaginationTest { buildUser { id = "41" }, ) } - apolloStore.writeOperation(query4, data4) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query4, data4) + dataFromStore = cacheManager.readOperation(query1).data expectedData = UsersQuery.Data { users = listOf( buildUser { id = "40" }, @@ -124,7 +124,7 @@ class OffsetBasedWithArrayPaginationTest { ) } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Non-contiguous page (should reset) val query5 = UsersQuery(offset = Optional.Present(50), limit = Optional.Present(2)) @@ -134,20 +134,20 @@ class OffsetBasedWithArrayPaginationTest { buildUser { id = "51" }, ) } - apolloStore.writeOperation(query5, data5) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query5, data5) + dataFromStore = cacheManager.readOperation(query1).data assertEquals(data5, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Empty page (should keep previous result) val query6 = UsersQuery(offset = Optional.Present(52), limit = Optional.Present(2)) val data6 = UsersQuery.Data { users = emptyList() } - apolloStore.writeOperation(query6, data6) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query6, data6) + dataFromStore = cacheManager.readOperation(query1).data assertEquals(data5, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) } private class OffsetPaginationMetadataGenerator(private val fieldName: String) : MetadataGenerator { diff --git a/tests/pagination/src/commonTest/kotlin/OffsetBasedWithPageAndInputPaginationTest.kt b/tests/pagination/src/commonTest/kotlin/OffsetBasedWithPageAndInputPaginationTest.kt index 1ad53c95..4484c507 100644 --- a/tests/pagination/src/commonTest/kotlin/OffsetBasedWithPageAndInputPaginationTest.kt +++ b/tests/pagination/src/commonTest/kotlin/OffsetBasedWithPageAndInputPaginationTest.kt @@ -5,7 +5,7 @@ import com.apollographql.apollo.api.CompiledField import com.apollographql.apollo.api.Executable import com.apollographql.apollo.api.Optional import com.apollographql.apollo.api.json.ApolloJsonElement -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.DefaultFieldKeyGenerator import com.apollographql.cache.normalized.api.FieldKeyContext import com.apollographql.cache.normalized.api.FieldKeyGenerator @@ -43,7 +43,7 @@ class OffsetBasedWithPageAndInputPaginationTest { } private fun test(cacheFactory: NormalizedCacheFactory) = runTest { - val apolloStore = ApolloStore( + val cacheManager = CacheManager( normalizedCacheFactory = cacheFactory, cacheKeyGenerator = TypePolicyCacheKeyGenerator, metadataGenerator = OffsetPaginationMetadataGenerator("UserPage"), @@ -51,7 +51,7 @@ class OffsetBasedWithPageAndInputPaginationTest { recordMerger = FieldRecordMerger(OffsetPaginationFieldMerger()), fieldKeyGenerator = UsersFieldKeyGenerator, ) - apolloStore.clearAll() + cacheManager.clearAll() // First page val query1 = UsersQuery(offset = Optional.Present(42), limit = Optional.Present(2)) @@ -63,10 +63,10 @@ class OffsetBasedWithPageAndInputPaginationTest { ) } } - apolloStore.writeOperation(query1, data1) - var dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query1, data1) + var dataFromStore = cacheManager.readOperation(query1).data assertEquals(data1, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page after val query2 = UsersQuery(offset = Optional.Present(44), limit = Optional.Present(2)) @@ -78,8 +78,8 @@ class OffsetBasedWithPageAndInputPaginationTest { ) } } - apolloStore.writeOperation(query2, data2) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query2, data2) + dataFromStore = cacheManager.readOperation(query1).data var expectedData = UsersQuery.Data { users = buildUserPage { users = listOf( @@ -91,7 +91,7 @@ class OffsetBasedWithPageAndInputPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page in the middle val query3 = UsersQuery(offset = Optional.Present(44), limit = Optional.Present(3)) @@ -104,8 +104,8 @@ class OffsetBasedWithPageAndInputPaginationTest { ) } } - apolloStore.writeOperation(query3, data3) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query3, data3) + dataFromStore = cacheManager.readOperation(query1).data expectedData = UsersQuery.Data { users = buildUserPage { users = listOf( @@ -118,7 +118,7 @@ class OffsetBasedWithPageAndInputPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page before val query4 = UsersQuery(offset = Optional.Present(40), limit = Optional.Present(2)) @@ -130,8 +130,8 @@ class OffsetBasedWithPageAndInputPaginationTest { ) } } - apolloStore.writeOperation(query4, data4) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query4, data4) + dataFromStore = cacheManager.readOperation(query1).data expectedData = UsersQuery.Data { users = buildUserPage { users = listOf( @@ -146,7 +146,7 @@ class OffsetBasedWithPageAndInputPaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Non-contiguous page (should reset) val query5 = UsersQuery(offset = Optional.Present(50), limit = Optional.Present(2)) @@ -158,10 +158,10 @@ class OffsetBasedWithPageAndInputPaginationTest { ) } } - apolloStore.writeOperation(query5, data5) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query5, data5) + dataFromStore = cacheManager.readOperation(query1).data assertEquals(data5, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Empty page (should keep previous result) val query6 = UsersQuery(offset = Optional.Present(52), limit = Optional.Present(2)) @@ -170,10 +170,10 @@ class OffsetBasedWithPageAndInputPaginationTest { users = emptyList() } } - apolloStore.writeOperation(query6, data6) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query6, data6) + dataFromStore = cacheManager.readOperation(query1).data assertEquals(data5, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) } private class OffsetPaginationMetadataGenerator(private val typeName: String) : MetadataGenerator { diff --git a/tests/pagination/src/commonTest/kotlin/OffsetBasedWithPagePaginationTest.kt b/tests/pagination/src/commonTest/kotlin/OffsetBasedWithPagePaginationTest.kt index ed2bdfdc..8d13af80 100644 --- a/tests/pagination/src/commonTest/kotlin/OffsetBasedWithPagePaginationTest.kt +++ b/tests/pagination/src/commonTest/kotlin/OffsetBasedWithPagePaginationTest.kt @@ -2,7 +2,7 @@ package pagination import com.apollographql.apollo.api.Optional import com.apollographql.apollo.api.json.ApolloJsonElement -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.FieldPolicyCacheResolver import com.apollographql.cache.normalized.api.FieldRecordMerger @@ -39,14 +39,14 @@ class OffsetBasedWithPagePaginationTest { } private fun test(cacheFactory: NormalizedCacheFactory) = runTest { - val apolloStore = ApolloStore( + val cacheManager = CacheManager( normalizedCacheFactory = cacheFactory, cacheKeyGenerator = TypePolicyCacheKeyGenerator, metadataGenerator = OffsetPaginationMetadataGenerator("UserPage"), cacheResolver = FieldPolicyCacheResolver, recordMerger = FieldRecordMerger(OffsetPaginationFieldMerger()) ) - apolloStore.clearAll() + cacheManager.clearAll() // First page val query1 = UsersQuery(offset = Optional.Present(42), limit = Optional.Present(2)) @@ -58,10 +58,10 @@ class OffsetBasedWithPagePaginationTest { ) } } - apolloStore.writeOperation(query1, data1) - var dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query1, data1) + var dataFromStore = cacheManager.readOperation(query1).data assertEquals(data1, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page after val query2 = UsersQuery(offset = Optional.Present(44), limit = Optional.Present(2)) @@ -73,8 +73,8 @@ class OffsetBasedWithPagePaginationTest { ) } } - apolloStore.writeOperation(query2, data2) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query2, data2) + dataFromStore = cacheManager.readOperation(query1).data var expectedData = UsersQuery.Data { users = buildUserPage { users = listOf( @@ -86,7 +86,7 @@ class OffsetBasedWithPagePaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page in the middle val query3 = UsersQuery(offset = Optional.Present(44), limit = Optional.Present(3)) @@ -99,8 +99,8 @@ class OffsetBasedWithPagePaginationTest { ) } } - apolloStore.writeOperation(query3, data3) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query3, data3) + dataFromStore = cacheManager.readOperation(query1).data expectedData = UsersQuery.Data { users = buildUserPage { users = listOf( @@ -113,7 +113,7 @@ class OffsetBasedWithPagePaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Page before val query4 = UsersQuery(offset = Optional.Present(40), limit = Optional.Present(2)) @@ -125,8 +125,8 @@ class OffsetBasedWithPagePaginationTest { ) } } - apolloStore.writeOperation(query4, data4) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query4, data4) + dataFromStore = cacheManager.readOperation(query1).data expectedData = UsersQuery.Data { users = buildUserPage { users = listOf( @@ -141,7 +141,7 @@ class OffsetBasedWithPagePaginationTest { } } assertEquals(expectedData, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Non-contiguous page (should reset) val query5 = UsersQuery(offset = Optional.Present(50), limit = Optional.Present(2)) @@ -153,10 +153,10 @@ class OffsetBasedWithPagePaginationTest { ) } } - apolloStore.writeOperation(query5, data5) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query5, data5) + dataFromStore = cacheManager.readOperation(query1).data assertEquals(data5, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) // Empty page (should keep previous result) val query6 = UsersQuery(offset = Optional.Present(52), limit = Optional.Present(2)) @@ -165,10 +165,10 @@ class OffsetBasedWithPagePaginationTest { users = emptyList() } } - apolloStore.writeOperation(query6, data6) - dataFromStore = apolloStore.readOperation(query1).data + cacheManager.writeOperation(query6, data6) + dataFromStore = cacheManager.readOperation(query1).data assertEquals(data5, dataFromStore) - assertChainedCachesAreEqual(apolloStore) + assertChainedCachesAreEqual(cacheManager) } private class OffsetPaginationMetadataGenerator(private val typeName: String) : MetadataGenerator { @@ -227,8 +227,8 @@ class OffsetBasedWithPagePaginationTest { } } -internal fun assertChainedCachesAreEqual(apolloStore: ApolloStore) { - val dump = apolloStore.dump().filterKeys { +internal fun assertChainedCachesAreEqual(cacheManager: CacheManager) { + val dump = cacheManager.dump().filterKeys { // Ignore optimistic cache for comparison it.simpleName != "OptimisticNormalizedCache" } diff --git a/tests/partial-results/src/commonTest/kotlin/test/CachePartialResultTest.kt b/tests/partial-results/src/commonTest/kotlin/test/CachePartialResultTest.kt index 2b7f3f3f..4997ed96 100644 --- a/tests/partial-results/src/commonTest/kotlin/test/CachePartialResultTest.kt +++ b/tests/partial-results/src/commonTest/kotlin/test/CachePartialResultTest.kt @@ -8,7 +8,7 @@ import com.apollographql.apollo.api.Operation import com.apollographql.apollo.api.graphQLErrorOrNull import com.apollographql.apollo.interceptor.ApolloInterceptor import com.apollographql.apollo.interceptor.ApolloInterceptorChain -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.CacheControlCacheResolver import com.apollographql.cache.normalized.api.CacheHeaders @@ -18,12 +18,13 @@ import com.apollographql.cache.normalized.api.IdCacheKeyGenerator import com.apollographql.cache.normalized.api.IdCacheKeyResolver import com.apollographql.cache.normalized.api.Record import com.apollographql.cache.normalized.api.SchemaCoordinatesMaxAgeProvider +import com.apollographql.cache.normalized.apolloStore +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchFromCache import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.fetchPolicyInterceptor import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.normalizedCache -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.storeReceivedDate import com.apollographql.cache.normalized.testing.append import com.apollographql.cache.normalized.testing.assertErrorsEquals @@ -170,8 +171,8 @@ class CachePartialResultTest { ) ApolloClient.Builder() .serverUrl(mockServer.url()) - .store( - ApolloStore( + .cacheManager( + CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheKeyResolver() @@ -309,7 +310,7 @@ class CachePartialResultTest { ) // Remove project lead from the cache - apolloClient.store.remove(CacheKey("User:3")) + apolloClient.apolloStore.remove(CacheKey("User:3")) val cacheResult = apolloClient.query(MeWithBestFriendQuery()) .fetchPolicyInterceptor(PartialCacheOnlyInterceptor) .execute() @@ -353,7 +354,7 @@ class CachePartialResultTest { ) // Remove best friend from the cache - apolloClient.store.remove(CacheKey("User:2")) + apolloClient.apolloStore.remove(CacheKey("User:2")) val cacheResult2 = apolloClient.query(MeWithBestFriendQuery()) .fetchPolicyInterceptor(PartialCacheOnlyInterceptor) .execute() @@ -394,7 +395,7 @@ class CachePartialResultTest { ) // Remove project user from the cache - apolloClient.store.remove(CacheKey("User:4")) + apolloClient.apolloStore.remove(CacheKey("User:4")) val cacheResult3 = apolloClient.query(MeWithBestFriendQuery()) .fetchPolicyInterceptor(PartialCacheOnlyInterceptor) .execute() @@ -441,8 +442,8 @@ class CachePartialResultTest { ) ApolloClient.Builder() .serverUrl(mockServer.url()) - .store( - ApolloStore( + .cacheManager( + CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheKeyResolver() @@ -503,8 +504,8 @@ class CachePartialResultTest { ) ApolloClient.Builder() .serverUrl(mockServer.url()) - .store( - ApolloStore( + .cacheManager( + CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheKeyResolver() @@ -541,7 +542,7 @@ class CachePartialResultTest { ) // Remove the category from the cache - apolloClient.store.accessCache { cache -> + apolloClient.apolloStore.accessCache { cache -> val record = cache.loadRecord(CacheKey("User:1"), CacheHeaders.NONE)!! cache.remove(CacheKey("User:1"), false) cache.merge(Record(record.key, record.fields - "category"), CacheHeaders.NONE, DefaultRecordMerger) @@ -645,7 +646,7 @@ class CachePartialResultTest { ) // Remove lead from the cache - apolloClient.store.remove(CacheKey("User:2")) + apolloClient.apolloStore.remove(CacheKey("User:2")) val cacheMissResult = apolloClient.query(WithFragmentsQuery()) .fetchPolicyInterceptor(PartialCacheOnlyInterceptor) diff --git a/tests/store-errors/src/commonTest/kotlin/test/StoreErrorsTest.kt b/tests/store-errors/src/commonTest/kotlin/test/StoreErrorsTest.kt index 9fda53c7..a0bdc406 100644 --- a/tests/store-errors/src/commonTest/kotlin/test/StoreErrorsTest.kt +++ b/tests/store-errors/src/commonTest/kotlin/test/StoreErrorsTest.kt @@ -7,18 +7,18 @@ import com.apollographql.apollo.api.Error import com.apollographql.apollo.api.Operation import com.apollographql.apollo.interceptor.ApolloInterceptor import com.apollographql.apollo.interceptor.ApolloInterceptorChain -import com.apollographql.cache.normalized.ApolloStore +import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.Record import com.apollographql.cache.normalized.api.withErrors +import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.errorsReplaceCachedValues import com.apollographql.cache.normalized.fetchFromCache import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.fetchPolicyInterceptor import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.sql.SqlNormalizedCacheFactory -import com.apollographql.cache.normalized.store import com.apollographql.cache.normalized.testing.assertErrorsEquals import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockServer @@ -41,28 +41,28 @@ class StoreErrorsTest { mockServer.close() } - private val memoryStore = ApolloStore(MemoryCacheFactory()) + private val memoryCacheManager = CacheManager(MemoryCacheFactory()) - private val sqlStore = ApolloStore(SqlNormalizedCacheFactory()).also { it.clearAll() } + private val sqlCacheManager = CacheManager(SqlNormalizedCacheFactory()).also { it.clearAll() } - private val memoryThenSqlStore = ApolloStore(MemoryCacheFactory().chain(SqlNormalizedCacheFactory())).also { it.clearAll() } + private val memoryThenSqlCacheManager = CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory())).also { it.clearAll() } @Test fun simpleMemory() = runTest(before = { setUp() }, after = { tearDown() }) { - simple(memoryStore) + simple(memoryCacheManager) } @Test fun simpleSql() = runTest(before = { setUp() }, after = { tearDown() }) { - simple(sqlStore) + simple(sqlCacheManager) } @Test fun simpleMemoryThenSql() = runTest(before = { setUp() }, after = { tearDown() }) { - simple(memoryThenSqlStore) + simple(memoryThenSqlCacheManager) } - private suspend fun simple(store: ApolloStore) { + private suspend fun simple(cacheManager: CacheManager) { mockServer.enqueueString( // language=JSON """ @@ -87,7 +87,7 @@ class StoreErrorsTest { ) ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .build() .use { apolloClient -> val networkResult = apolloClient.query(MeWithNickNameQuery()) @@ -128,20 +128,20 @@ class StoreErrorsTest { @Test fun listsMemory() = runTest(before = { setUp() }, after = { tearDown() }) { - lists(memoryStore) + lists(memoryCacheManager) } @Test fun listsSql() = runTest(before = { setUp() }, after = { tearDown() }) { - lists(sqlStore) + lists(sqlCacheManager) } @Test fun listsMemoryThenSql() = runTest(before = { setUp() }, after = { tearDown() }) { - lists(memoryThenSqlStore) + lists(memoryThenSqlCacheManager) } - private suspend fun lists(store: ApolloStore) { + private suspend fun lists(cacheManager: CacheManager) { mockServer.enqueueString( // language=JSON """ @@ -176,7 +176,7 @@ class StoreErrorsTest { ) ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .build() .use { apolloClient -> val networkResult = apolloClient.query(UsersQuery(listOf("1", "2", "3"))) @@ -227,20 +227,20 @@ class StoreErrorsTest { @Test fun compositeMemory() = runTest(before = { setUp() }, after = { tearDown() }) { - composite(memoryStore) + composite(memoryCacheManager) } @Test fun compositeSql() = runTest(before = { setUp() }, after = { tearDown() }) { - composite(sqlStore) + composite(sqlCacheManager) } @Test fun compositeMemoryThenSql() = runTest(before = { setUp() }, after = { tearDown() }) { - composite(memoryThenSqlStore) + composite(memoryThenSqlCacheManager) } - private suspend fun composite(store: ApolloStore) { + private suspend fun composite(cacheManager: CacheManager) { mockServer.enqueueString( // language=JSON """ @@ -284,7 +284,7 @@ class StoreErrorsTest { ) ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .build() .use { apolloClient -> val networkResult = apolloClient.query(MeWithBestFriendQuery()) @@ -342,20 +342,20 @@ class StoreErrorsTest { @Test fun aliasesMemory() = runTest(before = { setUp() }, after = { tearDown() }) { - aliases(memoryStore) + aliases(memoryCacheManager) } @Test fun aliasesSql() = runTest(before = { setUp() }, after = { tearDown() }) { - aliases(sqlStore) + aliases(sqlCacheManager) } @Test fun aliasesMemoryThenSql() = runTest(before = { setUp() }, after = { tearDown() }) { - aliases(memoryThenSqlStore) + aliases(memoryThenSqlCacheManager) } - private suspend fun aliases(store: ApolloStore) { + private suspend fun aliases(cacheManager: CacheManager) { mockServer.enqueueString( // language=JSON """ @@ -380,7 +380,7 @@ class StoreErrorsTest { ) ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .build() .use { apolloClient -> val networkResult = apolloClient.query(DefaultProjectQuery()) @@ -420,20 +420,20 @@ class StoreErrorsTest { @Test fun fragmentsAndAliasesMemory() = runTest(before = { setUp() }, after = { tearDown() }) { - fragmentsAndAliases(memoryStore) + fragmentsAndAliases(memoryCacheManager) } @Test fun fragmentsAndAliasesSql() = runTest(before = { setUp() }, after = { tearDown() }) { - fragmentsAndAliases(sqlStore) + fragmentsAndAliases(sqlCacheManager) } @Test fun fragmentsAndAliasesMemoryThenSql() = runTest(before = { setUp() }, after = { tearDown() }) { - fragmentsAndAliases(memoryThenSqlStore) + fragmentsAndAliases(memoryThenSqlCacheManager) } - private fun fragmentsAndAliases(store: ApolloStore) = runTest(before = { setUp() }, after = { tearDown() }) { + private fun fragmentsAndAliases(cacheManager: CacheManager) = runTest(before = { setUp() }, after = { tearDown() }) { mockServer.enqueueString( // language=JSON """ @@ -472,7 +472,7 @@ class StoreErrorsTest { ) ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .build() .use { apolloClient -> val networkResult = apolloClient.query(WithFragmentsQuery()) @@ -534,20 +534,20 @@ class StoreErrorsTest { @Test fun errorsReplaceCachedValuesMemory() = runTest(before = { setUp() }, after = { tearDown() }) { - errorsReplaceCachedValues(memoryStore) + errorsReplaceCachedValues(memoryCacheManager) } @Test fun errorsReplaceCachedValuesSql() = runTest(before = { setUp() }, after = { tearDown() }) { - errorsReplaceCachedValues(sqlStore) + errorsReplaceCachedValues(sqlCacheManager) } @Test fun errorsReplaceCachedValuesMemoryThenSql() = runTest(before = { setUp() }, after = { tearDown() }) { - errorsReplaceCachedValues(memoryThenSqlStore) + errorsReplaceCachedValues(memoryThenSqlCacheManager) } - private suspend fun errorsReplaceCachedValues(store: ApolloStore) { + private suspend fun errorsReplaceCachedValues(cacheManager: CacheManager) { mockServer.enqueueString( // language=JSON """ @@ -612,7 +612,7 @@ class StoreErrorsTest { ApolloClient.Builder() .serverUrl(mockServer.url()) - .store(store) + .cacheManager(cacheManager) .build() .use { apolloClient -> val noErrorNetworkResult = apolloClient.query(MeWithNickNameQuery()) @@ -704,7 +704,7 @@ class StoreErrorsTest { query, listOf(Error.Builder("'nickName' can't be reached").path(listOf("me", "nickName")).build()), ) - val normalized: Map = memoryStore.normalize( + val normalized: Map = memoryCacheManager.normalize( executable = query, dataWithErrors = dataWithErrors, ) @@ -719,21 +719,21 @@ class StoreErrorsTest { @Test fun writeOperationMemory() = runTest(before = { setUp() }, after = { tearDown() }) { - writeOperation(memoryStore) + writeOperation(memoryCacheManager) } @Test fun writeOperationSql() = runTest(before = { setUp() }, after = { tearDown() }) { - writeOperation(sqlStore) + writeOperation(sqlCacheManager) } @Test fun writeOperationMemoryThenSql() = runTest(before = { setUp() }, after = { tearDown() }) { - writeOperation(memoryThenSqlStore) + writeOperation(memoryThenSqlCacheManager) } - private fun writeOperation(store: ApolloStore) { - store.writeOperation( + private fun writeOperation(cacheManager: CacheManager) { + cacheManager.writeOperation( operation = MeWithNickNameQuery(), data = MeWithNickNameQuery.Data( MeWithNickNameQuery.Me( @@ -748,7 +748,7 @@ class StoreErrorsTest { Error.Builder("'nickName' can't be reached").path(listOf("me", "nickName")).build() ), ) - val responseFromCache = store.readOperation(MeWithNickNameQuery()) + val responseFromCache = cacheManager.readOperation(MeWithNickNameQuery()) assertEquals( MeWithNickNameQuery.Data( MeWithNickNameQuery.Me(