diff --git a/CHANGELOG.md b/CHANGELOG.md index 34c9c188..3f9ab7a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Next version (unreleased) - Records are now rooted per operation type (QUERY_ROOT, MUTATION_ROOT, SUBSCRIPTION_ROOT) (#109) +- `ApolloClient.apolloStore` is deprecated in favor of `ApolloClient.store` for consistency. # Version 0.0.8 _2025-03-28_ diff --git a/Writerside/topics/migration-guide.md b/Writerside/topics/migration-guide.md index 4a2463ba..cb6f3443 100644 --- a/Writerside/topics/migration-guide.md +++ b/Writerside/topics/migration-guide.md @@ -106,6 +106,7 @@ store.writeOperation(operation, data).also { store.publish(it) } - `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/normalized-cache-incubating/api/normalized-cache-incubating.api b/normalized-cache-incubating/api/normalized-cache-incubating.api index af048e23..e37bb3e3 100644 --- a/normalized-cache-incubating/api/normalized-cache-incubating.api +++ b/normalized-cache-incubating/api/normalized-cache-incubating.api @@ -160,6 +160,7 @@ public final class com/apollographql/cache/normalized/NormalizedCache { 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/ApolloStore; 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; diff --git a/normalized-cache-incubating/api/normalized-cache-incubating.klib.api b/normalized-cache-incubating/api/normalized-cache-incubating.klib.api index 94144144..fe60147c 100644 --- a/normalized-cache-incubating/api/normalized-cache-incubating.klib.api +++ b/normalized-cache-incubating/api/normalized-cache-incubating.klib.api @@ -568,6 +568,8 @@ 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/ApolloStore // com.apollographql.cache.normalized/store.|@com.apollographql.apollo.ApolloClient(){}[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] diff --git a/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/ClientCacheExtensions.kt b/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/ClientCacheExtensions.kt index 2ca1daea..839b9cc9 100644 --- a/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/ClientCacheExtensions.kt +++ b/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/ClientCacheExtensions.kt @@ -191,13 +191,18 @@ internal fun ApolloCall.watchInternal(data: D?): Flow - apolloClient.apolloStore.clearAll() + apolloClient.store.clearAll() val networkResponse = apolloClient.query(GetUserQuery()) .fetchPolicy(FetchPolicy.NetworkOnly) .execute() @@ -195,7 +195,7 @@ class DoNotStoreTest { ) .build() .use { apolloClient -> - apolloClient.apolloStore.clearAll() + apolloClient.store.clearAll() val networkResponse = apolloClient.mutation(SignInMutation("scott", "tiger")) .fetchPolicy(FetchPolicy.NetworkOnly) .execute() @@ -221,7 +221,7 @@ class DoNotStoreTest { networkResponse.data ) - apolloClient.apolloStore.accessCache { cache -> + apolloClient.store.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 e3dc07ee..241f10e2 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.apolloStore.clearAll() + client.store.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 7fe5b2ee..084597a1 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.apolloStore.writeOperation(operation, data) + client.store.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 950fef34..183c7b97 100644 --- a/tests/defer/src/commonTest/kotlin/test/DeferNormalizedCacheTest.kt +++ b/tests/defer/src/commonTest/kotlin/test/DeferNormalizedCacheTest.kt @@ -15,7 +15,6 @@ import com.apollographql.cache.normalized.ApolloStore 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.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.optimisticUpdates @@ -543,7 +542,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.apolloStore.accessCache { it.loadRecord(CacheKey("computers").append("0"), CacheHeaders.NONE)!!.fields }.also { + apolloClient.store.accessCache { it.loadRecord(CacheKey("computers").append("0"), CacheHeaders.NONE)!!.fields }.also { multipartBody.enqueuePart(jsonList[1].encodeUtf8(), true) } }.toList() diff --git a/tests/normalized-cache/src/commonTest/kotlin/fragmentnormalizer/FragmentNormalizerTest.kt b/tests/normalized-cache/src/commonTest/kotlin/fragmentnormalizer/FragmentNormalizerTest.kt index 8f8e6ba4..43e21e81 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.apolloStore.writeFragment( + apolloClient.store.writeFragment( ConversationFragmentImpl(), CacheKey(fragment1.id), fragment1Read, ) - apolloClient.apolloStore.writeFragment( + apolloClient.store.writeFragment( ConversationFragmentImpl(), CacheKey(fragment2.id), fragment2Read, ) - fragment1 = apolloClient.apolloStore.readFragment( + fragment1 = apolloClient.store.readFragment( ConversationFragmentImpl(), CacheKey(fragment1.id), ).data diff --git a/tests/pagination/src/commonTest/kotlin/EmbedTest.kt b/tests/pagination/src/commonTest/kotlin/EmbedTest.kt index 4263092d..c529a68f 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.apolloStore.writeOperation(query, data) - val dataFromStore = client.apolloStore.readOperation(query).data + client.store.writeOperation(query, data) + val dataFromStore = client.store.readOperation(query).data assertEquals(data, dataFromStore) } } diff --git a/tests/partial-results/src/commonTest/kotlin/test/CachePartialResultTest.kt b/tests/partial-results/src/commonTest/kotlin/test/CachePartialResultTest.kt index 6e08a8ad..2b7f3f3f 100644 --- a/tests/partial-results/src/commonTest/kotlin/test/CachePartialResultTest.kt +++ b/tests/partial-results/src/commonTest/kotlin/test/CachePartialResultTest.kt @@ -18,7 +18,6 @@ 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.fetchFromCache import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.fetchPolicyInterceptor @@ -310,7 +309,7 @@ class CachePartialResultTest { ) // Remove project lead from the cache - apolloClient.apolloStore.remove(CacheKey("User:3")) + apolloClient.store.remove(CacheKey("User:3")) val cacheResult = apolloClient.query(MeWithBestFriendQuery()) .fetchPolicyInterceptor(PartialCacheOnlyInterceptor) .execute() @@ -354,7 +353,7 @@ class CachePartialResultTest { ) // Remove best friend from the cache - apolloClient.apolloStore.remove(CacheKey("User:2")) + apolloClient.store.remove(CacheKey("User:2")) val cacheResult2 = apolloClient.query(MeWithBestFriendQuery()) .fetchPolicyInterceptor(PartialCacheOnlyInterceptor) .execute() @@ -395,7 +394,7 @@ class CachePartialResultTest { ) // Remove project user from the cache - apolloClient.apolloStore.remove(CacheKey("User:4")) + apolloClient.store.remove(CacheKey("User:4")) val cacheResult3 = apolloClient.query(MeWithBestFriendQuery()) .fetchPolicyInterceptor(PartialCacheOnlyInterceptor) .execute() @@ -542,7 +541,7 @@ class CachePartialResultTest { ) // Remove the category from the cache - apolloClient.apolloStore.accessCache { cache -> + apolloClient.store.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) @@ -646,7 +645,7 @@ class CachePartialResultTest { ) // Remove lead from the cache - apolloClient.apolloStore.remove(CacheKey("User:2")) + apolloClient.store.remove(CacheKey("User:2")) val cacheMissResult = apolloClient.query(WithFragmentsQuery()) .fetchPolicyInterceptor(PartialCacheOnlyInterceptor)