diff --git a/CHANGELOG.md b/CHANGELOG.md index dee75b591..0ff7cd00c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ PUT_CHANGELOG_HERE - Database files are now stored in the `cache` directory by default on Android (#164) +- `FieldPolicyCacheResolver` now uses the `fieldPolicies` passed to its constructor instead of the information from `CompiledField`. This allows to better isolate the main Apollo Kotlin project from the cache project. (#250) + If your code was calling `FieldPolicyCacheResolver()` directly, update it to pass `Cache.fieldPolicies` to the constructor. +- Rename `IdCacheKeyResolver` to `IdCacheResolver`, and keep the list ids and single id arguments in the same list. (#250) # v1.0.0-alpha.7 _2025-10-14_ diff --git a/normalized-cache-apollo-compiler-plugin/src/main/kotlin/com/apollographql/cache/apollocompilerplugin/internal/AddKeyFieldsDocumentTransform.kt b/normalized-cache-apollo-compiler-plugin/src/main/kotlin/com/apollographql/cache/apollocompilerplugin/internal/AddKeyFieldsDocumentTransform.kt index 1b576e032..70c3d5bee 100644 --- a/normalized-cache-apollo-compiler-plugin/src/main/kotlin/com/apollographql/cache/apollocompilerplugin/internal/AddKeyFieldsDocumentTransform.kt +++ b/normalized-cache-apollo-compiler-plugin/src/main/kotlin/com/apollographql/cache/apollocompilerplugin/internal/AddKeyFieldsDocumentTransform.kt @@ -43,7 +43,7 @@ internal object AddKeyFieldsExecutableDocumentTransform : ExecutableDocumentTran ) } - private fun GQLOperationDefinition.withRequiredFields(schema: Schema, keyFields: Map>): GQLOperationDefinition { + private fun GQLOperationDefinition.withRequiredFields(schema: Schema, keyFields: Map>): GQLOperationDefinition { val parentType = rootTypeDefinition(schema)!!.name return copy( selections = selections.withRequiredFields( @@ -55,7 +55,7 @@ internal object AddKeyFieldsExecutableDocumentTransform : ExecutableDocumentTran ) } - private fun GQLFragmentDefinition.withRequiredFields(schema: Schema, keyFields: Map>): GQLFragmentDefinition { + private fun GQLFragmentDefinition.withRequiredFields(schema: Schema, keyFields: Map>): GQLFragmentDefinition { return copy( selections = selections.withRequiredFields( schema = schema, @@ -73,7 +73,7 @@ internal object AddKeyFieldsExecutableDocumentTransform : ExecutableDocumentTran @OptIn(ApolloInternal::class) private fun List.withRequiredFields( schema: Schema, - keyFields: Map>, + keyFields: Map>, parentType: String, isRoot: Boolean, ): List { @@ -106,7 +106,7 @@ internal object AddKeyFieldsExecutableDocumentTransform : ExecutableDocumentTran return newSelections } - val parentTypeKeyFields = keyFields[parentType] ?: emptySet() + val parentTypeKeyFields = keyFields[parentType] ?: emptyList() newSelections.filterIsInstance().forEach { // Disallow fields whose alias conflicts with a key field, or is "__typename" if (parentTypeKeyFields.contains(it.alias) || it.alias == "__typename") { @@ -118,7 +118,7 @@ internal object AddKeyFieldsExecutableDocumentTransform : ExecutableDocumentTran } // Add key fields - val fieldNames = newSelections.filterIsInstance().map { it.responseName() } + val fieldNames = newSelections.filterIsInstance().map { it.responseName() }.toSet() val fieldNamesToAdd = (parentTypeKeyFields - fieldNames) // Unions and interfaces without key fields: add key fields of all possible types in inline fragments @@ -130,7 +130,7 @@ internal object AddKeyFieldsExecutableDocumentTransform : ExecutableDocumentTran emptySet() } possibleTypes - .associateWith { possibleType -> keyFields[possibleType] ?: emptySet() } + .associateWith { possibleType -> keyFields[possibleType] ?: emptyList() } .mapNotNull { (possibleType, possibleTypeKeyFields) -> val fieldNamesToAddInInlineFragment = possibleTypeKeyFields - fieldNames if (fieldNamesToAddInInlineFragment.isNotEmpty()) { @@ -156,7 +156,7 @@ internal object AddKeyFieldsExecutableDocumentTransform : ExecutableDocumentTran private fun GQLField.withRequiredFields( schema: Schema, - keyFields: Map>, + keyFields: Map>, parentType: String, ): GQLField { val typeDefinition = definitionFromScope(schema, parentType)!! diff --git a/normalized-cache-apollo-compiler-plugin/src/main/kotlin/com/apollographql/cache/apollocompilerplugin/internal/CacheSchemaCodeGenerator.kt b/normalized-cache-apollo-compiler-plugin/src/main/kotlin/com/apollographql/cache/apollocompilerplugin/internal/CacheSchemaCodeGenerator.kt index 1909b91ba..65797304f 100644 --- a/normalized-cache-apollo-compiler-plugin/src/main/kotlin/com/apollographql/cache/apollocompilerplugin/internal/CacheSchemaCodeGenerator.kt +++ b/normalized-cache-apollo-compiler-plugin/src/main/kotlin/com/apollographql/cache/apollocompilerplugin/internal/CacheSchemaCodeGenerator.kt @@ -36,6 +36,8 @@ private object Symbols { val Seconds = MemberName(Duration.Companion::class.asTypeName(), "seconds", isExtension = true) val TypePolicy = ClassName("com.apollographql.cache.normalized.api", "TypePolicy") val EmbeddedFields = ClassName("com.apollographql.cache.normalized.api", "EmbeddedFields") + val FieldPolicies = ClassName("com.apollographql.cache.normalized.api", "FieldPolicies") + val FieldPolicy = FieldPolicies.nestedClass("FieldPolicy") val ApolloClientBuilder = ClassName("com.apollographql.apollo", "ApolloClient", "Builder") val NormalizedCacheFactory = ClassName("com.apollographql.cache.normalized.api", "NormalizedCacheFactory") val CacheKeyScope = ClassName("com.apollographql.cache.normalized.api", "CacheKey", "Scope") @@ -59,6 +61,7 @@ internal class CacheSchemaCodeGenerator( ?: environment.arguments["packageName"] as? String ?: throw IllegalArgumentException("com.apollographql.cache.packageName argument is required and must be a String")) + ".cache" val typePolicies = validSchema.getTypePolicies() + val fieldPolicies = validSchema.getFieldPolicies() val connectionTypes = validSchema.getConnectionTypes() val embeddedFields = validSchema.getEmbeddedFields(typePolicies, connectionTypes) val file = FileSpec.builder(packageName, "Cache") @@ -66,6 +69,7 @@ internal class CacheSchemaCodeGenerator( TypeSpec.objectBuilder("Cache") .addProperty(maxAgeProperty(validSchema)) .addProperty(typePoliciesProperty(typePolicies)) + .addProperty(fieldPoliciesProperty(fieldPolicies)) .addProperty(embeddedFieldsProperty(embeddedFields)) .addProperty(connectionTypesProperty(connectionTypes)) .addFunction(cacheFunction()) @@ -145,7 +149,7 @@ internal class CacheSchemaCodeGenerator( typePolicies.forEach { (type, typePolicy) -> addStatement("%S to %T(", type, Symbols.TypePolicy) withIndent { - addStatement("keyFields = setOf(") + addStatement("keyFields = listOf(") withIndent { typePolicy.keyFields.forEach { keyField -> addStatement("%S, ", keyField) @@ -191,6 +195,49 @@ internal class CacheSchemaCodeGenerator( .build() } + private fun fieldPoliciesProperty(fieldPolicies: Map): PropertySpec { + val initializer = if (fieldPolicies.isEmpty()) { + CodeBlock.of("emptyMap()") + } else { + CodeBlock.builder().apply { + add("mapOf(\n") + withIndent { + fieldPolicies.forEach { (type, fieldPolicies) -> + addStatement("%S to %T(", type, Symbols.FieldPolicies) + withIndent { + addStatement("fieldPolicies = mapOf(") + withIndent { + fieldPolicies.fieldPolicies.forEach { (fieldName, fieldPolicy) -> + addStatement("%S to %T(", fieldName, Symbols.FieldPolicy) + withIndent { + addStatement("keyArgs = listOf(") + fieldPolicy.keyArgs.forEach { keyArg -> + withIndent { + addStatement("%S, ", keyArg) + } + } + add("),\n") + } + add("),\n") + } + } + add("),\n") + } + addStatement("),") + } + } + add(")") + } + .build() + } + return PropertySpec.builder( + name = "fieldPolicies", + type = MAP.parameterizedBy(STRING, Symbols.FieldPolicies) + ) + .initializer(initializer) + .build() + } + private fun embeddedFieldsProperty(embeddedFields: Map): PropertySpec { val initializer = if (embeddedFields.isEmpty()) { CodeBlock.of("emptyMap()") @@ -201,7 +248,7 @@ internal class CacheSchemaCodeGenerator( embeddedFields.forEach { (type, embeddedField) -> addStatement("%S to %T(", type, Symbols.EmbeddedFields) withIndent { - addStatement("embeddedFields = setOf(") + addStatement("embeddedFields = listOf(") withIndent { embeddedField.embeddedFields.forEach { embeddedField -> addStatement("%S, ", embeddedField) @@ -250,6 +297,7 @@ internal class CacheSchemaCodeGenerator( "return %M(\n⇥" + "normalizedCacheFactory = normalizedCacheFactory,\n" + "typePolicies = typePolicies,\n" + + "fieldPolicies = fieldPolicies,\n" + "connectionTypes = connectionTypes, \n" + "embeddedFields = embeddedFields, \n" + "maxAges = maxAges,\n" + @@ -260,7 +308,7 @@ internal class CacheSchemaCodeGenerator( ")", Symbols.NormalisedCacheExtension, ) - .build() + .build(), ) .build() } diff --git a/normalized-cache-apollo-compiler-plugin/src/main/kotlin/com/apollographql/cache/apollocompilerplugin/internal/GQLUtils.kt b/normalized-cache-apollo-compiler-plugin/src/main/kotlin/com/apollographql/cache/apollocompilerplugin/internal/GQLUtils.kt index 24b19ac40..b77190603 100644 --- a/normalized-cache-apollo-compiler-plugin/src/main/kotlin/com/apollographql/cache/apollocompilerplugin/internal/GQLUtils.kt +++ b/normalized-cache-apollo-compiler-plugin/src/main/kotlin/com/apollographql/cache/apollocompilerplugin/internal/GQLUtils.kt @@ -16,13 +16,15 @@ internal val GQLTypeDefinition.fields else -> emptyList() } -internal fun GQLDirective.extractFields(argumentName: String): Set { +internal fun GQLDirective.extractFields(argumentName: String): List { return (((arguments.singleOrNull { it.name == argumentName }?.value as? GQLStringValue)?.value ?: "") .parseAsGQLSelections().value?.map { gqlSelection -> if (gqlSelection !is GQLField) { - throw SourceAwareException("Apollo: $argumentName values should be field selections", sourceLocation) + throw SourceAwareException("Apollo: $argumentName values must be field selections", sourceLocation) + } + if (gqlSelection.selections.isNotEmpty()) { + throw SourceAwareException("Apollo: composite fields are not supported in $argumentName", sourceLocation) } gqlSelection.name - } ?: throw SourceAwareException("Apollo: $argumentName should be a selectionSet", sourceLocation)) - .toSet() + } ?: throw SourceAwareException("Apollo: $argumentName must be a selectionSet", sourceLocation)) } diff --git a/normalized-cache-apollo-compiler-plugin/src/main/kotlin/com/apollographql/cache/apollocompilerplugin/internal/getEmbeddedFields.kt b/normalized-cache-apollo-compiler-plugin/src/main/kotlin/com/apollographql/cache/apollocompilerplugin/internal/getEmbeddedFields.kt index 9d6657d8d..efbf1b5bf 100644 --- a/normalized-cache-apollo-compiler-plugin/src/main/kotlin/com/apollographql/cache/apollocompilerplugin/internal/getEmbeddedFields.kt +++ b/normalized-cache-apollo-compiler-plugin/src/main/kotlin/com/apollographql/cache/apollocompilerplugin/internal/getEmbeddedFields.kt @@ -6,7 +6,7 @@ import com.apollographql.apollo.ast.Schema import com.apollographql.apollo.ast.rawType internal data class EmbeddedFields( - val embeddedFields: Set, + val embeddedFields: List, ) internal fun Schema.getEmbeddedFields( @@ -14,20 +14,20 @@ internal fun Schema.getEmbeddedFields( connectionTypes: Set, ): Map { // Fields manually specified as embedded - val embeddedFields: Map> = typePolicies + val embeddedFields: Map> = typePolicies .filter { it.value.embeddedFields.isNotEmpty() } .mapValues { it.value.embeddedFields } // Fields that are of a connection type - val connectionFields: Map> = getConnectionFields(connectionTypes) + val connectionFields: Map> = getConnectionFields(connectionTypes) // Specific Connection type fields - val connectionTypeFields: Map> = connectionTypes.associateWith { setOf("edges", "pageInfo") } + val connectionTypeFields: Map> = connectionTypes.associateWith { listOf("edges", "pageInfo") } // Merge all return (embeddedFields.entries + connectionFields.entries + connectionTypeFields.entries) .groupBy({ it.key }, { it.value }) - .mapValues { entry -> EmbeddedFields(entry.value.flatten().toSet()) } + .mapValues { entry -> EmbeddedFields(entry.value.flatten().distinct()) } } -private fun Schema.getConnectionFields(connectionTypes: Set): Map> { +private fun Schema.getConnectionFields(connectionTypes: Set): Map> { return typeDefinitions.values .filter { it is GQLObjectTypeDefinition || it is GQLInterfaceTypeDefinition } .mapNotNull { typeDefinition -> @@ -38,7 +38,7 @@ private fun Schema.getConnectionFields(connectionTypes: Set): Map, +) { + internal data class FieldPolicy( + val keyArgs: List, + ) +} + +/** + * Returns the field policies for object types in the schema. + */ +internal fun Schema.getFieldPolicies(): Map { + @Suppress("UNCHECKED_CAST") + return typeDefinitions.values + .filterIsInstance() + .associate { + it.name to validateAndComputeFieldPolicies(it) + } + .filterValues { it != null } + .mapValues { FieldPolicies(it.value!!) } +} + +private fun Schema.validateAndComputeFieldPolicies(typeDefinition: GQLObjectTypeDefinition): Map? { + val fieldPolicyDirectives = typeDefinition.directives.filter { originalDirectiveName(it.name) == FIELD_POLICY }.ifEmpty { return null } + val fieldPolicies = fieldPolicyDirectives.associate { it.toFieldPolicy() } + for ((fieldName, keyArgs) in fieldPolicies) { + val field = typeDefinition.fields.singleOrNull { it.name == fieldName } + if (field == null) { + throw SourceAwareException("Apollo: unknown field '${typeDefinition.name}.$fieldName' in @fieldPolicy", typeDefinition.sourceLocation) + } + for (keyArg in keyArgs.keyArgs) { + if (field.arguments.none { it.name == keyArg }) { + throw SourceAwareException("Apollo: unknown argument '${typeDefinition.name}.$fieldName($keyArg:)' in @fieldPolicy", typeDefinition.sourceLocation) + } + } + } + return fieldPolicies +} + +private fun GQLDirective.toFieldPolicy(): Pair { + val forField = (arguments.singleOrNull { it.name == "forField" }?.value as? GQLStringValue)?.value + ?: throw SourceAwareException("Apollo: missing or wrong type 'forField' argument in @fieldPolicy", sourceLocation) + return forField to FieldPolicy(extractFields("keyArgs")) +} diff --git a/normalized-cache-apollo-compiler-plugin/src/main/kotlin/com/apollographql/cache/apollocompilerplugin/internal/getTypePolicies.kt b/normalized-cache-apollo-compiler-plugin/src/main/kotlin/com/apollographql/cache/apollocompilerplugin/internal/getTypePolicies.kt index bf5c2f0fa..f25d89081 100644 --- a/normalized-cache-apollo-compiler-plugin/src/main/kotlin/com/apollographql/cache/apollocompilerplugin/internal/getTypePolicies.kt +++ b/normalized-cache-apollo-compiler-plugin/src/main/kotlin/com/apollographql/cache/apollocompilerplugin/internal/getTypePolicies.kt @@ -9,8 +9,8 @@ import com.apollographql.apollo.ast.Schema.Companion.TYPE_POLICY import com.apollographql.apollo.ast.SourceAwareException internal data class TypePolicy( - val keyFields: Set, - val embeddedFields: Set, + val keyFields: List, + val embeddedFields: List, ) /** diff --git a/normalized-cache-apollo-compiler-plugin/src/test/kotlin/com/apollographql/cache/apollocompilerplugin/internal/AddKeyFieldsExecutableDocumentTransformTest.kt b/normalized-cache-apollo-compiler-plugin/src/test/kotlin/com/apollographql/cache/apollocompilerplugin/internal/AddKeyFieldsExecutableDocumentTransformTest.kt index 20c91c0f3..ff5ed3021 100644 --- a/normalized-cache-apollo-compiler-plugin/src/test/kotlin/com/apollographql/cache/apollocompilerplugin/internal/AddKeyFieldsExecutableDocumentTransformTest.kt +++ b/normalized-cache-apollo-compiler-plugin/src/test/kotlin/com/apollographql/cache/apollocompilerplugin/internal/AddKeyFieldsExecutableDocumentTransformTest.kt @@ -1,4 +1,5 @@ @file:OptIn(ApolloExperimental::class) +@file:Suppress("ApolloMissingGraphQLDefinitionImport", "GraphQLUnresolvedReference") package com.apollographql.cache.apollocompilerplugin.internal @@ -71,7 +72,7 @@ class AddKeyFieldsExecutableDocumentTransformTest { interface HasID @typePolicy(keyFields: "id") { id: ID! } - + interface User implements HasID { id: ID! name: String! diff --git a/normalized-cache-apollo-compiler-plugin/src/test/kotlin/com/apollographql/cache/apollocompilerplugin/internal/GetConnectionTypesTest.kt b/normalized-cache-apollo-compiler-plugin/src/test/kotlin/com/apollographql/cache/apollocompilerplugin/internal/GetConnectionTypesTest.kt index 728aed417..dfcbfba87 100644 --- a/normalized-cache-apollo-compiler-plugin/src/test/kotlin/com/apollographql/cache/apollocompilerplugin/internal/GetConnectionTypesTest.kt +++ b/normalized-cache-apollo-compiler-plugin/src/test/kotlin/com/apollographql/cache/apollocompilerplugin/internal/GetConnectionTypesTest.kt @@ -1,4 +1,5 @@ @file:OptIn(ApolloExperimental::class) +@file:Suppress("ApolloMissingGraphQLDefinitionImport", "GraphQLUnresolvedReference") package com.apollographql.cache.apollocompilerplugin.internal diff --git a/normalized-cache-apollo-compiler-plugin/src/test/kotlin/com/apollographql/cache/apollocompilerplugin/internal/GetEmbeddedFieldsTest.kt b/normalized-cache-apollo-compiler-plugin/src/test/kotlin/com/apollographql/cache/apollocompilerplugin/internal/GetEmbeddedFieldsTest.kt index 93bb02d3b..2027b1b14 100644 --- a/normalized-cache-apollo-compiler-plugin/src/test/kotlin/com/apollographql/cache/apollocompilerplugin/internal/GetEmbeddedFieldsTest.kt +++ b/normalized-cache-apollo-compiler-plugin/src/test/kotlin/com/apollographql/cache/apollocompilerplugin/internal/GetEmbeddedFieldsTest.kt @@ -1,4 +1,5 @@ @file:OptIn(ApolloExperimental::class) +@file:Suppress("ApolloMissingGraphQLDefinitionImport", "GraphQLUnresolvedReference") package com.apollographql.cache.apollocompilerplugin.internal @@ -72,9 +73,9 @@ class GetEmbeddedFieldsTest { val connectionTypes = schema.getConnectionTypes() val embeddedFields = schema.getEmbeddedFields(typePolicies, connectionTypes) val expected = mapOf( - "Query" to EmbeddedFields(setOf("users")), - "User" to EmbeddedFields(setOf("name", "email")), - "UserConnection" to EmbeddedFields(setOf("edges", "pageInfo")), + "Query" to EmbeddedFields(listOf("users")), + "User" to EmbeddedFields(listOf("name", "email")), + "UserConnection" to EmbeddedFields(listOf("edges", "pageInfo")), ) assertEquals(expected, embeddedFields) } @@ -102,9 +103,9 @@ class GetEmbeddedFieldsTest { val connectionTypes = schema.getConnectionTypes() val embeddedFields = schema.getEmbeddedFields(typePolicies, connectionTypes) val expected = mapOf( - "Query" to EmbeddedFields(setOf("users")), - "User" to EmbeddedFields(setOf("name", "email")), - "UserConnection" to EmbeddedFields(setOf("edges", "pageInfo")), + "Query" to EmbeddedFields(listOf("users")), + "User" to EmbeddedFields(listOf("name", "email")), + "UserConnection" to EmbeddedFields(listOf("edges", "pageInfo")), ) assertEquals(expected, embeddedFields) } diff --git a/normalized-cache-apollo-compiler-plugin/src/test/kotlin/com/apollographql/cache/apollocompilerplugin/internal/GetFieldPoliciesTest.kt b/normalized-cache-apollo-compiler-plugin/src/test/kotlin/com/apollographql/cache/apollocompilerplugin/internal/GetFieldPoliciesTest.kt new file mode 100644 index 000000000..0010bdf60 --- /dev/null +++ b/normalized-cache-apollo-compiler-plugin/src/test/kotlin/com/apollographql/cache/apollocompilerplugin/internal/GetFieldPoliciesTest.kt @@ -0,0 +1,113 @@ +@file:OptIn(ApolloExperimental::class) +@file:Suppress("ApolloMissingGraphQLDefinitionImport", "GraphQLUnresolvedReference") + +package com.apollographql.cache.apollocompilerplugin.internal + +import com.apollographql.apollo.annotations.ApolloExperimental +import com.apollographql.apollo.ast.builtinForeignSchemas +import com.apollographql.apollo.ast.internal.SchemaValidationOptions +import com.apollographql.apollo.ast.parseAsGQLDocument +import com.apollographql.apollo.ast.validateAsSchema +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertFails + +class GetFieldPoliciesTest { + @Test + fun simpleTypePolicies() { + // language=GraphQL + val schema = """ + type Query { + user(id: ID!): User + animal(kingdom: String!, species: String!): Animal + } + + type User @typePolicy(keyFields: "id") { + id: ID! + } + + interface Animal @typePolicy(keyFields: "kingdom species") { + kingdom: String! + species: String! + } + + extend type Query + @fieldPolicy(forField: "user", keyArgs: "id") + @fieldPolicy(forField: "animal", keyArgs: "kingdom species") + """.trimIndent() + .parseAsGQLDocument().getOrThrow() + .validateAsSchema( + SchemaValidationOptions( + addKotlinLabsDefinitions = true, + foreignSchemas = builtinForeignSchemas() + cacheForeignSchema, + ), + ).getOrThrow() + + val expected = mapOf( + "Query" to FieldPolicies( + fieldPolicies = mapOf( + "user" to FieldPolicies.FieldPolicy( + keyArgs = listOf("id"), + ), + "animal" to FieldPolicies.FieldPolicy( + keyArgs = listOf("kingdom", "species"), + ), + ), + ), + ) + + assertEquals(expected, schema.getFieldPolicies()) + } + + @Test + fun unknownField() { + // language=GraphQL + val schema = """ + type Query { + user(id: ID!): User + } + + type User @typePolicy(keyFields: "id") { + id: ID! + } + + extend type Query + @fieldPolicy(forField: "unknownField", keyArgs: "id") + """.trimIndent() + .parseAsGQLDocument().getOrThrow() + .validateAsSchema( + SchemaValidationOptions( + addKotlinLabsDefinitions = true, + foreignSchemas = builtinForeignSchemas() + cacheForeignSchema, + ), + ).getOrThrow() + + assertFails("null: (1, 1): Apollo: unknown field 'Query.unknownField' in @fieldPolicy") { schema.getFieldPolicies() } + } + + @Test + fun unknownArgument() { + // language=GraphQL + val schema = """ + type Query { + user(id: ID!): User + } + + type User @typePolicy(keyFields: "id") { + id: ID! + } + + extend type Query + @fieldPolicy(forField: "user", keyArgs: "id unknownArg") + """.trimIndent() + .parseAsGQLDocument().getOrThrow() + .validateAsSchema( + SchemaValidationOptions( + addKotlinLabsDefinitions = true, + foreignSchemas = builtinForeignSchemas() + cacheForeignSchema, + ), + ).getOrThrow() + + assertFails("null: (1, 1): Apollo: unknown argument 'Query.user(unknownArg:)' in @fieldPolicy") { schema.getFieldPolicies() } + } +} diff --git a/normalized-cache-apollo-compiler-plugin/src/test/kotlin/com/apollographql/cache/apollocompilerplugin/internal/GetMaxAgesTest.kt b/normalized-cache-apollo-compiler-plugin/src/test/kotlin/com/apollographql/cache/apollocompilerplugin/internal/GetMaxAgesTest.kt index 6447c2cb2..c58359819 100644 --- a/normalized-cache-apollo-compiler-plugin/src/test/kotlin/com/apollographql/cache/apollocompilerplugin/internal/GetMaxAgesTest.kt +++ b/normalized-cache-apollo-compiler-plugin/src/test/kotlin/com/apollographql/cache/apollocompilerplugin/internal/GetMaxAgesTest.kt @@ -1,4 +1,5 @@ @file:OptIn(ApolloExperimental::class) +@file:Suppress("ApolloMissingGraphQLDefinitionImport", "GraphQLUnresolvedReference") package com.apollographql.cache.apollocompilerplugin.internal @@ -16,6 +17,7 @@ import kotlin.test.fail class GetMaxAgesTest { @Test fun basic() { + // language=GraphQL val schemaText = """ schema { query: Query @@ -91,35 +93,36 @@ class GetMaxAgesTest { @Test fun validationErrors() { + // language=GraphQL val schemaText = """ schema { query: Query } - + extend schema @link( url: "https://specs.apollo.dev/cache/v0.3", import: ["@cacheControl", "@cacheControlField"] ) - + type Query { book: Book cachedBook: Book @cacheControl(maxAge: 60, inheritMaxAge: true) reader: Reader @cacheControl(maxAge: 40, inheritMaxAge: false) } - + type Book @cacheControl(maxAge: 50, inheritMaxAge: true) { title: String } - + type Reader @cacheControl(maxAge: 50, inheritMaxAge: false){ book: Book } - + type Publisher { id: ID! name: String! } - + extend type Publisher @cacheControlField(name: "name", maxAge: 20, inheritMaxAge: true) @cacheControlField(name: "id", maxAge: 20, inheritMaxAge: false) diff --git a/normalized-cache-apollo-compiler-plugin/src/test/kotlin/com/apollographql/cache/apollocompilerplugin/internal/GetTypePoliciesTest.kt b/normalized-cache-apollo-compiler-plugin/src/test/kotlin/com/apollographql/cache/apollocompilerplugin/internal/GetTypePoliciesTest.kt index e3efe3a5c..194cb9925 100644 --- a/normalized-cache-apollo-compiler-plugin/src/test/kotlin/com/apollographql/cache/apollocompilerplugin/internal/GetTypePoliciesTest.kt +++ b/normalized-cache-apollo-compiler-plugin/src/test/kotlin/com/apollographql/cache/apollocompilerplugin/internal/GetTypePoliciesTest.kt @@ -1,4 +1,5 @@ @file:OptIn(ApolloExperimental::class) +@file:Suppress("ApolloMissingGraphQLDefinitionImport", "GraphQLUnresolvedReference") package com.apollographql.cache.apollocompilerplugin.internal @@ -58,12 +59,12 @@ class GetTypePoliciesTest { ).getOrThrow() val expected = mapOf( - "User" to TypePolicy(keyFields = setOf("id"), embeddedFields = emptySet()), - "Animal" to TypePolicy(keyFields = setOf("kingdom", "species"), embeddedFields = emptySet()), - "Lion" to TypePolicy(keyFields = setOf("kingdom", "species"), embeddedFields = emptySet()), - "HasId" to TypePolicy(keyFields = setOf("id"), embeddedFields = emptySet()), - "Circle" to TypePolicy(keyFields = setOf("id"), embeddedFields = emptySet()), - "Square" to TypePolicy(keyFields = setOf("radius"), embeddedFields = emptySet()), + "User" to TypePolicy(keyFields = listOf("id"), embeddedFields = emptyList()), + "Animal" to TypePolicy(keyFields = listOf("kingdom", "species"), embeddedFields = emptyList()), + "Lion" to TypePolicy(keyFields = listOf("kingdom", "species"), embeddedFields = emptyList()), + "HasId" to TypePolicy(keyFields = listOf("id"), embeddedFields = emptyList()), + "Circle" to TypePolicy(keyFields = listOf("id"), embeddedFields = emptyList()), + "Square" to TypePolicy(keyFields = listOf("radius"), embeddedFields = emptyList()), ) assertEquals(expected, schema.getTypePolicies()) diff --git a/normalized-cache-sqlite/api/android/normalized-cache-sqlite.api b/normalized-cache-sqlite/api/android/normalized-cache-sqlite.api index ad9c82852..23861ec42 100644 --- a/normalized-cache-sqlite/api/android/normalized-cache-sqlite.api +++ b/normalized-cache-sqlite/api/android/normalized-cache-sqlite.api @@ -26,11 +26,6 @@ public final class com/apollographql/cache/normalized/sql/SqlNormalizedCacheFact } public final class com/apollographql/cache/normalized/sql/SqlNormalizedCacheFactory_androidKt { - public static final fun SqlNormalizedCacheFactory (Landroid/content/Context;)Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory; - public static final fun SqlNormalizedCacheFactory (Landroid/content/Context;Ljava/lang/String;)Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory; - public static final fun SqlNormalizedCacheFactory (Landroid/content/Context;Ljava/lang/String;Landroidx/sqlite/db/SupportSQLiteOpenHelper$Factory;)Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory; - public static final fun SqlNormalizedCacheFactory (Landroid/content/Context;Ljava/lang/String;Landroidx/sqlite/db/SupportSQLiteOpenHelper$Factory;Lkotlin/jvm/functions/Function1;)Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory; - public static final fun SqlNormalizedCacheFactory (Landroid/content/Context;Ljava/lang/String;Landroidx/sqlite/db/SupportSQLiteOpenHelper$Factory;Lkotlin/jvm/functions/Function1;Z)Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory; public static final fun SqlNormalizedCacheFactory (Landroid/content/Context;Ljava/lang/String;Landroidx/sqlite/db/SupportSQLiteOpenHelper$Factory;Lkotlin/jvm/functions/Function1;ZLjava/lang/Long;)Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory; public static final fun SqlNormalizedCacheFactory (Ljava/lang/String;)Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory; public static synthetic fun SqlNormalizedCacheFactory$default (Landroid/content/Context;Ljava/lang/String;Landroidx/sqlite/db/SupportSQLiteOpenHelper$Factory;Lkotlin/jvm/functions/Function1;ZLjava/lang/Long;ILjava/lang/Object;)Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory; diff --git a/normalized-cache-sqlite/src/androidMain/kotlin/com/apollographql/cache/normalized/sql/SqlNormalizedCacheFactory.android.kt b/normalized-cache-sqlite/src/androidMain/kotlin/com/apollographql/cache/normalized/sql/SqlNormalizedCacheFactory.android.kt index 0a04d0309..990bfae5a 100644 --- a/normalized-cache-sqlite/src/androidMain/kotlin/com/apollographql/cache/normalized/sql/SqlNormalizedCacheFactory.android.kt +++ b/normalized-cache-sqlite/src/androidMain/kotlin/com/apollographql/cache/normalized/sql/SqlNormalizedCacheFactory.android.kt @@ -22,7 +22,6 @@ actual fun SqlNormalizedCacheFactory(name: String?): NormalizedCacheFactory = * @param useNoBackupDirectory Sets whether to use a no backup directory or not. * @param windowSizeBytes Size of cursor window in bytes, per [android.database.CursorWindow] (Android 28+ only), or null to use the default. */ -@JvmOverloads fun SqlNormalizedCacheFactory( context: Context, name: String? = "apollo.db", 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 f6eb0febc..76f7df0d9 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 @@ -3,6 +3,8 @@ package com.apollographql.cache.normalized.sql 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.DefaultCacheKeyGenerator +import com.apollographql.cache.normalized.api.DefaultCacheResolver import com.apollographql.cache.normalized.api.DefaultRecordMerger import com.apollographql.cache.normalized.api.Record import com.apollographql.cache.normalized.api.withDates @@ -14,7 +16,7 @@ import kotlin.test.assertNull class TrimTest { @Test fun trimTest() = runTest { - val cacheManager = CacheManager(SqlNormalizedCacheFactory()).also { it.clearAll() } + val cacheManager = CacheManager(SqlNormalizedCacheFactory(), DefaultCacheKeyGenerator, DefaultCacheResolver).also { it.clearAll() } val largeString = "".padStart(1024, '?') diff --git a/normalized-cache/api/normalized-cache.api b/normalized-cache/api/normalized-cache.api index 2d15cb529..67292dbf1 100644 --- a/normalized-cache/api/normalized-cache.api +++ b/normalized-cache/api/normalized-cache.api @@ -131,8 +131,8 @@ public final class com/apollographql/cache/normalized/CacheManager$ReadResult { } 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;Z)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;ZILjava/lang/Object;)Lcom/apollographql/cache/normalized/CacheManager; + public static final fun CacheManager (Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory;Lcom/apollographql/cache/normalized/api/CacheKeyGenerator;Lcom/apollographql/cache/normalized/api/CacheResolver;Lcom/apollographql/cache/normalized/api/MetadataGenerator;Lcom/apollographql/cache/normalized/api/RecordMerger;Lcom/apollographql/cache/normalized/api/FieldKeyGenerator;Lcom/apollographql/cache/normalized/api/EmbeddedFieldsProvider;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;Z)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/CacheResolver;Lcom/apollographql/cache/normalized/api/MetadataGenerator;Lcom/apollographql/cache/normalized/api/RecordMerger;Lcom/apollographql/cache/normalized/api/FieldKeyGenerator;Lcom/apollographql/cache/normalized/api/EmbeddedFieldsProvider;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;ZILjava/lang/Object;)Lcom/apollographql/cache/normalized/CacheManager; } public final class com/apollographql/cache/normalized/CacheMissLoggingInterceptor : com/apollographql/apollo/interceptor/ApolloInterceptor { @@ -140,6 +140,20 @@ public final class com/apollographql/cache/normalized/CacheMissLoggingIntercepto public fun intercept (Lcom/apollographql/apollo/api/ApolloRequest;Lcom/apollographql/apollo/interceptor/ApolloInterceptorChain;)Lkotlinx/coroutines/flow/Flow; } +public final class com/apollographql/cache/normalized/ClientCacheExtensionsKt { + 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 getApolloStore (Lcom/apollographql/apollo/ApolloClient;)Lcom/apollographql/cache/normalized/ApolloStore; + public static final fun logCacheMisses (Lcom/apollographql/apollo/ApolloClient$Builder;Lkotlin/jvm/functions/Function1;)Lcom/apollographql/apollo/ApolloClient$Builder; + public static synthetic fun logCacheMisses$default (Lcom/apollographql/apollo/ApolloClient$Builder;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcom/apollographql/apollo/ApolloClient$Builder; + public static final fun normalizedCache (Lcom/apollographql/apollo/ApolloClient$Builder;Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory;Lcom/apollographql/cache/normalized/api/CacheKeyGenerator;Lcom/apollographql/cache/normalized/api/CacheResolver;Lcom/apollographql/cache/normalized/api/MetadataGenerator;Lcom/apollographql/cache/normalized/api/RecordMerger;Lcom/apollographql/cache/normalized/api/FieldKeyGenerator;Lcom/apollographql/cache/normalized/api/EmbeddedFieldsProvider;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;ZZ)Lcom/apollographql/apollo/ApolloClient$Builder; + public static final fun normalizedCache (Lcom/apollographql/apollo/ApolloClient$Builder;Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory;Ljava/util/Map;Ljava/util/Map;Lcom/apollographql/cache/normalized/api/MetadataGenerator;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/api/CacheKey$Scope;ZZ)Lcom/apollographql/apollo/ApolloClient$Builder; + public static synthetic fun normalizedCache$default (Lcom/apollographql/apollo/ApolloClient$Builder;Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory;Lcom/apollographql/cache/normalized/api/CacheKeyGenerator;Lcom/apollographql/cache/normalized/api/CacheResolver;Lcom/apollographql/cache/normalized/api/MetadataGenerator;Lcom/apollographql/cache/normalized/api/RecordMerger;Lcom/apollographql/cache/normalized/api/FieldKeyGenerator;Lcom/apollographql/cache/normalized/api/EmbeddedFieldsProvider;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;ZZILjava/lang/Object;)Lcom/apollographql/apollo/ApolloClient$Builder; + public static synthetic fun normalizedCache$default (Lcom/apollographql/apollo/ApolloClient$Builder;Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory;Ljava/util/Map;Ljava/util/Map;Lcom/apollographql/cache/normalized/api/MetadataGenerator;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/api/CacheKey$Scope;ZZILjava/lang/Object;)Lcom/apollographql/apollo/ApolloClient$Builder; + public static final fun normalizedCache-PTSDy14 (Lcom/apollographql/apollo/ApolloClient$Builder;Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory;Ljava/util/Map;Ljava/util/Map;Ljava/util/Set;Ljava/util/Map;Ljava/util/Map;JLcom/apollographql/cache/normalized/api/CacheKey$Scope;ZZ)Lcom/apollographql/apollo/ApolloClient$Builder; + public static final fun storePartialResponses (Lcom/apollographql/apollo/api/MutableExecutionOptions;Z)Ljava/lang/Void; +} + public final class com/apollographql/cache/normalized/ClockKt { public static final fun clock (Lcom/apollographql/apollo/api/MutableExecutionOptions;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object; } @@ -172,7 +186,7 @@ public final class com/apollographql/cache/normalized/FetchPolicy : java/lang/En public static fun values ()[Lcom/apollographql/cache/normalized/FetchPolicy; } -public final class com/apollographql/cache/normalized/FetchPolicyInterceptors { +public final class com/apollographql/cache/normalized/FetchPolicyInterceptorsKt { public static final fun errorsAsException (Lcom/apollographql/apollo/api/ApolloResponse;)Lcom/apollographql/apollo/api/ApolloResponse; public static final fun getCacheAndNetworkInterceptor ()Lcom/apollographql/apollo/interceptor/ApolloInterceptor; public static final fun getDefaultFetchPolicyInterceptor ()Lcom/apollographql/apollo/interceptor/ApolloInterceptor; @@ -212,27 +226,6 @@ public final class com/apollographql/cache/normalized/MemoryCacheOnlyKt { public static final fun memoryCacheOnly (Lcom/apollographql/apollo/api/MutableExecutionOptions;Z)Ljava/lang/Object; } -public final class com/apollographql/cache/normalized/NormalizedCache { - public static final fun -logCacheMisses (Lcom/apollographql/apollo/ApolloClient$Builder;Lkotlin/jvm/functions/Function1;)Lcom/apollographql/apollo/ApolloClient$Builder; - public static synthetic fun -logCacheMisses$default (Lcom/apollographql/apollo/ApolloClient$Builder;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcom/apollographql/apollo/ApolloClient$Builder; - 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; - 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/cache/normalized/api/CacheResolver;)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/cache/normalized/api/CacheResolver;Lcom/apollographql/cache/normalized/api/RecordMerger;)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/cache/normalized/api/CacheResolver;Lcom/apollographql/cache/normalized/api/RecordMerger;Lcom/apollographql/cache/normalized/api/FieldKeyGenerator;)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/cache/normalized/api/CacheResolver;Lcom/apollographql/cache/normalized/api/RecordMerger;Lcom/apollographql/cache/normalized/api/FieldKeyGenerator;Lcom/apollographql/cache/normalized/api/EmbeddedFieldsProvider;)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/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/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/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;Z)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/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;ZZ)Lcom/apollographql/apollo/ApolloClient$Builder; - public static synthetic fun configureApolloClientBuilder2$default (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/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;ZZILjava/lang/Object;)Lcom/apollographql/apollo/ApolloClient$Builder; - public static final fun getApolloStore (Lcom/apollographql/apollo/ApolloClient;)Lcom/apollographql/cache/normalized/ApolloStore; - public static final fun normalizedCache-mLShkvk (Lcom/apollographql/apollo/ApolloClient$Builder;Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory;Ljava/util/Map;Ljava/util/Set;Ljava/util/Map;Ljava/util/Map;JLcom/apollographql/cache/normalized/api/CacheKey$Scope;ZZ)Lcom/apollographql/apollo/ApolloClient$Builder; - public static final fun storePartialResponses (Lcom/apollographql/apollo/api/MutableExecutionOptions;Z)Ljava/lang/Void; -} - public final class com/apollographql/cache/normalized/OptimisticUpdatesKt { public static final fun optimisticUpdates (Lcom/apollographql/apollo/ApolloCall;Lcom/apollographql/apollo/api/Mutation$Data;)Lcom/apollographql/apollo/ApolloCall; public static final fun optimisticUpdates (Lcom/apollographql/apollo/api/ApolloRequest$Builder;Lcom/apollographql/apollo/api/Mutation$Data;)Lcom/apollographql/apollo/api/ApolloRequest$Builder; @@ -285,10 +278,8 @@ public final class com/apollographql/cache/normalized/api/ApolloCacheHeaders { } public final class com/apollographql/cache/normalized/api/CacheControlCacheResolver : com/apollographql/cache/normalized/api/CacheResolver { - public fun (Lcom/apollographql/cache/normalized/api/CacheResolver;)V - public synthetic fun (Lcom/apollographql/cache/normalized/api/CacheResolver;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public fun (Lcom/apollographql/cache/normalized/api/MaxAgeProvider;Lcom/apollographql/cache/normalized/api/CacheResolver;)V - public synthetic fun (Lcom/apollographql/cache/normalized/api/MaxAgeProvider;Lcom/apollographql/cache/normalized/api/CacheResolver;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun (Lcom/apollographql/cache/normalized/api/MaxAgeProvider;Ljava/util/Map;)V public fun resolveField (Lcom/apollographql/cache/normalized/api/ResolverContext;)Ljava/lang/Object; } @@ -355,12 +346,6 @@ public final class com/apollographql/cache/normalized/api/CacheKeyGeneratorConte public final fun getVariables ()Lcom/apollographql/apollo/api/Executable$Variables; } -public final class com/apollographql/cache/normalized/api/CacheKeyGeneratorKt { - public static final fun TypePolicyCacheKeyGenerator (Ljava/util/Map;Lcom/apollographql/cache/normalized/api/CacheKey$Scope;)Lcom/apollographql/cache/normalized/api/CacheKeyGenerator; - public static synthetic fun TypePolicyCacheKeyGenerator$default (Ljava/util/Map;Lcom/apollographql/cache/normalized/api/CacheKey$Scope;ILjava/lang/Object;)Lcom/apollographql/cache/normalized/api/CacheKeyGenerator; - public static final fun getTypePolicyCacheKeyGenerator ()Lcom/apollographql/cache/normalized/api/CacheKeyGenerator; -} - public abstract class com/apollographql/cache/normalized/api/CacheKeyResolver : com/apollographql/cache/normalized/api/CacheResolver { public fun ()V public abstract fun cacheKeyForField-fLoEQYY (Lcom/apollographql/cache/normalized/api/ResolverContext;)Ljava/lang/String; @@ -379,11 +364,11 @@ public final class com/apollographql/cache/normalized/api/CacheResolver$Resolved } public final class com/apollographql/cache/normalized/api/CacheResolverKt { - public static final fun FieldPolicyCacheResolver (Lcom/apollographql/cache/normalized/api/CacheKey$Scope;)Lcom/apollographql/cache/normalized/api/CacheResolver; - public static synthetic fun FieldPolicyCacheResolver$default (Lcom/apollographql/cache/normalized/api/CacheKey$Scope;ILjava/lang/Object;)Lcom/apollographql/cache/normalized/api/CacheResolver; + public static final fun FieldPolicyCacheResolver (Ljava/util/Map;Lcom/apollographql/cache/normalized/api/CacheKey$Scope;)Lcom/apollographql/cache/normalized/api/CacheResolver; + public static synthetic fun FieldPolicyCacheResolver$default (Ljava/util/Map;Lcom/apollographql/cache/normalized/api/CacheKey$Scope;ILjava/lang/Object;)Lcom/apollographql/cache/normalized/api/CacheResolver; + public static final fun IdCacheResolver (Ljava/util/List;Lcom/apollographql/cache/normalized/api/CacheKey$Scope;)Lcom/apollographql/cache/normalized/api/CacheResolver; + public static synthetic fun IdCacheResolver$default (Ljava/util/List;Lcom/apollographql/cache/normalized/api/CacheKey$Scope;ILjava/lang/Object;)Lcom/apollographql/cache/normalized/api/CacheResolver; public static final fun getFieldKey (Lcom/apollographql/cache/normalized/api/ResolverContext;)Ljava/lang/String; - public static final fun getFieldPolicyCacheResolver ()Lcom/apollographql/cache/normalized/api/CacheResolver; - public static final fun listItemsInParent (Lcom/apollographql/cache/normalized/api/ResolverContext;Ljava/lang/String;)Ljava/util/Map; } public final class com/apollographql/cache/normalized/api/ConnectionEmbeddedFieldsProvider : com/apollographql/cache/normalized/api/EmbeddedFieldsProvider { @@ -414,6 +399,11 @@ public final class com/apollographql/cache/normalized/api/DataWithErrorsKt { public static synthetic fun withErrors$default (Lcom/apollographql/apollo/api/Executable$Data;Lcom/apollographql/apollo/api/Executable;Ljava/util/List;Lcom/apollographql/apollo/api/CustomScalarAdapters;ILjava/lang/Object;)Ljava/util/Map; } +public final class com/apollographql/cache/normalized/api/DefaultCacheKeyGenerator : com/apollographql/cache/normalized/api/CacheKeyGenerator { + public static final field INSTANCE Lcom/apollographql/cache/normalized/api/DefaultCacheKeyGenerator; + public fun cacheKeyForObject-z2_y8R0 (Ljava/util/Map;Lcom/apollographql/cache/normalized/api/CacheKeyGeneratorContext;)Ljava/lang/String; +} + public final class com/apollographql/cache/normalized/api/DefaultCacheResolver : com/apollographql/cache/normalized/api/CacheResolver { public static final field INSTANCE Lcom/apollographql/cache/normalized/api/DefaultCacheResolver; public fun resolveField (Lcom/apollographql/cache/normalized/api/ResolverContext;)Ljava/lang/Object; @@ -435,17 +425,17 @@ public final class com/apollographql/cache/normalized/api/DefaultRecordMerger : } public final class com/apollographql/cache/normalized/api/EmbeddedFields { - public static final synthetic fun box-impl (Ljava/util/Set;)Lcom/apollographql/cache/normalized/api/EmbeddedFields; - public static fun constructor-impl (Ljava/util/Set;)Ljava/util/Set; + public static final synthetic fun box-impl (Ljava/util/List;)Lcom/apollographql/cache/normalized/api/EmbeddedFields; + public static fun constructor-impl (Ljava/util/List;)Ljava/util/List; public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl (Ljava/util/Set;Ljava/lang/Object;)Z - public static final fun equals-impl0 (Ljava/util/Set;Ljava/util/Set;)Z - public final fun getEmbeddedFields ()Ljava/util/Set; + public static fun equals-impl (Ljava/util/List;Ljava/lang/Object;)Z + public static final fun equals-impl0 (Ljava/util/List;Ljava/util/List;)Z + public final fun getEmbeddedFields ()Ljava/util/List; public fun hashCode ()I - public static fun hashCode-impl (Ljava/util/Set;)I + public static fun hashCode-impl (Ljava/util/List;)I public fun toString ()Ljava/lang/String; - public static fun toString-impl (Ljava/util/Set;)Ljava/lang/String; - public final synthetic fun unbox-impl ()Ljava/util/Set; + public static fun toString-impl (Ljava/util/List;)Ljava/lang/String; + public final synthetic fun unbox-impl ()Ljava/util/List; } public final class com/apollographql/cache/normalized/api/EmbeddedFieldsContext { @@ -480,6 +470,34 @@ public abstract interface class com/apollographql/cache/normalized/api/FieldKeyG public abstract fun getFieldKey (Lcom/apollographql/cache/normalized/api/FieldKeyContext;)Ljava/lang/String; } +public final class com/apollographql/cache/normalized/api/FieldPolicies { + public static final synthetic fun box-impl (Ljava/util/Map;)Lcom/apollographql/cache/normalized/api/FieldPolicies; + public static fun constructor-impl (Ljava/util/Map;)Ljava/util/Map; + public fun equals (Ljava/lang/Object;)Z + public static fun equals-impl (Ljava/util/Map;Ljava/lang/Object;)Z + public static final fun equals-impl0 (Ljava/util/Map;Ljava/util/Map;)Z + public final fun getFieldPolicies ()Ljava/util/Map; + public fun hashCode ()I + public static fun hashCode-impl (Ljava/util/Map;)I + public fun toString ()Ljava/lang/String; + public static fun toString-impl (Ljava/util/Map;)Ljava/lang/String; + public final synthetic fun unbox-impl ()Ljava/util/Map; +} + +public final class com/apollographql/cache/normalized/api/FieldPolicies$FieldPolicy { + public static final synthetic fun box-impl (Ljava/util/List;)Lcom/apollographql/cache/normalized/api/FieldPolicies$FieldPolicy; + public static fun constructor-impl (Ljava/util/List;)Ljava/util/List; + public fun equals (Ljava/lang/Object;)Z + public static fun equals-impl (Ljava/util/List;Ljava/lang/Object;)Z + public static final fun equals-impl0 (Ljava/util/List;Ljava/util/List;)Z + public final fun getKeyArgs ()Ljava/util/List; + public fun hashCode ()I + public static fun hashCode-impl (Ljava/util/List;)I + public fun toString ()Ljava/lang/String; + public static fun toString-impl (Ljava/util/List;)Ljava/lang/String; + public final synthetic fun unbox-impl ()Ljava/util/List; +} + public final class com/apollographql/cache/normalized/api/FieldRecordMerger : com/apollographql/cache/normalized/api/RecordMerger { public fun (Lcom/apollographql/cache/normalized/api/FieldRecordMerger$FieldMerger;)V public fun merge (Lcom/apollographql/cache/normalized/api/RecordMergerContext;)Lkotlin/Pair; @@ -514,12 +532,13 @@ public final class com/apollographql/cache/normalized/api/IdCacheKeyGenerator : public fun cacheKeyForObject-z2_y8R0 (Ljava/util/Map;Lcom/apollographql/cache/normalized/api/CacheKeyGeneratorContext;)Ljava/lang/String; } -public final class com/apollographql/cache/normalized/api/IdCacheKeyResolver : com/apollographql/cache/normalized/api/CacheKeyResolver { - public fun ()V - public fun (Ljava/util/List;Ljava/util/List;Lcom/apollographql/cache/normalized/api/CacheKey$Scope;)V - public synthetic fun (Ljava/util/List;Ljava/util/List;Lcom/apollographql/cache/normalized/api/CacheKey$Scope;ILkotlin/jvm/internal/DefaultConstructorMarker;)V - public fun cacheKeyForField-fLoEQYY (Lcom/apollographql/cache/normalized/api/ResolverContext;)Ljava/lang/String; - public fun listOfCacheKeysForField (Lcom/apollographql/cache/normalized/api/ResolverContext;)Ljava/util/List; +public final class com/apollographql/cache/normalized/api/KeyArgumentsCacheResolver : com/apollographql/cache/normalized/api/CacheResolver { + public fun (Lcom/apollographql/cache/normalized/api/KeyArgumentsProvider;Lcom/apollographql/cache/normalized/api/CacheKey$Scope;)V + public fun resolveField (Lcom/apollographql/cache/normalized/api/ResolverContext;)Ljava/lang/Object; +} + +public abstract interface class com/apollographql/cache/normalized/api/KeyArgumentsProvider { + public abstract fun getKeyArguments (Ljava/lang/String;Lcom/apollographql/apollo/api/CompiledField;)Ljava/util/List; } public abstract interface class com/apollographql/cache/normalized/api/MaxAge { @@ -699,24 +718,30 @@ public final class com/apollographql/cache/normalized/api/SchemaCoordinatesMaxAg } public final class com/apollographql/cache/normalized/api/TypePolicy { - public static final synthetic fun box-impl (Ljava/util/Set;)Lcom/apollographql/cache/normalized/api/TypePolicy; - public static fun constructor-impl (Ljava/util/Set;)Ljava/util/Set; + public static final synthetic fun box-impl (Ljava/util/List;)Lcom/apollographql/cache/normalized/api/TypePolicy; + public static fun constructor-impl (Ljava/util/List;)Ljava/util/List; public fun equals (Ljava/lang/Object;)Z - public static fun equals-impl (Ljava/util/Set;Ljava/lang/Object;)Z - public static final fun equals-impl0 (Ljava/util/Set;Ljava/util/Set;)Z - public final fun getKeyFields ()Ljava/util/Set; + public static fun equals-impl (Ljava/util/List;Ljava/lang/Object;)Z + public static final fun equals-impl0 (Ljava/util/List;Ljava/util/List;)Z + public final fun getKeyFields ()Ljava/util/List; public fun hashCode ()I - public static fun hashCode-impl (Ljava/util/Set;)I + public static fun hashCode-impl (Ljava/util/List;)I public fun toString ()Ljava/lang/String; - public static fun toString-impl (Ljava/util/Set;)Ljava/lang/String; - public final synthetic fun unbox-impl ()Ljava/util/Set; + public static fun toString-impl (Ljava/util/List;)Ljava/lang/String; + public final synthetic fun unbox-impl ()Ljava/util/List; +} + +public final class com/apollographql/cache/normalized/api/TypePolicyCacheKeyGenerator : com/apollographql/cache/normalized/api/CacheKeyGenerator { + public fun (Ljava/util/Map;Lcom/apollographql/cache/normalized/api/CacheKey$Scope;)V + public synthetic fun (Ljava/util/Map;Lcom/apollographql/cache/normalized/api/CacheKey$Scope;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun cacheKeyForObject-z2_y8R0 (Ljava/util/Map;Lcom/apollographql/cache/normalized/api/CacheKeyGeneratorContext;)Ljava/lang/String; } public final class com/apollographql/cache/normalized/internal/NormalizerKt { - public static final fun normalized-7h_XKoo (Lcom/apollographql/apollo/api/Executable$Data;Lcom/apollographql/apollo/api/Executable;Ljava/lang/String;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheKeyGenerator;Lcom/apollographql/cache/normalized/api/MetadataGenerator;Lcom/apollographql/cache/normalized/api/FieldKeyGenerator;Lcom/apollographql/cache/normalized/api/EmbeddedFieldsProvider;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;)Ljava/util/Map; - public static final fun normalized-7h_XKoo (Ljava/util/Map;Lcom/apollographql/apollo/api/Executable;Ljava/lang/String;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheKeyGenerator;Lcom/apollographql/cache/normalized/api/MetadataGenerator;Lcom/apollographql/cache/normalized/api/FieldKeyGenerator;Lcom/apollographql/cache/normalized/api/EmbeddedFieldsProvider;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;)Ljava/util/Map; - public static synthetic fun normalized-7h_XKoo$default (Lcom/apollographql/apollo/api/Executable$Data;Lcom/apollographql/apollo/api/Executable;Ljava/lang/String;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheKeyGenerator;Lcom/apollographql/cache/normalized/api/MetadataGenerator;Lcom/apollographql/cache/normalized/api/FieldKeyGenerator;Lcom/apollographql/cache/normalized/api/EmbeddedFieldsProvider;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;ILjava/lang/Object;)Ljava/util/Map; - public static synthetic fun normalized-7h_XKoo$default (Ljava/util/Map;Lcom/apollographql/apollo/api/Executable;Ljava/lang/String;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/CacheKeyGenerator;Lcom/apollographql/cache/normalized/api/MetadataGenerator;Lcom/apollographql/cache/normalized/api/FieldKeyGenerator;Lcom/apollographql/cache/normalized/api/EmbeddedFieldsProvider;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;ILjava/lang/Object;)Ljava/util/Map; + public static final fun normalized-Rh5gc5g (Lcom/apollographql/apollo/api/Executable$Data;Lcom/apollographql/apollo/api/Executable;Lcom/apollographql/cache/normalized/api/CacheKeyGenerator;Ljava/lang/String;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/MetadataGenerator;Lcom/apollographql/cache/normalized/api/FieldKeyGenerator;Lcom/apollographql/cache/normalized/api/EmbeddedFieldsProvider;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;)Ljava/util/Map; + public static final fun normalized-Rh5gc5g (Ljava/util/Map;Lcom/apollographql/apollo/api/Executable;Lcom/apollographql/cache/normalized/api/CacheKeyGenerator;Ljava/lang/String;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/MetadataGenerator;Lcom/apollographql/cache/normalized/api/FieldKeyGenerator;Lcom/apollographql/cache/normalized/api/EmbeddedFieldsProvider;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;)Ljava/util/Map; + public static synthetic fun normalized-Rh5gc5g$default (Lcom/apollographql/apollo/api/Executable$Data;Lcom/apollographql/apollo/api/Executable;Lcom/apollographql/cache/normalized/api/CacheKeyGenerator;Ljava/lang/String;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/MetadataGenerator;Lcom/apollographql/cache/normalized/api/FieldKeyGenerator;Lcom/apollographql/cache/normalized/api/EmbeddedFieldsProvider;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;ILjava/lang/Object;)Ljava/util/Map; + public static synthetic fun normalized-Rh5gc5g$default (Ljava/util/Map;Lcom/apollographql/apollo/api/Executable;Lcom/apollographql/cache/normalized/api/CacheKeyGenerator;Ljava/lang/String;Lcom/apollographql/apollo/api/CustomScalarAdapters;Lcom/apollographql/cache/normalized/api/MetadataGenerator;Lcom/apollographql/cache/normalized/api/FieldKeyGenerator;Lcom/apollographql/cache/normalized/api/EmbeddedFieldsProvider;Lcom/apollographql/cache/normalized/api/MaxAgeProvider;ILjava/lang/Object;)Ljava/util/Map; } public final class com/apollographql/cache/normalized/memory/MemoryCache : com/apollographql/cache/normalized/api/NormalizedCache { @@ -736,7 +761,6 @@ public final class com/apollographql/cache/normalized/memory/MemoryCache : com/a public final class com/apollographql/cache/normalized/memory/MemoryCacheFactory : com/apollographql/cache/normalized/api/NormalizedCacheFactory { public fun ()V - public fun (I)V public fun (IJ)V public synthetic fun (IJILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun chain (Lcom/apollographql/cache/normalized/api/NormalizedCacheFactory;)Lcom/apollographql/cache/normalized/memory/MemoryCacheFactory; diff --git a/normalized-cache/api/normalized-cache.klib.api b/normalized-cache/api/normalized-cache.klib.api index ce42499b5..7548c6ab3 100644 --- a/normalized-cache/api/normalized-cache.klib.api +++ b/normalized-cache/api/normalized-cache.klib.api @@ -45,6 +45,10 @@ abstract interface com.apollographql.cache.normalized.api/FieldKeyGenerator { // abstract fun getFieldKey(com.apollographql.cache.normalized.api/FieldKeyContext): kotlin/String // com.apollographql.cache.normalized.api/FieldKeyGenerator.getFieldKey|getFieldKey(com.apollographql.cache.normalized.api.FieldKeyContext){}[0] } +abstract interface com.apollographql.cache.normalized.api/KeyArgumentsProvider { // com.apollographql.cache.normalized.api/KeyArgumentsProvider|null[0] + abstract fun getKeyArguments(kotlin/String, com.apollographql.apollo.api/CompiledField): kotlin.collections/List // com.apollographql.cache.normalized.api/KeyArgumentsProvider.getKeyArguments|getKeyArguments(kotlin.String;com.apollographql.apollo.api.CompiledField){}[0] +} + abstract interface com.apollographql.cache.normalized.api/MaxAgeProvider { // com.apollographql.cache.normalized.api/MaxAgeProvider|null[0] abstract fun getMaxAge(com.apollographql.cache.normalized.api/MaxAgeContext): kotlin.time/Duration // com.apollographql.cache.normalized.api/MaxAgeProvider.getMaxAge|getMaxAge(com.apollographql.cache.normalized.api.MaxAgeContext){}[0] } @@ -143,8 +147,8 @@ abstract class com.apollographql.cache.normalized.api/NormalizedCacheFactory { / } final class com.apollographql.cache.normalized.api/CacheControlCacheResolver : com.apollographql.cache.normalized.api/CacheResolver { // com.apollographql.cache.normalized.api/CacheControlCacheResolver|null[0] - constructor (com.apollographql.cache.normalized.api/CacheResolver = ...) // com.apollographql.cache.normalized.api/CacheControlCacheResolver.|(com.apollographql.cache.normalized.api.CacheResolver){}[0] - constructor (com.apollographql.cache.normalized.api/MaxAgeProvider, com.apollographql.cache.normalized.api/CacheResolver = ...) // com.apollographql.cache.normalized.api/CacheControlCacheResolver.|(com.apollographql.cache.normalized.api.MaxAgeProvider;com.apollographql.cache.normalized.api.CacheResolver){}[0] + constructor (com.apollographql.cache.normalized.api/MaxAgeProvider, com.apollographql.cache.normalized.api/CacheResolver) // com.apollographql.cache.normalized.api/CacheControlCacheResolver.|(com.apollographql.cache.normalized.api.MaxAgeProvider;com.apollographql.cache.normalized.api.CacheResolver){}[0] + constructor (com.apollographql.cache.normalized.api/MaxAgeProvider, kotlin.collections/Map) // com.apollographql.cache.normalized.api/CacheControlCacheResolver.|(com.apollographql.cache.normalized.api.MaxAgeProvider;kotlin.collections.Map){}[0] final fun resolveField(com.apollographql.cache.normalized.api/ResolverContext): kotlin/Any? // com.apollographql.cache.normalized.api/CacheControlCacheResolver.resolveField|resolveField(com.apollographql.cache.normalized.api.ResolverContext){}[0] } @@ -268,11 +272,10 @@ final class com.apollographql.cache.normalized.api/IdCacheKeyGenerator : com.apo final fun cacheKeyForObject(kotlin.collections/Map, com.apollographql.cache.normalized.api/CacheKeyGeneratorContext): com.apollographql.cache.normalized.api/CacheKey? // com.apollographql.cache.normalized.api/IdCacheKeyGenerator.cacheKeyForObject|cacheKeyForObject(kotlin.collections.Map;com.apollographql.cache.normalized.api.CacheKeyGeneratorContext){}[0] } -final class com.apollographql.cache.normalized.api/IdCacheKeyResolver : com.apollographql.cache.normalized.api/CacheKeyResolver { // com.apollographql.cache.normalized.api/IdCacheKeyResolver|null[0] - constructor (kotlin.collections/List = ..., kotlin.collections/List = ..., com.apollographql.cache.normalized.api/CacheKey.Scope = ...) // com.apollographql.cache.normalized.api/IdCacheKeyResolver.|(kotlin.collections.List;kotlin.collections.List;com.apollographql.cache.normalized.api.CacheKey.Scope){}[0] +final class com.apollographql.cache.normalized.api/KeyArgumentsCacheResolver : com.apollographql.cache.normalized.api/CacheResolver { // com.apollographql.cache.normalized.api/KeyArgumentsCacheResolver|null[0] + constructor (com.apollographql.cache.normalized.api/KeyArgumentsProvider, com.apollographql.cache.normalized.api/CacheKey.Scope) // com.apollographql.cache.normalized.api/KeyArgumentsCacheResolver.|(com.apollographql.cache.normalized.api.KeyArgumentsProvider;com.apollographql.cache.normalized.api.CacheKey.Scope){}[0] - final fun cacheKeyForField(com.apollographql.cache.normalized.api/ResolverContext): com.apollographql.cache.normalized.api/CacheKey? // com.apollographql.cache.normalized.api/IdCacheKeyResolver.cacheKeyForField|cacheKeyForField(com.apollographql.cache.normalized.api.ResolverContext){}[0] - final fun listOfCacheKeysForField(com.apollographql.cache.normalized.api/ResolverContext): kotlin.collections/List? // com.apollographql.cache.normalized.api/IdCacheKeyResolver.listOfCacheKeysForField|listOfCacheKeysForField(com.apollographql.cache.normalized.api.ResolverContext){}[0] + final fun resolveField(com.apollographql.cache.normalized.api/ResolverContext): kotlin/Any? // com.apollographql.cache.normalized.api/KeyArgumentsCacheResolver.resolveField|resolveField(com.apollographql.cache.normalized.api.ResolverContext){}[0] } final class com.apollographql.cache.normalized.api/MaxAgeContext { // com.apollographql.cache.normalized.api/MaxAgeContext|null[0] @@ -388,6 +391,12 @@ final class com.apollographql.cache.normalized.api/SchemaCoordinatesMaxAgeProvid final fun getMaxAge(com.apollographql.cache.normalized.api/MaxAgeContext): kotlin.time/Duration // com.apollographql.cache.normalized.api/SchemaCoordinatesMaxAgeProvider.getMaxAge|getMaxAge(com.apollographql.cache.normalized.api.MaxAgeContext){}[0] } +final class com.apollographql.cache.normalized.api/TypePolicyCacheKeyGenerator : com.apollographql.cache.normalized.api/CacheKeyGenerator { // com.apollographql.cache.normalized.api/TypePolicyCacheKeyGenerator|null[0] + constructor (kotlin.collections/Map, com.apollographql.cache.normalized.api/CacheKey.Scope = ...) // com.apollographql.cache.normalized.api/TypePolicyCacheKeyGenerator.|(kotlin.collections.Map;com.apollographql.cache.normalized.api.CacheKey.Scope){}[0] + + final fun cacheKeyForObject(kotlin.collections/Map, com.apollographql.cache.normalized.api/CacheKeyGeneratorContext): com.apollographql.cache.normalized.api/CacheKey? // com.apollographql.cache.normalized.api/TypePolicyCacheKeyGenerator.cacheKeyForObject|cacheKeyForObject(kotlin.collections.Map;com.apollographql.cache.normalized.api.CacheKeyGeneratorContext){}[0] +} + final class com.apollographql.cache.normalized.memory/MemoryCache : com.apollographql.cache.normalized.api/NormalizedCache { // com.apollographql.cache.normalized.memory/MemoryCache|null[0] constructor (com.apollographql.cache.normalized.api/NormalizedCache? = ..., kotlin/Int = ..., kotlin/Long = ...) // com.apollographql.cache.normalized.memory/MemoryCache.|(com.apollographql.cache.normalized.api.NormalizedCache?;kotlin.Int;kotlin.Long){}[0] @@ -541,21 +550,43 @@ final value class com.apollographql.cache.normalized.api/CacheKey { // com.apoll } final value class com.apollographql.cache.normalized.api/EmbeddedFields { // com.apollographql.cache.normalized.api/EmbeddedFields|null[0] - constructor (kotlin.collections/Set) // com.apollographql.cache.normalized.api/EmbeddedFields.|(kotlin.collections.Set){}[0] + constructor (kotlin.collections/List) // com.apollographql.cache.normalized.api/EmbeddedFields.|(kotlin.collections.List){}[0] final val embeddedFields // com.apollographql.cache.normalized.api/EmbeddedFields.embeddedFields|{}embeddedFields[0] - final fun (): kotlin.collections/Set // com.apollographql.cache.normalized.api/EmbeddedFields.embeddedFields.|(){}[0] + final fun (): kotlin.collections/List // com.apollographql.cache.normalized.api/EmbeddedFields.embeddedFields.|(){}[0] final fun equals(kotlin/Any?): kotlin/Boolean // com.apollographql.cache.normalized.api/EmbeddedFields.equals|equals(kotlin.Any?){}[0] final fun hashCode(): kotlin/Int // com.apollographql.cache.normalized.api/EmbeddedFields.hashCode|hashCode(){}[0] final fun toString(): kotlin/String // com.apollographql.cache.normalized.api/EmbeddedFields.toString|toString(){}[0] } +final value class com.apollographql.cache.normalized.api/FieldPolicies { // com.apollographql.cache.normalized.api/FieldPolicies|null[0] + constructor (kotlin.collections/Map) // com.apollographql.cache.normalized.api/FieldPolicies.|(kotlin.collections.Map){}[0] + + final val fieldPolicies // com.apollographql.cache.normalized.api/FieldPolicies.fieldPolicies|{}fieldPolicies[0] + final fun (): kotlin.collections/Map // com.apollographql.cache.normalized.api/FieldPolicies.fieldPolicies.|(){}[0] + + final fun equals(kotlin/Any?): kotlin/Boolean // com.apollographql.cache.normalized.api/FieldPolicies.equals|equals(kotlin.Any?){}[0] + final fun hashCode(): kotlin/Int // com.apollographql.cache.normalized.api/FieldPolicies.hashCode|hashCode(){}[0] + final fun toString(): kotlin/String // com.apollographql.cache.normalized.api/FieldPolicies.toString|toString(){}[0] + + final value class FieldPolicy { // com.apollographql.cache.normalized.api/FieldPolicies.FieldPolicy|null[0] + constructor (kotlin.collections/List) // com.apollographql.cache.normalized.api/FieldPolicies.FieldPolicy.|(kotlin.collections.List){}[0] + + final val keyArgs // com.apollographql.cache.normalized.api/FieldPolicies.FieldPolicy.keyArgs|{}keyArgs[0] + final fun (): kotlin.collections/List // com.apollographql.cache.normalized.api/FieldPolicies.FieldPolicy.keyArgs.|(){}[0] + + final fun equals(kotlin/Any?): kotlin/Boolean // com.apollographql.cache.normalized.api/FieldPolicies.FieldPolicy.equals|equals(kotlin.Any?){}[0] + final fun hashCode(): kotlin/Int // com.apollographql.cache.normalized.api/FieldPolicies.FieldPolicy.hashCode|hashCode(){}[0] + final fun toString(): kotlin/String // com.apollographql.cache.normalized.api/FieldPolicies.FieldPolicy.toString|toString(){}[0] + } +} + final value class com.apollographql.cache.normalized.api/TypePolicy { // com.apollographql.cache.normalized.api/TypePolicy|null[0] - constructor (kotlin.collections/Set) // com.apollographql.cache.normalized.api/TypePolicy.|(kotlin.collections.Set){}[0] + constructor (kotlin.collections/List) // com.apollographql.cache.normalized.api/TypePolicy.|(kotlin.collections.List){}[0] final val keyFields // com.apollographql.cache.normalized.api/TypePolicy.keyFields|{}keyFields[0] - final fun (): kotlin.collections/Set // com.apollographql.cache.normalized.api/TypePolicy.keyFields.|(){}[0] + final fun (): kotlin.collections/List // com.apollographql.cache.normalized.api/TypePolicy.keyFields.|(){}[0] final fun equals(kotlin/Any?): kotlin/Boolean // com.apollographql.cache.normalized.api/TypePolicy.equals|equals(kotlin.Any?){}[0] final fun hashCode(): kotlin/Int // com.apollographql.cache.normalized.api/TypePolicy.hashCode|hashCode(){}[0] @@ -585,6 +616,10 @@ final object com.apollographql.cache.normalized.api/ApolloCacheHeaders { // com. final fun (): kotlin/String // com.apollographql.cache.normalized.api/ApolloCacheHeaders.STALE.|(){}[0] } +final object com.apollographql.cache.normalized.api/DefaultCacheKeyGenerator : com.apollographql.cache.normalized.api/CacheKeyGenerator { // com.apollographql.cache.normalized.api/DefaultCacheKeyGenerator|null[0] + final fun cacheKeyForObject(kotlin.collections/Map, com.apollographql.cache.normalized.api/CacheKeyGeneratorContext): com.apollographql.cache.normalized.api/CacheKey? // com.apollographql.cache.normalized.api/DefaultCacheKeyGenerator.cacheKeyForObject|cacheKeyForObject(kotlin.collections.Map;com.apollographql.cache.normalized.api.CacheKeyGeneratorContext){}[0] +} + final object com.apollographql.cache.normalized.api/DefaultCacheResolver : com.apollographql.cache.normalized.api/CacheResolver { // com.apollographql.cache.normalized.api/DefaultCacheResolver|null[0] final fun resolveField(com.apollographql.cache.normalized.api/ResolverContext): kotlin/Any? // com.apollographql.cache.normalized.api/DefaultCacheResolver.resolveField|resolveField(com.apollographql.cache.normalized.api.ResolverContext){}[0] } @@ -609,10 +644,6 @@ final val com.apollographql.cache.normalized.api/ConnectionRecordMerger // com.a final fun (): com.apollographql.cache.normalized.api/FieldRecordMerger // com.apollographql.cache.normalized.api/ConnectionRecordMerger.|(){}[0] final val com.apollographql.cache.normalized.api/DefaultMaxAgeProvider // com.apollographql.cache.normalized.api/DefaultMaxAgeProvider|{}DefaultMaxAgeProvider[0] final fun (): com.apollographql.cache.normalized.api/MaxAgeProvider // com.apollographql.cache.normalized.api/DefaultMaxAgeProvider.|(){}[0] -final val com.apollographql.cache.normalized.api/FieldPolicyCacheResolver // com.apollographql.cache.normalized.api/FieldPolicyCacheResolver|{}FieldPolicyCacheResolver[0] - final fun (): com.apollographql.cache.normalized.api/CacheResolver // com.apollographql.cache.normalized.api/FieldPolicyCacheResolver.|(){}[0] -final val com.apollographql.cache.normalized.api/TypePolicyCacheKeyGenerator // com.apollographql.cache.normalized.api/TypePolicyCacheKeyGenerator|{}TypePolicyCacheKeyGenerator[0] - final fun (): com.apollographql.cache.normalized.api/CacheKeyGenerator // com.apollographql.cache.normalized.api/TypePolicyCacheKeyGenerator.|(){}[0] final val com.apollographql.cache.normalized/CacheAndNetworkInterceptor // com.apollographql.cache.normalized/CacheAndNetworkInterceptor|{}CacheAndNetworkInterceptor[0] final fun (): com.apollographql.apollo.interceptor/ApolloInterceptor // com.apollographql.cache.normalized/CacheAndNetworkInterceptor.|(){}[0] final val com.apollographql.cache.normalized/DefaultFetchPolicyInterceptor // com.apollographql.cache.normalized/DefaultFetchPolicyInterceptor|{}DefaultFetchPolicyInterceptor[0] @@ -636,18 +667,18 @@ final val com.apollographql.cache.normalized/isFromCache // com.apollographql.ca 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 = ..., 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;kotlin.Boolean){}[0] -final fun (com.apollographql.apollo/ApolloClient.Builder).com.apollographql.cache.normalized/normalizedCache(com.apollographql.cache.normalized.api/NormalizedCacheFactory, kotlin.collections/Map, kotlin.collections/Set, kotlin.collections/Map, kotlin.collections/Map, kotlin.time/Duration, com.apollographql.cache.normalized.api/CacheKey.Scope, kotlin/Boolean, kotlin/Boolean): com.apollographql.apollo/ApolloClient.Builder // com.apollographql.cache.normalized/normalizedCache|normalizedCache@com.apollographql.apollo.ApolloClient.Builder(com.apollographql.cache.normalized.api.NormalizedCacheFactory;kotlin.collections.Map;kotlin.collections.Set;kotlin.collections.Map;kotlin.collections.Map;kotlin.time.Duration;com.apollographql.cache.normalized.api.CacheKey.Scope;kotlin.Boolean;kotlin.Boolean){}[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/CacheResolver, com.apollographql.cache.normalized.api/MetadataGenerator = ..., 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 = ..., 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.CacheResolver;com.apollographql.cache.normalized.api.MetadataGenerator;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;kotlin.Boolean){}[0] +final fun (com.apollographql.apollo/ApolloClient.Builder).com.apollographql.cache.normalized/normalizedCache(com.apollographql.cache.normalized.api/NormalizedCacheFactory, kotlin.collections/Map, kotlin.collections/Map, com.apollographql.cache.normalized.api/MetadataGenerator = ..., 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.api/CacheKey.Scope = ..., kotlin/Boolean = ..., kotlin/Boolean = ...): com.apollographql.apollo/ApolloClient.Builder // com.apollographql.cache.normalized/normalizedCache|normalizedCache@com.apollographql.apollo.ApolloClient.Builder(com.apollographql.cache.normalized.api.NormalizedCacheFactory;kotlin.collections.Map;kotlin.collections.Map;com.apollographql.cache.normalized.api.MetadataGenerator;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.api.CacheKey.Scope;kotlin.Boolean;kotlin.Boolean){}[0] +final fun (com.apollographql.apollo/ApolloClient.Builder).com.apollographql.cache.normalized/normalizedCache(com.apollographql.cache.normalized.api/NormalizedCacheFactory, kotlin.collections/Map, kotlin.collections/Map, kotlin.collections/Set, kotlin.collections/Map, kotlin.collections/Map, kotlin.time/Duration, com.apollographql.cache.normalized.api/CacheKey.Scope, kotlin/Boolean, kotlin/Boolean): com.apollographql.apollo/ApolloClient.Builder // com.apollographql.cache.normalized/normalizedCache|normalizedCache@com.apollographql.apollo.ApolloClient.Builder(com.apollographql.cache.normalized.api.NormalizedCacheFactory;kotlin.collections.Map;kotlin.collections.Map;kotlin.collections.Set;kotlin.collections.Map;kotlin.collections.Map;kotlin.time.Duration;com.apollographql.cache.normalized.api.CacheKey.Scope;kotlin.Boolean;kotlin.Boolean){}[0] final fun (com.apollographql.cache.normalized.api/Record).com.apollographql.cache.normalized.api/expirationDate(kotlin/String): kotlin/Long? // com.apollographql.cache.normalized.api/expirationDate|expirationDate@com.apollographql.cache.normalized.api.Record(kotlin.String){}[0] final fun (com.apollographql.cache.normalized.api/Record).com.apollographql.cache.normalized.api/receivedDate(kotlin/String): kotlin/Long? // com.apollographql.cache.normalized.api/receivedDate|receivedDate@com.apollographql.cache.normalized.api.Record(kotlin.String){}[0] final fun (com.apollographql.cache.normalized.api/Record).com.apollographql.cache.normalized.api/withDates(kotlin/String?, kotlin/String?): com.apollographql.cache.normalized.api/Record // com.apollographql.cache.normalized.api/withDates|withDates@com.apollographql.cache.normalized.api.Record(kotlin.String?;kotlin.String?){}[0] final fun (com.apollographql.cache.normalized.api/ResolverContext).com.apollographql.cache.normalized.api/getFieldKey(): kotlin/String // com.apollographql.cache.normalized.api/getFieldKey|getFieldKey@com.apollographql.cache.normalized.api.ResolverContext(){}[0] -final fun (com.apollographql.cache.normalized.api/ResolverContext).com.apollographql.cache.normalized.api/listItemsInParent(kotlin/String): kotlin.collections/Map // com.apollographql.cache.normalized.api/listItemsInParent|listItemsInParent@com.apollographql.cache.normalized.api.ResolverContext(kotlin.String){}[0] final fun (kotlin.collections/Collection?).com.apollographql.cache.normalized.api/dependentKeys(): kotlin.collections/Set // com.apollographql.cache.normalized.api/dependentKeys|dependentKeys@kotlin.collections.Collection?(){}[0] final fun (kotlin.collections/Map).com.apollographql.cache.normalized/getReachableCacheKeys(): kotlin.collections/Set // com.apollographql.cache.normalized/getReachableCacheKeys|getReachableCacheKeys@kotlin.collections.Map(){}[0] final fun <#A: com.apollographql.apollo.api/Executable.Data> (#A).com.apollographql.cache.normalized.api/withErrors(com.apollographql.apollo.api/Executable<#A>, kotlin.collections/List?, com.apollographql.apollo.api/CustomScalarAdapters = ...): kotlin.collections/Map // com.apollographql.cache.normalized.api/withErrors|withErrors@0:0(com.apollographql.apollo.api.Executable<0:0>;kotlin.collections.List?;com.apollographql.apollo.api.CustomScalarAdapters){0§}[0] -final fun <#A: com.apollographql.apollo.api/Executable.Data> (#A).com.apollographql.cache.normalized.internal/normalized(com.apollographql.apollo.api/Executable<#A>, com.apollographql.cache.normalized.api/CacheKey = ..., com.apollographql.apollo.api/CustomScalarAdapters = ..., com.apollographql.cache.normalized.api/CacheKeyGenerator = ..., com.apollographql.cache.normalized.api/MetadataGenerator = ..., com.apollographql.cache.normalized.api/FieldKeyGenerator = ..., com.apollographql.cache.normalized.api/EmbeddedFieldsProvider = ..., com.apollographql.cache.normalized.api/MaxAgeProvider = ...): kotlin.collections/Map // com.apollographql.cache.normalized.internal/normalized|normalized@0:0(com.apollographql.apollo.api.Executable<0:0>;com.apollographql.cache.normalized.api.CacheKey;com.apollographql.apollo.api.CustomScalarAdapters;com.apollographql.cache.normalized.api.CacheKeyGenerator;com.apollographql.cache.normalized.api.MetadataGenerator;com.apollographql.cache.normalized.api.FieldKeyGenerator;com.apollographql.cache.normalized.api.EmbeddedFieldsProvider;com.apollographql.cache.normalized.api.MaxAgeProvider){0§}[0] -final fun <#A: com.apollographql.apollo.api/Executable.Data> (kotlin.collections/Map).com.apollographql.cache.normalized.internal/normalized(com.apollographql.apollo.api/Executable<#A>, com.apollographql.cache.normalized.api/CacheKey = ..., com.apollographql.apollo.api/CustomScalarAdapters = ..., com.apollographql.cache.normalized.api/CacheKeyGenerator = ..., com.apollographql.cache.normalized.api/MetadataGenerator = ..., com.apollographql.cache.normalized.api/FieldKeyGenerator = ..., com.apollographql.cache.normalized.api/EmbeddedFieldsProvider = ..., com.apollographql.cache.normalized.api/MaxAgeProvider = ...): kotlin.collections/Map // com.apollographql.cache.normalized.internal/normalized|normalized@kotlin.collections.Map(com.apollographql.apollo.api.Executable<0:0>;com.apollographql.cache.normalized.api.CacheKey;com.apollographql.apollo.api.CustomScalarAdapters;com.apollographql.cache.normalized.api.CacheKeyGenerator;com.apollographql.cache.normalized.api.MetadataGenerator;com.apollographql.cache.normalized.api.FieldKeyGenerator;com.apollographql.cache.normalized.api.EmbeddedFieldsProvider;com.apollographql.cache.normalized.api.MaxAgeProvider){0§}[0] +final fun <#A: com.apollographql.apollo.api/Executable.Data> (#A).com.apollographql.cache.normalized.internal/normalized(com.apollographql.apollo.api/Executable<#A>, com.apollographql.cache.normalized.api/CacheKeyGenerator, com.apollographql.cache.normalized.api/CacheKey = ..., com.apollographql.apollo.api/CustomScalarAdapters = ..., com.apollographql.cache.normalized.api/MetadataGenerator = ..., com.apollographql.cache.normalized.api/FieldKeyGenerator = ..., com.apollographql.cache.normalized.api/EmbeddedFieldsProvider = ..., com.apollographql.cache.normalized.api/MaxAgeProvider = ...): kotlin.collections/Map // com.apollographql.cache.normalized.internal/normalized|normalized@0:0(com.apollographql.apollo.api.Executable<0:0>;com.apollographql.cache.normalized.api.CacheKeyGenerator;com.apollographql.cache.normalized.api.CacheKey;com.apollographql.apollo.api.CustomScalarAdapters;com.apollographql.cache.normalized.api.MetadataGenerator;com.apollographql.cache.normalized.api.FieldKeyGenerator;com.apollographql.cache.normalized.api.EmbeddedFieldsProvider;com.apollographql.cache.normalized.api.MaxAgeProvider){0§}[0] +final fun <#A: com.apollographql.apollo.api/Executable.Data> (kotlin.collections/Map).com.apollographql.cache.normalized.internal/normalized(com.apollographql.apollo.api/Executable<#A>, com.apollographql.cache.normalized.api/CacheKeyGenerator, com.apollographql.cache.normalized.api/CacheKey = ..., com.apollographql.apollo.api/CustomScalarAdapters = ..., com.apollographql.cache.normalized.api/MetadataGenerator = ..., com.apollographql.cache.normalized.api/FieldKeyGenerator = ..., com.apollographql.cache.normalized.api/EmbeddedFieldsProvider = ..., com.apollographql.cache.normalized.api/MaxAgeProvider = ...): kotlin.collections/Map // com.apollographql.cache.normalized.internal/normalized|normalized@kotlin.collections.Map(com.apollographql.apollo.api.Executable<0:0>;com.apollographql.cache.normalized.api.CacheKeyGenerator;com.apollographql.cache.normalized.api.CacheKey;com.apollographql.apollo.api.CustomScalarAdapters;com.apollographql.cache.normalized.api.MetadataGenerator;com.apollographql.cache.normalized.api.FieldKeyGenerator;com.apollographql.cache.normalized.api.EmbeddedFieldsProvider;com.apollographql.cache.normalized.api.MaxAgeProvider){0§}[0] final fun <#A: com.apollographql.apollo.api/Mutation.Data> (com.apollographql.apollo.api/ApolloRequest.Builder<#A>).com.apollographql.cache.normalized/optimisticUpdates(#A): com.apollographql.apollo.api/ApolloRequest.Builder<#A> // com.apollographql.cache.normalized/optimisticUpdates|optimisticUpdates@com.apollographql.apollo.api.ApolloRequest.Builder<0:0>(0:0){0§}[0] final fun <#A: com.apollographql.apollo.api/Mutation.Data> (com.apollographql.apollo/ApolloCall<#A>).com.apollographql.cache.normalized/optimisticUpdates(#A): com.apollographql.apollo/ApolloCall<#A> // com.apollographql.cache.normalized/optimisticUpdates|optimisticUpdates@com.apollographql.apollo.ApolloCall<0:0>(0:0){0§}[0] final fun <#A: com.apollographql.apollo.api/Operation.Data> (com.apollographql.apollo.api/ApolloRequest.Builder<#A>).com.apollographql.cache.normalized/fetchFromCache(kotlin/Boolean): com.apollographql.apollo.api/ApolloRequest.Builder<#A> // com.apollographql.cache.normalized/fetchFromCache|fetchFromCache@com.apollographql.apollo.api.ApolloRequest.Builder<0:0>(kotlin.Boolean){0§}[0] @@ -672,9 +703,9 @@ 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.api/FieldPolicyCacheResolver(com.apollographql.cache.normalized.api/CacheKey.Scope = ...): com.apollographql.cache.normalized.api/CacheResolver // com.apollographql.cache.normalized.api/FieldPolicyCacheResolver|FieldPolicyCacheResolver(com.apollographql.cache.normalized.api.CacheKey.Scope){}[0] -final fun com.apollographql.cache.normalized.api/TypePolicyCacheKeyGenerator(kotlin.collections/Map, com.apollographql.cache.normalized.api/CacheKey.Scope = ...): com.apollographql.cache.normalized.api/CacheKeyGenerator // com.apollographql.cache.normalized.api/TypePolicyCacheKeyGenerator|TypePolicyCacheKeyGenerator(kotlin.collections.Map;com.apollographql.cache.normalized.api.CacheKey.Scope){}[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 = ..., kotlin/Boolean = ...): 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;kotlin.Boolean){}[0] +final fun com.apollographql.cache.normalized.api/FieldPolicyCacheResolver(kotlin.collections/Map, com.apollographql.cache.normalized.api/CacheKey.Scope = ...): com.apollographql.cache.normalized.api/CacheResolver // com.apollographql.cache.normalized.api/FieldPolicyCacheResolver|FieldPolicyCacheResolver(kotlin.collections.Map;com.apollographql.cache.normalized.api.CacheKey.Scope){}[0] +final fun com.apollographql.cache.normalized.api/IdCacheResolver(kotlin.collections/List = ..., com.apollographql.cache.normalized.api/CacheKey.Scope = ...): com.apollographql.cache.normalized.api/CacheResolver // com.apollographql.cache.normalized.api/IdCacheResolver|IdCacheResolver(kotlin.collections.List;com.apollographql.cache.normalized.api.CacheKey.Scope){}[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/CacheResolver, com.apollographql.cache.normalized.api/MetadataGenerator = ..., 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.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.CacheResolver;com.apollographql.cache.normalized.api.MetadataGenerator;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 suspend 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 suspend fun (com.apollographql.cache.normalized.api/NormalizedCache).com.apollographql.cache.normalized/garbageCollect(com.apollographql.cache.normalized.api/MaxAgeProvider, kotlin.time/Duration = ..., kotlin/Function0 = ...): 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;kotlin.Function0){}[0] final suspend 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] 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 index 43dee163c..91d6e7c05 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/CacheManager.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/CacheManager.kt @@ -25,7 +25,6 @@ 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.TypePolicyCacheKeyGenerator import com.apollographql.cache.normalized.internal.DefaultCacheManager import com.benasher44.uuid.Uuid import kotlinx.coroutines.flow.SharedFlow @@ -309,9 +308,9 @@ interface CacheManager { fun CacheManager( normalizedCacheFactory: NormalizedCacheFactory, - cacheKeyGenerator: CacheKeyGenerator = @Suppress("DEPRECATION") TypePolicyCacheKeyGenerator, + cacheKeyGenerator: CacheKeyGenerator, + cacheResolver: CacheResolver, metadataGenerator: MetadataGenerator = EmptyMetadataGenerator, - cacheResolver: CacheResolver = com.apollographql.cache.normalized.api.FieldPolicyCacheResolver(keyScope = CacheKey.Scope.TYPE), recordMerger: RecordMerger = DefaultRecordMerger, fieldKeyGenerator: FieldKeyGenerator = DefaultFieldKeyGenerator, embeddedFieldsProvider: EmbeddedFieldsProvider = EmptyEmbeddedFieldsProvider, 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 dcdc6bde4..2788ee1d6 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 @@ -1,5 +1,3 @@ -@file:JvmName("NormalizedCache") - package com.apollographql.cache.normalized import com.apollographql.apollo.ApolloClient @@ -16,11 +14,12 @@ import com.apollographql.cache.normalized.api.ApolloCacheHeaders import com.apollographql.cache.normalized.api.CacheControlCacheResolver 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.api.CacheResolver import com.apollographql.cache.normalized.api.ConnectionFieldKeyGenerator import com.apollographql.cache.normalized.api.ConnectionMetadataGenerator import com.apollographql.cache.normalized.api.ConnectionRecordMerger +import com.apollographql.cache.normalized.api.DefaultCacheKeyGenerator +import com.apollographql.cache.normalized.api.DefaultCacheResolver import com.apollographql.cache.normalized.api.DefaultEmbeddedFieldsProvider import com.apollographql.cache.normalized.api.DefaultFieldKeyGenerator import com.apollographql.cache.normalized.api.DefaultMaxAgeProvider @@ -30,6 +29,7 @@ import com.apollographql.cache.normalized.api.EmbeddedFieldsProvider import com.apollographql.cache.normalized.api.EmptyEmbeddedFieldsProvider import com.apollographql.cache.normalized.api.EmptyMetadataGenerator import com.apollographql.cache.normalized.api.FieldKeyGenerator +import com.apollographql.cache.normalized.api.FieldPolicies import com.apollographql.cache.normalized.api.FieldPolicyCacheResolver import com.apollographql.cache.normalized.api.GlobalMaxAgeProvider import com.apollographql.cache.normalized.api.MaxAge @@ -44,8 +44,6 @@ import com.apollographql.cache.normalized.internal.ApolloCacheInterceptor import com.apollographql.cache.normalized.internal.WatcherInterceptor import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map -import kotlin.jvm.JvmName -import kotlin.jvm.JvmOverloads import kotlin.time.Duration /** @@ -57,17 +55,15 @@ import kotlin.time.Duration * where the cache is created will also be isolated so that the cache can be mutated. * * @param cacheResolver a [CacheResolver] to customize normalization - * + * @param cacheKeyGenerator a [CacheKeyGenerator] to generate cache keys for objects * @param writeToCacheAsynchronously set to true to write to the cache after the response has been emitted. - * This allows to display results faster + * This allows to display results faster. */ -@JvmOverloads -@JvmName("configureApolloClientBuilder2") fun ApolloClient.Builder.normalizedCache( normalizedCacheFactory: NormalizedCacheFactory, - cacheKeyGenerator: CacheKeyGenerator = @Suppress("DEPRECATION") TypePolicyCacheKeyGenerator, + cacheKeyGenerator: CacheKeyGenerator, + cacheResolver: CacheResolver, metadataGenerator: MetadataGenerator = EmptyMetadataGenerator, - cacheResolver: CacheResolver = FieldPolicyCacheResolver(keyScope = CacheKey.Scope.TYPE), recordMerger: RecordMerger = DefaultRecordMerger, fieldKeyGenerator: FieldKeyGenerator = DefaultFieldKeyGenerator, embeddedFieldsProvider: EmbeddedFieldsProvider = EmptyEmbeddedFieldsProvider, @@ -75,6 +71,45 @@ fun ApolloClient.Builder.normalizedCache( enableOptimisticUpdates: Boolean = false, writeToCacheAsynchronously: Boolean = false, ): ApolloClient.Builder { + return cacheManager( + CacheManager( + normalizedCacheFactory = normalizedCacheFactory, + cacheKeyGenerator = cacheKeyGenerator, + metadataGenerator = metadataGenerator, + cacheResolver = cacheResolver, + recordMerger = recordMerger, + fieldKeyGenerator = fieldKeyGenerator, + embeddedFieldsProvider = embeddedFieldsProvider, + maxAgeProvider = maxAgeProvider, + enableOptimisticUpdates = enableOptimisticUpdates, + ), + writeToCacheAsynchronously, + ) +} + +fun ApolloClient.Builder.normalizedCache( + normalizedCacheFactory: NormalizedCacheFactory, + typePolicies: Map, + fieldPolicies: Map, + metadataGenerator: MetadataGenerator = EmptyMetadataGenerator, + recordMerger: RecordMerger = DefaultRecordMerger, + fieldKeyGenerator: FieldKeyGenerator = DefaultFieldKeyGenerator, + embeddedFieldsProvider: EmbeddedFieldsProvider = EmptyEmbeddedFieldsProvider, + maxAgeProvider: MaxAgeProvider = DefaultMaxAgeProvider, + keyScope: CacheKey.Scope = CacheKey.Scope.TYPE, + enableOptimisticUpdates: Boolean = false, + writeToCacheAsynchronously: Boolean = false, +): ApolloClient.Builder { + val cacheKeyGenerator = if (typePolicies.isEmpty()) { + DefaultCacheKeyGenerator + } else { + TypePolicyCacheKeyGenerator(typePolicies, keyScope) + } + val cacheResolver = if (fieldPolicies.isEmpty()) { + DefaultCacheResolver + } else { + FieldPolicyCacheResolver(fieldPolicies, keyScope) + } return cacheManager( CacheManager( normalizedCacheFactory = normalizedCacheFactory, @@ -93,6 +128,7 @@ fun ApolloClient.Builder.normalizedCache( fun ApolloClient.Builder.normalizedCache( normalizedCacheFactory: NormalizedCacheFactory, typePolicies: Map, + fieldPolicies: Map, connectionTypes: Set, embeddedFields: Map, maxAges: Map, @@ -102,11 +138,7 @@ fun ApolloClient.Builder.normalizedCache( writeToCacheAsynchronously: Boolean, ): ApolloClient.Builder { val cacheKeyGenerator = if (typePolicies.isEmpty()) { - object : CacheKeyGenerator { - override fun cacheKeyForObject(obj: Map, context: CacheKeyGeneratorContext): CacheKey? { - return null - } - } + DefaultCacheKeyGenerator } else { TypePolicyCacheKeyGenerator(typePolicies, keyScope) } @@ -120,12 +152,17 @@ fun ApolloClient.Builder.normalizedCache( } else { SchemaCoordinatesMaxAgeProvider(maxAges, defaultMaxAge) } + val fieldPolicyResolver = if (fieldPolicies.isEmpty()) { + DefaultCacheResolver + } else { + FieldPolicyCacheResolver(fieldPolicies, keyScope) + } val cacheResolver = if (maxAges.isEmpty()) { - FieldPolicyCacheResolver(keyScope) + fieldPolicyResolver } else { CacheControlCacheResolver( maxAgeProvider = maxAgeProvider, - delegateResolver = FieldPolicyCacheResolver(keyScope), + delegateResolver = fieldPolicyResolver, ) } val recordMerger = if (connectionTypes.isEmpty()) { @@ -163,7 +200,6 @@ fun ApolloClient.Builder.normalizedCache( } } -@JvmName("-logCacheMisses") fun ApolloClient.Builder.logCacheMisses( log: (String) -> Unit = { println(it) }, ): ApolloClient.Builder { diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/FetchPolicyInterceptors.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/FetchPolicyInterceptors.kt index a78bf3632..1c17af023 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/FetchPolicyInterceptors.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/FetchPolicyInterceptors.kt @@ -1,5 +1,3 @@ -@file:JvmName("FetchPolicyInterceptors") - package com.apollographql.cache.normalized import com.apollographql.apollo.api.ApolloRequest @@ -23,7 +21,6 @@ import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.single -import kotlin.jvm.JvmName /** * An interceptor that emits the response from the cache first, and if there was a cache miss, emits the response(s) from the network. diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/CacheKeyGenerator.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/CacheKeyGenerator.kt index 50270bedf..038bd0274 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/CacheKeyGenerator.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/CacheKeyGenerator.kt @@ -2,7 +2,6 @@ package com.apollographql.cache.normalized.api import com.apollographql.apollo.api.CompiledField import com.apollographql.apollo.api.Executable -import com.apollographql.apollo.api.keyFields /** * An [CacheKeyGenerator] is responsible for finding an id for a given object @@ -41,24 +40,11 @@ class CacheKeyGeneratorContext( ) /** - * A [CacheKeyGenerator] that uses the `@typePolicy` directive to compute the cache key. - * - * Note: this uses the key fields of the **schema** type and therefore can't generate cache keys for: - * - unions - * - interfaces that have a `@typePolicy` on subtypes. - * - * For those cases, prefer `fun TypePolicyCacheKeyGenerator(typePolicies, keyScope)`, which uses the concrete type (found in `__typename`) - * instead. + * A [CacheKeyGenerator] that does not generate any cache key. */ -@Deprecated("Use TypePolicyCacheKeyGenerator(typePolicies, keyScope) instead") -val TypePolicyCacheKeyGenerator: CacheKeyGenerator = object : CacheKeyGenerator { +object DefaultCacheKeyGenerator : CacheKeyGenerator { override fun cacheKeyForObject(obj: Map, context: CacheKeyGeneratorContext): CacheKey? { - val keyFields = context.field.type.rawType().keyFields() - return if (keyFields.isNotEmpty()) { - CacheKey(obj["__typename"].toString(), keyFields.map { obj[it].toString() }) - } else { - null - } + return null } } @@ -71,10 +57,10 @@ val TypePolicyCacheKeyGenerator: CacheKeyGenerator = object : CacheKeyGenerator * @param keyScope the scope of the generated cache keys. Use [CacheKey.Scope.TYPE] to namespace the keys by the concrete type name, or * [CacheKey.Scope.SERVICE] if the ids are unique across the whole service. */ -fun TypePolicyCacheKeyGenerator( - typePolicies: Map, - keyScope: CacheKey.Scope = CacheKey.Scope.TYPE, -) = object : CacheKeyGenerator { +class TypePolicyCacheKeyGenerator( + private val typePolicies: Map, + private val keyScope: CacheKey.Scope = CacheKey.Scope.TYPE, +) : CacheKeyGenerator { override fun cacheKeyForObject(obj: Map, context: CacheKeyGeneratorContext): CacheKey? { val typeName = obj["__typename"].toString() val typePolicy = typePolicies[typeName] diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/CacheKeyResolver.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/CacheKeyResolver.kt index e004b4636..2d0c5e0cd 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/CacheKeyResolver.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/CacheKeyResolver.kt @@ -66,53 +66,3 @@ abstract class CacheKeyResolver : CacheResolver { return DefaultCacheResolver.resolveField(context) } } - -/** - * A simple [CacheKeyResolver] that uses the id/ids argument, if present, to compute the cache key. - * The name of the id arguments can be provided (by default "id" for objects and "ids" for lists). - * If several names are provided, the first present one is used. - * Only one level of list is supported - implement [CacheResolver] if you need arbitrary nested lists of objects. - * - * @param idFields possible names of the argument containing the id for objects - * @param idListFields possible names of the argument containing the ids for lists - * @param keyScope the scope of the computed cache keys. Use [CacheKey.Scope.TYPE] to namespace the keys by the schema type name, or - * [CacheKey.Scope.SERVICE] if the ids are unique across the whole service. - * - * @see IdCacheKeyGenerator - */ -class IdCacheKeyResolver( - private val idFields: List = listOf("id"), - private val idListFields: List = listOf("ids"), - private val keyScope: CacheKey.Scope = CacheKey.Scope.TYPE, -) : CacheKeyResolver() { - override fun cacheKeyForField(context: ResolverContext): CacheKey? { - val fieldKey = context.getFieldKey() - if (context.parent[fieldKey] != null) { - return null - } - val id = idFields.firstNotNullOfOrNull { context.field.argumentValue(it, context.variables).getOrNull()?.toString() } ?: return null - return if (keyScope == CacheKey.Scope.TYPE) { - CacheKey(context.field.type.rawType().name, id) - } else { - CacheKey(id) - } - } - - override fun listOfCacheKeysForField(context: ResolverContext): List? { - val fieldKey = context.getFieldKey() - if (context.parent[fieldKey] != null) { - return null - } - val ids = idListFields.firstNotNullOfOrNull { context.field.argumentValue(it, context.variables).getOrNull() as? List<*> } - ?: return null - return ids.map { id -> - id?.toString()?.let { - if (keyScope == CacheKey.Scope.TYPE) { - CacheKey(context.field.type.rawType().name, it) - } else { - CacheKey(it) - } - } - } - } -} diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/CacheResolver.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/CacheResolver.kt index d861e7e9b..62eb6b0d5 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/CacheResolver.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/CacheResolver.kt @@ -154,7 +154,7 @@ fun ResolverContext.getFieldKey(): String { * * Note: this relies on the default format of the field keys as per [DefaultFieldKeyGenerator]. */ -fun ResolverContext.listItemsInParent(keyArg: String): Map { +private fun ResolverContext.listItemsInParent(keyArg: String): Map { val keyPrefix = "${this.field.name}(" val filteredParent = this.parent.filterKeys { it.startsWith(keyPrefix) && it.contains("\"$keyArg\":") } val items: Map = filteredParent.map { (k, v) -> @@ -203,16 +203,17 @@ object DefaultCacheResolver : CacheResolver { */ class CacheControlCacheResolver( private val maxAgeProvider: MaxAgeProvider, - private val delegateResolver: CacheResolver = FieldPolicyCacheResolver(keyScope = CacheKey.Scope.TYPE), + private val delegateResolver: CacheResolver, ) : CacheResolver { /** * Creates a new [CacheControlCacheResolver] with no max ages. Use this constructor if you want to consider only the expiration dates. */ constructor( - delegateResolver: CacheResolver = FieldPolicyCacheResolver(keyScope = CacheKey.Scope.TYPE), + maxAgeProvider: MaxAgeProvider, + fieldPolicies: Map, ) : this( - maxAgeProvider = DefaultMaxAgeProvider, - delegateResolver = delegateResolver, + maxAgeProvider = maxAgeProvider, + delegateResolver = FieldPolicyCacheResolver(fieldPolicies = fieldPolicies, keyScope = CacheKey.Scope.TYPE), ) override fun resolveField(context: ResolverContext): Any? { @@ -234,7 +235,7 @@ class CacheControlCacheResolver( throw CacheMissException( key = context.parentKey.keyToString(), fieldName = context.getFieldKey(), - stale = true + stale = true, ) } if (staleDuration >= 0) isStale = true @@ -249,7 +250,7 @@ class CacheControlCacheResolver( throw CacheMissException( key = context.parentKey.keyToString(), fieldName = context.getFieldKey(), - stale = true + stale = true, ) } if (staleDuration >= 0) isStale = true @@ -271,15 +272,33 @@ class CacheControlCacheResolver( /** * A cache resolver that uses `@fieldPolicy` directives to resolve fields and delegates to [DefaultCacheResolver] otherwise. * - * Note: this namespaces the ids with the **schema** type, will lead to cache misses for: + * Note: using a [CacheKey.Scope.TYPE] `keyScope` namespaces the ids with the **schema** type, which will lead to cache misses for: * - unions * - interfaces that have a `@typePolicy` on subtypes. * - * If the ids are unique across the whole service, use `FieldPolicyCacheResolver(keyScope = CacheKey.Scope.SERVICE)`. Otherwise there is - * no way to resolve the cache key automatically for those cases. + * If the ids are unique across the whole service, use [CacheKey.Scope.SERVICE]. Otherwise there is no way to resolve the cache keys + * automatically for those cases. + * + * @param fieldPolicies the field policies where to look for key arguments + * @param keyScope the scope of the computed cache keys. Use [CacheKey.Scope.TYPE] to namespace the keys by the schema type name, or + * [CacheKey.Scope.SERVICE] if the ids are unique across the whole service. */ -@Deprecated("Use FieldPolicyCacheResolver(keyScope) instead") -val FieldPolicyCacheResolver: CacheResolver = FieldPolicyCacheResolver(keyScope = CacheKey.Scope.TYPE) +fun FieldPolicyCacheResolver( + fieldPolicies: Map, + keyScope: CacheKey.Scope = CacheKey.Scope.TYPE, +): CacheResolver = KeyArgumentsCacheResolver( + keyArgumentsProvider = object : KeyArgumentsProvider { + override fun getKeyArguments(parentType: String, field: CompiledField): List { + return fieldPolicies[parentType]?.fieldPolicies[field.name]?.keyArgs.orEmpty() + } + }, + keyScope = keyScope, +) + + +interface KeyArgumentsProvider { + fun getKeyArguments(parentType: String, field: CompiledField): List +} /** * A cache resolver that uses `@fieldPolicy` directives to resolve fields and delegates to [DefaultCacheResolver] otherwise. @@ -291,15 +310,20 @@ val FieldPolicyCacheResolver: CacheResolver = FieldPolicyCacheResolver(keyScope * If the ids are unique across the whole service, use [CacheKey.Scope.SERVICE]. Otherwise there is no way to resolve the cache keys * automatically for those cases. * + * @param keyArgumentsProvider provides the key arguments for a given field * @param keyScope the scope of the computed cache keys. Use [CacheKey.Scope.TYPE] to namespace the keys by the schema type name, or * [CacheKey.Scope.SERVICE] if the ids are unique across the whole service. */ -fun FieldPolicyCacheResolver( - keyScope: CacheKey.Scope = CacheKey.Scope.TYPE, -) = object : CacheResolver { +class KeyArgumentsCacheResolver( + private val keyArgumentsProvider: KeyArgumentsProvider, + private val keyScope: CacheKey.Scope, +) : CacheResolver { override fun resolveField(context: ResolverContext): Any? { - val keyArgs = context.field.argumentValues(context.variables) { it.definition.isKey } - val keyArgsValues = keyArgs.values + val keyArgs = + keyArgumentsProvider.getKeyArguments(context.parentType, context.field).ifEmpty { return DefaultCacheResolver.resolveField(context) } + val keyArgsMap = context.field.argumentValues(context.variables) { it.definition.name in keyArgs } + // Keep the same order as defined in the field policy + val keyArgsValues = keyArgs.map { keyArgsMap[it] } if (keyArgsValues.isEmpty()) { return DefaultCacheResolver.resolveField(context) } @@ -310,11 +334,11 @@ fun FieldPolicyCacheResolver( if (type is CompiledListType) { // Only support flat lists if (type.ofType !is CompiledListType && !(type.ofType is CompiledNotNullType && (type.ofType as CompiledNotNullType).ofType is CompiledListType)) { - // Only support single key argument which is a flat list + // Only support single key argument which is a list if (keyArgsValues.size == 1) { val keyArgsValue = keyArgsValues.first() as? List<*> if (keyArgsValue != null) { - val listItemsInParent: Map = context.listItemsInParent(keyArgs.keys.first()) + val listItemsInParent: Map = context.listItemsInParent(keyArgs.first()) return keyArgsValue.mapIndexed { index, value -> if (listItemsInParent.containsKey(value)) { listItemsInParent[value]?.let { @@ -362,3 +386,29 @@ fun FieldPolicyCacheResolver( return builder.build() } } + + +/** + * A [CacheResolver] that uses the id/ids argument, if present, to compute the cache key. + * The name of the id arguments can be provided (by default "id" and "ids"). + * If several names are provided, the first present one is used. + * Only one level of list is supported - implement [CacheResolver] if you need arbitrary nested lists of objects. + * + * @param idArguments possible names of the argument containing the id for objects + * @param keyScope the scope of the computed cache keys. Use [CacheKey.Scope.TYPE] to namespace the keys by the schema type name, or + * [CacheKey.Scope.SERVICE] if the ids are unique across the whole service. + * + * @see IdCacheKeyGenerator + */ +fun IdCacheResolver( + idArguments: List = listOf("id", "ids"), + keyScope: CacheKey.Scope = CacheKey.Scope.TYPE, +): CacheResolver = KeyArgumentsCacheResolver( + keyArgumentsProvider = object : KeyArgumentsProvider { + override fun getKeyArguments(parentType: String, field: CompiledField): List { + return idArguments.firstOrNull { argName -> field.arguments.any { it.definition.name == argName } }?.let { listOf(it) } + ?: emptyList() + } + }, + keyScope = keyScope, +) diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/EmbeddedFields.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/EmbeddedFields.kt index aa384e7ff..15d61e750 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/EmbeddedFields.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/EmbeddedFields.kt @@ -4,5 +4,5 @@ import kotlin.jvm.JvmInline @JvmInline value class EmbeddedFields( - val embeddedFields: Set, + val embeddedFields: List, ) diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/FieldPolicies.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/FieldPolicies.kt new file mode 100644 index 000000000..1ca587cee --- /dev/null +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/FieldPolicies.kt @@ -0,0 +1,13 @@ +package com.apollographql.cache.normalized.api + +import kotlin.jvm.JvmInline + +@JvmInline +value class FieldPolicies( + val fieldPolicies: Map, +) { + @JvmInline + value class FieldPolicy( + val keyArgs: List, + ) +} diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/TypePolicy.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/TypePolicy.kt index 5407bb48e..2db5230b8 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/TypePolicy.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/api/TypePolicy.kt @@ -4,5 +4,5 @@ import kotlin.jvm.JvmInline @JvmInline value class TypePolicy( - val keyFields: Set, + val keyFields: List, ) diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/Normalizer.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/Normalizer.kt index a029342df..17d63626c 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/Normalizer.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/internal/Normalizer.kt @@ -29,7 +29,6 @@ import com.apollographql.cache.normalized.api.MaxAgeProvider import com.apollographql.cache.normalized.api.MetadataGenerator import com.apollographql.cache.normalized.api.MetadataGeneratorContext import com.apollographql.cache.normalized.api.Record -import com.apollographql.cache.normalized.api.TypePolicyCacheKeyGenerator import com.apollographql.cache.normalized.api.append import com.apollographql.cache.normalized.api.toMaxAgeField import com.apollographql.cache.normalized.api.withErrors @@ -281,16 +280,25 @@ internal class Normalizer( */ fun D.normalized( executable: Executable, + cacheKeyGenerator: CacheKeyGenerator, rootKey: CacheKey = CacheKey.QUERY_ROOT, customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, - cacheKeyGenerator: CacheKeyGenerator = @Suppress("DEPRECATION") TypePolicyCacheKeyGenerator, metadataGenerator: MetadataGenerator = EmptyMetadataGenerator, fieldKeyGenerator: FieldKeyGenerator = DefaultFieldKeyGenerator, embeddedFieldsProvider: EmbeddedFieldsProvider = EmptyEmbeddedFieldsProvider, maxAgeProvider: MaxAgeProvider = DefaultMaxAgeProvider, ): Map { val dataWithErrors = this.withErrors(executable, null, customScalarAdapters) - return dataWithErrors.normalized(executable, rootKey, customScalarAdapters, cacheKeyGenerator, metadataGenerator, fieldKeyGenerator, embeddedFieldsProvider, maxAgeProvider) + return dataWithErrors.normalized( + executable = executable, + cacheKeyGenerator = cacheKeyGenerator, + rootKey = rootKey, + customScalarAdapters = customScalarAdapters, + metadataGenerator = metadataGenerator, + fieldKeyGenerator = fieldKeyGenerator, + embeddedFieldsProvider = embeddedFieldsProvider, + maxAgeProvider = maxAgeProvider, + ) } /** @@ -298,15 +306,28 @@ fun D.normalized( */ fun DataWithErrors.normalized( executable: Executable, + cacheKeyGenerator: CacheKeyGenerator, rootKey: CacheKey = CacheKey.QUERY_ROOT, customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, - cacheKeyGenerator: CacheKeyGenerator = @Suppress("DEPRECATION") TypePolicyCacheKeyGenerator, metadataGenerator: MetadataGenerator = EmptyMetadataGenerator, fieldKeyGenerator: FieldKeyGenerator = DefaultFieldKeyGenerator, embeddedFieldsProvider: EmbeddedFieldsProvider = EmptyEmbeddedFieldsProvider, maxAgeProvider: MaxAgeProvider = DefaultMaxAgeProvider, ): Map { val variables = executable.variables(customScalarAdapters, withDefaultValues = true) - return Normalizer(variables, rootKey, cacheKeyGenerator, metadataGenerator, fieldKeyGenerator, embeddedFieldsProvider, maxAgeProvider) - .normalize(this, executable.rootField().selections, executable.rootField().type.rawType(), listOf(executable.rootField())) + return Normalizer( + variables = variables, + rootKey = rootKey, + cacheKeyGenerator = cacheKeyGenerator, + metadataGenerator = metadataGenerator, + fieldKeyGenerator = fieldKeyGenerator, + embeddedFieldsProvider = embeddedFieldsProvider, + maxAgeProvider = maxAgeProvider, + ) + .normalize( + map = this, + selections = executable.rootField().selections, + parentType = executable.rootField().type.rawType(), + fieldPath = listOf(executable.rootField()), + ) } diff --git a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/memory/MemoryCache.kt b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/memory/MemoryCache.kt index e91a857a5..404d1c782 100644 --- a/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/memory/MemoryCache.kt +++ b/normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/memory/MemoryCache.kt @@ -12,7 +12,6 @@ import com.apollographql.cache.normalized.api.withDates import com.apollographql.cache.normalized.internal.withReentrantLock import com.apollographql.cache.normalized.memory.internal.LruCache import kotlinx.coroutines.sync.Mutex -import kotlin.jvm.JvmOverloads import kotlin.reflect.KClass /** @@ -150,7 +149,7 @@ class MemoryCache( } } -class MemoryCacheFactory @JvmOverloads constructor( +class MemoryCacheFactory( private val maxSizeBytes: Int = Int.MAX_VALUE, private val expireAfterMillis: Long = -1, ) : NormalizedCacheFactory() { diff --git a/tests/browser/src/commonTest/kotlin/BrowserTest.kt b/tests/browser/src/commonTest/kotlin/BrowserTest.kt index 148fb0e5a..ac86dde17 100644 --- a/tests/browser/src/commonTest/kotlin/BrowserTest.kt +++ b/tests/browser/src/commonTest/kotlin/BrowserTest.kt @@ -4,6 +4,8 @@ import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.testing.QueueTestNetworkTransport import com.apollographql.apollo.testing.enqueueTestResponse import com.apollographql.cache.normalized.FetchPolicy +import com.apollographql.cache.normalized.api.CacheKey +import com.apollographql.cache.normalized.api.FieldPolicyCacheResolver import com.apollographql.cache.normalized.api.TypePolicyCacheKeyGenerator import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.normalizedCache @@ -23,7 +25,8 @@ class BrowserTest { .networkTransport(QueueTestNetworkTransport()) .normalizedCache( normalizedCacheFactory = SqlNormalizedCacheFactory(), - cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies) + cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies, CacheKey.Scope.TYPE), + cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies, CacheKey.Scope.TYPE), ) .build() .use { apolloClient -> diff --git a/tests/cache-control/src/commonTest/kotlin/ClientAndServerSideCacheControlTest.kt b/tests/cache-control/src/commonTest/kotlin/ClientAndServerSideCacheControlTest.kt index 715652ee9..a6f5994e1 100644 --- a/tests/cache-control/src/commonTest/kotlin/ClientAndServerSideCacheControlTest.kt +++ b/tests/cache-control/src/commonTest/kotlin/ClientAndServerSideCacheControlTest.kt @@ -7,6 +7,8 @@ import com.apollographql.apollo.api.Query 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.DefaultCacheKeyGenerator +import com.apollographql.cache.normalized.api.DefaultCacheResolver import com.apollographql.cache.normalized.api.GlobalMaxAgeProvider import com.apollographql.cache.normalized.api.MaxAge import com.apollographql.cache.normalized.api.NormalizedCacheFactory @@ -57,14 +59,16 @@ class ClientAndServerSideCacheControlTest { val client = ApolloClient.Builder() .normalizedCache( normalizedCacheFactory = normalizedCacheFactory, + cacheKeyGenerator = DefaultCacheKeyGenerator, cacheResolver = CacheControlCacheResolver( - SchemaCoordinatesMaxAgeProvider( + maxAgeProvider = SchemaCoordinatesMaxAgeProvider( mapOf( "User.email" to MaxAge.Duration(2.seconds), ), defaultMaxAge = 20.seconds, - ) - ) + ), + delegateResolver = DefaultCacheResolver, + ), ) .storeExpirationDate(true) .serverUrl(mockServer.url()) @@ -88,7 +92,7 @@ class ClientAndServerSideCacheControlTest { MockResponse.Builder() .addHeader("Cache-Control", "max-age=10") .body(data) - .build() + .build(), ) client.query(GetUserQuery()).fetchPolicy(FetchPolicy.NetworkOnly).cacheHeaders(receivedDate(currentTimeSeconds() - 10)).execute() @@ -106,7 +110,7 @@ class ClientAndServerSideCacheControlTest { MockResponse.Builder() .addHeader("Cache-Control", "max-age=0") .body(data) - .build() + .build(), ) client.query(GetUserQuery()).fetchPolicy(FetchPolicy.NetworkOnly).cacheHeaders(receivedDate(currentTimeSeconds())).execute() @@ -136,14 +140,16 @@ class ClientAndServerSideCacheControlTest { val client = ApolloClient.Builder() .normalizedCache( normalizedCacheFactory = normalizedCacheFactory, + cacheKeyGenerator = DefaultCacheKeyGenerator, cacheResolver = CacheControlCacheResolver( SchemaCoordinatesMaxAgeProvider( mapOf( "User.email" to MaxAge.Duration(2.seconds), ), defaultMaxAge = 20.seconds, - ) - ) + ), + delegateResolver = DefaultCacheResolver, + ), ) .storeExpirationDate(true) .serverUrl(mockServer.url()) @@ -167,7 +173,7 @@ class ClientAndServerSideCacheControlTest { MockResponse.Builder() .addHeader("Cache-Control", "max-age=10") .body(data) - .build() + .build(), ) client.query(GetUserQuery()).fetchPolicy(FetchPolicy.NetworkOnly).cacheHeaders(receivedDate(currentTimeSeconds() - 10)).execute() @@ -186,7 +192,7 @@ class ClientAndServerSideCacheControlTest { MockResponse.Builder() .addHeader("Cache-Control", "max-age=0") .body(data) - .build() + .build(), ) client.query(GetUserQuery()).fetchPolicy(FetchPolicy.NetworkOnly).cacheHeaders(receivedDate(currentTimeSeconds())).execute() @@ -215,8 +221,9 @@ class ClientAndServerSideCacheControlTest { val mockServer = MockServer() val client = ApolloClient.Builder() .normalizedCache( + cacheKeyGenerator = DefaultCacheKeyGenerator, normalizedCacheFactory = normalizedCacheFactory, - cacheResolver = CacheControlCacheResolver(GlobalMaxAgeProvider(1.days)), + cacheResolver = CacheControlCacheResolver(GlobalMaxAgeProvider(1.days), DefaultCacheResolver), ) .serverUrl(mockServer.url()) .build() diff --git a/tests/cache-control/src/commonTest/kotlin/ClientSideCacheControlTest.kt b/tests/cache-control/src/commonTest/kotlin/ClientSideCacheControlTest.kt index c9da8e27d..e5ae2b95b 100644 --- a/tests/cache-control/src/commonTest/kotlin/ClientSideCacheControlTest.kt +++ b/tests/cache-control/src/commonTest/kotlin/ClientSideCacheControlTest.kt @@ -7,6 +7,8 @@ import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.ApolloCacheHeaders import com.apollographql.cache.normalized.api.CacheControlCacheResolver import com.apollographql.cache.normalized.api.CacheHeaders +import com.apollographql.cache.normalized.api.DefaultCacheKeyGenerator +import com.apollographql.cache.normalized.api.DefaultCacheResolver import com.apollographql.cache.normalized.api.DefaultRecordMerger import com.apollographql.cache.normalized.api.GlobalMaxAgeProvider import com.apollographql.cache.normalized.api.MaxAge @@ -103,7 +105,8 @@ class ClientSideCacheControlTest { val client = ApolloClient.Builder() .normalizedCache( normalizedCacheFactory = normalizedCacheFactory, - cacheResolver = CacheControlCacheResolver(GlobalMaxAgeProvider(maxAge.seconds)), + cacheKeyGenerator = DefaultCacheKeyGenerator, + cacheResolver = CacheControlCacheResolver(GlobalMaxAgeProvider(maxAge.seconds), DefaultCacheResolver), ) .serverUrl("unused") .build() @@ -112,7 +115,7 @@ class ClientSideCacheControlTest { val query = ProgrammaticGetUserQuery() val data = ProgrammaticGetUserQuery.Data(ProgrammaticGetUserQuery.User("John", "john@doe.com", true)) - val records = data.normalized(query).values + val records = data.normalized(query, DefaultCacheKeyGenerator).values client.apolloStore.accessCache { // store records in the past @@ -150,7 +153,8 @@ class ClientSideCacheControlTest { val client = ApolloClient.Builder() .normalizedCache( normalizedCacheFactory = normalizedCacheFactory, - cacheResolver = CacheControlCacheResolver(maxAgeProvider), + cacheKeyGenerator = DefaultCacheKeyGenerator, + cacheResolver = CacheControlCacheResolver(maxAgeProvider, DefaultCacheResolver), ) .serverUrl("unused") .build() @@ -203,7 +207,7 @@ class ClientSideCacheControlTest { private suspend fun mergeProgrammaticCompanyQueryResults(client: ApolloClient, secondsAgo: Int) { val data = ProgrammaticGetCompanyQuery.Data(ProgrammaticGetCompanyQuery.Company(id = "42")) - val records = data.normalized(ProgrammaticGetCompanyQuery()).values + val records = data.normalized(ProgrammaticGetCompanyQuery(), DefaultCacheKeyGenerator).values client.apolloStore.accessCache { it.merge(records, receivedDate(currentTimeSeconds() - secondsAgo), DefaultRecordMerger) } @@ -276,7 +280,7 @@ class ClientSideCacheControlTest { private suspend fun mergeDeclarativeCompanyQueryResults(client: ApolloClient, secondsAgo: Int = 0) { val data = DeclarativeGetCompanyQuery.Data(DeclarativeGetCompanyQuery.Company(__typename = "Company", id = "42")) - val records = data.normalized(DeclarativeGetCompanyQuery()).values + val records = data.normalized(DeclarativeGetCompanyQuery(), DefaultCacheKeyGenerator).values client.apolloStore.accessCache { it.merge(records, receivedDate(currentTimeSeconds() - secondsAgo), DefaultRecordMerger) } @@ -285,7 +289,7 @@ class ClientSideCacheControlTest { private suspend fun mergeUserQueryResults(client: ApolloClient, secondsAgo: Int = 0) { val data = DeclarativeGetUserQuery.Data(DeclarativeGetUserQuery.User(__typename = "User", name = "John", email = "john@doe.com", admin = true)) - val records = data.normalized(DeclarativeGetUserQuery()).values + val records = data.normalized(DeclarativeGetUserQuery(), DefaultCacheKeyGenerator).values client.apolloStore.accessCache { it.merge(records, receivedDate(currentTimeSeconds() - secondsAgo), DefaultRecordMerger) } @@ -293,7 +297,7 @@ class ClientSideCacheControlTest { private suspend fun mergeProjectQueryResults(client: ApolloClient, secondsAgo: Int = 0) { val data = DeclarativeGetProjectQuery.Data(DeclarativeGetProjectQuery.Project(__typename = "Project", id = "42", name = "Stardust")) - val records = data.normalized(DeclarativeGetProjectQuery()).values + val records = data.normalized(DeclarativeGetProjectQuery(), DefaultCacheKeyGenerator).values 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 46d5cfe1e..4d1346198 100644 --- a/tests/cache-control/src/commonTest/kotlin/DoNotStoreTest.kt +++ b/tests/cache-control/src/commonTest/kotlin/DoNotStoreTest.kt @@ -13,8 +13,10 @@ import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.DefaultFieldKeyGenerator import com.apollographql.cache.normalized.api.FieldKeyContext import com.apollographql.cache.normalized.api.FieldKeyGenerator +import com.apollographql.cache.normalized.api.FieldPolicyCacheResolver import com.apollographql.cache.normalized.api.NormalizedCacheFactory import com.apollographql.cache.normalized.api.SchemaCoordinatesMaxAgeProvider +import com.apollographql.cache.normalized.api.TypePolicyCacheKeyGenerator import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.fetchFromCache import com.apollographql.cache.normalized.fetchPolicy @@ -97,6 +99,8 @@ class DoNotStoreTest { .serverUrl(mockServer.url()) .normalizedCache( normalizedCacheFactory = normalizedCacheFactory, + cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), + cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies), maxAgeProvider = maxAgeProvider, ) .build() @@ -195,8 +199,10 @@ class DoNotStoreTest { .serverUrl(mockServer.url()) .normalizedCache( normalizedCacheFactory = normalizedCacheFactory, + cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), + cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies), maxAgeProvider = maxAgeProvider, - fieldKeyGenerator = fieldKeyGenerator + fieldKeyGenerator = fieldKeyGenerator, ) .build() .use { apolloClient -> diff --git a/tests/cache-control/src/commonTest/kotlin/ServerSideCacheControlTest.kt b/tests/cache-control/src/commonTest/kotlin/ServerSideCacheControlTest.kt index e2a7bf260..8a857a8dd 100644 --- a/tests/cache-control/src/commonTest/kotlin/ServerSideCacheControlTest.kt +++ b/tests/cache-control/src/commonTest/kotlin/ServerSideCacheControlTest.kt @@ -5,6 +5,9 @@ import com.apollographql.apollo.api.ApolloResponse 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.DefaultCacheKeyGenerator +import com.apollographql.cache.normalized.api.DefaultCacheResolver +import com.apollographql.cache.normalized.api.DefaultMaxAgeProvider import com.apollographql.cache.normalized.api.NormalizedCacheFactory import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.fetchPolicy @@ -43,7 +46,8 @@ class ServerSideCacheControlTest { val client = ApolloClient.Builder() .normalizedCache( normalizedCacheFactory = normalizedCacheFactory, - cacheResolver = CacheControlCacheResolver(), + cacheKeyGenerator = DefaultCacheKeyGenerator, + cacheResolver = CacheControlCacheResolver(DefaultMaxAgeProvider, DefaultCacheResolver), ) .storeExpirationDate(true) .serverUrl(mockServer.url()) diff --git a/tests/cache-options/src/commonTest/kotlin/test/CacheOptionsTest.kt b/tests/cache-options/src/commonTest/kotlin/test/CacheOptionsTest.kt index 4a90c6bbf..3d85e471b 100644 --- a/tests/cache-options/src/commonTest/kotlin/test/CacheOptionsTest.kt +++ b/tests/cache-options/src/commonTest/kotlin/test/CacheOptionsTest.kt @@ -8,6 +8,8 @@ import com.apollographql.apollo.api.Operation import com.apollographql.apollo.exception.CacheMissException import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy +import com.apollographql.cache.normalized.api.FieldPolicyCacheResolver +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 @@ -23,6 +25,7 @@ import kotlinx.coroutines.flow.emitAll import kotlinx.coroutines.flow.onCompletion import kotlinx.coroutines.flow.toList import okio.use +import test.cache.Cache import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertIs @@ -41,11 +44,26 @@ class CacheOptionsTest { mockServer.close() } - private val memoryCacheManager = CacheManager(MemoryCacheFactory()) + private val memoryCacheManager = + CacheManager( + normalizedCacheFactory = MemoryCacheFactory(), + cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), + cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies), + ) - private val sqlCacheManager = CacheManager(SqlNormalizedCacheFactory()) + private val sqlCacheManager = + CacheManager( + normalizedCacheFactory = SqlNormalizedCacheFactory(), + cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), + cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies), + ) - private val memoryThenSqlCacheManager = CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory())) + private val memoryThenSqlCacheManager = + CacheManager( + normalizedCacheFactory = MemoryCacheFactory().chain(SqlNormalizedCacheFactory()), + cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), + cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies), + ) @Test fun simpleMemory() = runTest(before = { setUp() }, after = { tearDown() }) { @@ -83,7 +101,7 @@ class CacheOptionsTest { } ] } - """ + """, ) ApolloClient.Builder() .serverUrl(mockServer.url()) @@ -100,16 +118,16 @@ class CacheOptionsTest { id = "1", firstName = "John", lastName = "Smith", - nickName = null - ) + nickName = null, + ), ), - networkResult.data + networkResult.data, ) assertErrorsEquals( listOf( - Error.Builder("'nickName' can't be reached").path(listOf("me", "nickName")).build() + Error.Builder("'nickName' can't be reached").path(listOf("me", "nickName")).build(), ), - networkResult.errors + networkResult.errors, ) val cacheResult = apolloClient.query(MeWithNickNameQuery()) @@ -117,11 +135,11 @@ class CacheOptionsTest { .execute() assertEquals( networkResult.data, - cacheResult.data + cacheResult.data, ) assertErrorsEquals( networkResult.errors, - cacheResult.errors + cacheResult.errors, ) } } @@ -156,7 +174,7 @@ class CacheOptionsTest { } } } - """ + """, ) mockServer.enqueueString( // language=JSON @@ -172,7 +190,7 @@ class CacheOptionsTest { } ] } - """ + """, ) ApolloClient.Builder() .serverUrl(mockServer.url()) @@ -190,9 +208,9 @@ class CacheOptionsTest { firstName = "John", lastName = "Smith", email = "jdoe@example.com", - ) + ), ), - networkResult1.data + networkResult1.data, ) assertNull(networkResult1.errors) @@ -201,15 +219,15 @@ class CacheOptionsTest { .execute() assertEquals( UserByCategoryQuery.Data( - user = null + user = null, ), - networkResult2.data + networkResult2.data, ) assertErrorsEquals( listOf( - Error.Builder("'User' can't be reached").path(listOf("user")).build() + Error.Builder("'User' can't be reached").path(listOf("user")).build(), ), - networkResult2.errors + networkResult2.errors, ) val cacheResult = apolloClient.query(UserByCategoryQuery(Category(1, "test2"))) @@ -219,11 +237,11 @@ class CacheOptionsTest { .execute() assertEquals( networkResult2.data, - cacheResult.data + cacheResult.data, ) assertErrorsEquals( networkResult2.errors, - cacheResult.errors + cacheResult.errors, ) } } @@ -275,7 +293,7 @@ class CacheOptionsTest { } ] } - """ + """, ) mockServer.enqueueString( // language=JSON @@ -307,7 +325,7 @@ class CacheOptionsTest { } ] } - """ + """, ) ApolloClient.Builder() @@ -336,15 +354,15 @@ class CacheOptionsTest { email = "jdoe@example.com", ), null, - ) + ), ), - networkResult1.data + networkResult1.data, ) assertErrorsEquals( listOf( - Error.Builder("User `3` not found").path(listOf("users", 2)).build() + Error.Builder("User `3` not found").path(listOf("users", 2)).build(), ), - networkResult1.errors + networkResult1.errors, ) val networkResult2 = apolloClient.query(UsersQuery(listOf("4", "5", "6"))) @@ -368,15 +386,15 @@ class CacheOptionsTest { email = "ajohnson@example.com", ), null, - ) + ), ), - networkResult2.data + networkResult2.data, ) assertErrorsEquals( listOf( - Error.Builder("User `6` not found").path(listOf("users", 2)).build() + Error.Builder("User `6` not found").path(listOf("users", 2)).build(), ), - networkResult2.errors + networkResult2.errors, ) @@ -419,7 +437,7 @@ class CacheOptionsTest { ), null, null, - ) + ), ), cacheResult.data, ) @@ -474,7 +492,7 @@ class CacheOptionsTest { ] } } - """ + """, ) mockServer.enqueueString( // language=JSON @@ -500,7 +518,7 @@ class CacheOptionsTest { ] } } - """ + """, ) ApolloClient.Builder() @@ -529,9 +547,9 @@ class CacheOptionsTest { email = "jdoe@example.com", ), null, - ) + ), ), - networkResult1.data + networkResult1.data, ) assertNull(networkResult1.errors) @@ -556,9 +574,9 @@ class CacheOptionsTest { email = "ajohnson@example.com", ), null, - ) + ), ), - networkResult2.data + networkResult2.data, ) assertNull(networkResult2.errors) @@ -601,7 +619,7 @@ class CacheOptionsTest { email = "ajohnson@example.com", ), null, - ) + ), ), cacheResult.data, ) @@ -656,7 +674,7 @@ class CacheOptionsTest { } ] } - """ + """, ) ApolloClient.Builder() @@ -685,15 +703,15 @@ class CacheOptionsTest { email = "jdoe@example.com", ), null, - ) + ), ), - networkResult1.data + networkResult1.data, ) assertErrorsEquals( listOf( - Error.Builder("User `3` not found").path(listOf("allUsers", 2)).build() + Error.Builder("User `3` not found").path(listOf("allUsers", 2)).build(), ), - networkResult1.errors + networkResult1.errors, ) val cacheResult1 = apolloClient.query(AllUsersQuery()) @@ -719,7 +737,7 @@ class CacheOptionsTest { email = "jdoe@example.com", ), null, - ) + ), ), cacheResult1.data, ) @@ -754,7 +772,7 @@ class CacheOptionsTest { ), null, null, - ) + ), ), cacheResult2.data, ) @@ -808,7 +826,7 @@ class CacheOptionsTest { } ] } - """ + """, ) ApolloClient.Builder() .serverUrl(mockServer.url()) @@ -827,16 +845,16 @@ class CacheOptionsTest { id = "1", firstName = "John", lastName = "Smith", - nickName = null - ) + nickName = null, + ), ), - networkResult.data + networkResult.data, ) assertErrorsEquals( listOf( - Error.Builder("'nickName' can't be reached").path(listOf("me", "nickName")).build() + Error.Builder("'nickName' can't be reached").path(listOf("me", "nickName")).build(), ), - networkResult.errors + networkResult.errors, ) val cacheResult = apolloClient.query(MeWithNickNameAndProjectQuery()) @@ -850,16 +868,16 @@ class CacheOptionsTest { firstName = "John", lastName = "Smith", nickName = null, - bestFriend = null - ) + bestFriend = null, + ), ), - cacheResult.data + cacheResult.data, ) assertErrorsEquals( networkResult.errors!! + listOf( - Error.Builder("Object 'User:1' has no field named 'bestFriend' in the cache").path(listOf("me", "bestFriend")).build() + Error.Builder("Object 'User:1' has no field named 'bestFriend' in the cache").path(listOf("me", "bestFriend")).build(), ), - cacheResult.errors + cacheResult.errors, ) } } @@ -894,7 +912,7 @@ class CacheOptionsTest { } } } - """ + """, ) ApolloClient.Builder() .serverUrl(mockServer.url()) @@ -915,10 +933,10 @@ class CacheOptionsTest { id = "1", firstName = "John", lastName = "Smith", - nickName = "js" - ) + nickName = "js", + ), ), - results[1].data + results[1].data, ) assertNull(results[1].exception) } diff --git a/tests/cache-variables-arguments/src/commonTest/kotlin/test/CacheArgumentTest.kt b/tests/cache-variables-arguments/src/commonTest/kotlin/test/CacheArgumentTest.kt index 697d4f79c..483fe99b4 100644 --- a/tests/cache-variables-arguments/src/commonTest/kotlin/test/CacheArgumentTest.kt +++ b/tests/cache-variables-arguments/src/commonTest/kotlin/test/CacheArgumentTest.kt @@ -7,6 +7,7 @@ import cache.include.VariableDefaultValueEmptyQuery import cache.include.VariableDefaultValueNullQuery import cache.include.VariableDefaultValueWithCQuery import com.apollographql.apollo.api.Operation +import com.apollographql.cache.normalized.api.DefaultCacheKeyGenerator import com.apollographql.cache.normalized.internal.normalized import kotlin.test.Test import kotlin.test.assertEquals @@ -82,7 +83,7 @@ class CacheArgumentTest { } private fun Operation.fieldKey(data: D): String { - val record = data.normalized(this) + val record = data.normalized(this, DefaultCacheKeyGenerator) return record.values.single().keys.single { it.startsWith("a") } } 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 7fe5b2ee4..3cc42c824 100644 --- a/tests/cache-variables-arguments/src/commonTest/kotlin/test/IncludeTest.kt +++ b/tests/cache-variables-arguments/src/commonTest/kotlin/test/IncludeTest.kt @@ -3,6 +3,8 @@ package test import cache.include.GetUserQuery import com.apollographql.apollo.ApolloClient import com.apollographql.cache.normalized.FetchPolicy +import com.apollographql.cache.normalized.api.DefaultCacheKeyGenerator +import com.apollographql.cache.normalized.api.DefaultCacheResolver import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory @@ -15,7 +17,7 @@ class IncludeTest { @Test fun simple() = runTest { val client = ApolloClient.Builder() - .normalizedCache(MemoryCacheFactory()) + .normalizedCache(MemoryCacheFactory(), DefaultCacheKeyGenerator, DefaultCacheResolver) .serverUrl("https://unused.com") .build() diff --git a/tests/defer/src/commonTest/kotlin/test/DeferNormalizedCacheTest.kt b/tests/defer/src/commonTest/kotlin/test/DeferNormalizedCacheTest.kt index a93ff9ea9..742e3c340 100644 --- a/tests/defer/src/commonTest/kotlin/test/DeferNormalizedCacheTest.kt +++ b/tests/defer/src/commonTest/kotlin/test/DeferNormalizedCacheTest.kt @@ -15,6 +15,8 @@ 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.DefaultCacheKeyGenerator +import com.apollographql.cache.normalized.api.DefaultCacheResolver import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy @@ -58,7 +60,13 @@ class DeferNormalizedCacheTest { private lateinit var cacheManager: CacheManager private suspend fun setUp() { - cacheManager = CacheManager(MemoryCacheFactory(), enableOptimisticUpdates = true) + cacheManager = + CacheManager( + normalizedCacheFactory = MemoryCacheFactory(), + cacheKeyGenerator = DefaultCacheKeyGenerator, + cacheResolver = DefaultCacheResolver, + enableOptimisticUpdates = true, + ) mockServer = MockServer() apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() } @@ -74,7 +82,7 @@ class DeferNormalizedCacheTest { // Cache is empty assertIs( - apolloClient.query(WithFragmentSpreadsQuery()).execute().exception + apolloClient.query(WithFragmentSpreadsQuery()).execute().exception, ) // Fill the cache by doing a network only request @@ -93,13 +101,18 @@ class DeferNormalizedCacheTest { // We get the last/fully formed data val cacheExpected = WithFragmentSpreadsQuery.Data( - listOf(WithFragmentSpreadsQuery.Computer("Computer", "Computer1", ComputerFields("386", 1993, - ComputerFields.Screen("Screen", "640x480", - ScreenFields(false) - ) - ) - ) - ) + listOf( + WithFragmentSpreadsQuery.Computer( + "Computer", "Computer1", + ComputerFields( + "386", 1993, + ComputerFields.Screen( + "Screen", "640x480", + ScreenFields(false), + ), + ), + ), + ), ) assertEquals(cacheExpected, cacheActual) } @@ -125,23 +138,32 @@ class DeferNormalizedCacheTest { val networkExpected = listOf( WithFragmentSpreadsQuery.Data( - listOf(WithFragmentSpreadsQuery.Computer("Computer", "Computer1", null)) + listOf(WithFragmentSpreadsQuery.Computer("Computer", "Computer1", null)), ), WithFragmentSpreadsQuery.Data( - listOf(WithFragmentSpreadsQuery.Computer("Computer", "Computer1", ComputerFields("386", 1993, - ComputerFields.Screen("Screen", "640x480", null) - ) - ) - ) + listOf( + WithFragmentSpreadsQuery.Computer( + "Computer", "Computer1", + ComputerFields( + "386", 1993, + ComputerFields.Screen("Screen", "640x480", null), + ), + ), + ), ), WithFragmentSpreadsQuery.Data( - listOf(WithFragmentSpreadsQuery.Computer("Computer", "Computer1", ComputerFields("386", 1993, - ComputerFields.Screen("Screen", "640x480", - ScreenFields(false) - ) - ) - ) - ) + listOf( + WithFragmentSpreadsQuery.Computer( + "Computer", "Computer1", + ComputerFields( + "386", 1993, + ComputerFields.Screen( + "Screen", "640x480", + ScreenFields(false), + ), + ), + ), + ), ), ) assertEquals(networkExpected, networkActual) @@ -166,23 +188,32 @@ class DeferNormalizedCacheTest { val networkExpected = listOf( WithFragmentSpreadsQuery.Data( - listOf(WithFragmentSpreadsQuery.Computer("Computer", "Computer1", null)) + listOf(WithFragmentSpreadsQuery.Computer("Computer", "Computer1", null)), ), WithFragmentSpreadsQuery.Data( - listOf(WithFragmentSpreadsQuery.Computer("Computer", "Computer1", ComputerFields("386", 1993, - ComputerFields.Screen("Screen", "640x480", null) - ) - ) - ) + listOf( + WithFragmentSpreadsQuery.Computer( + "Computer", "Computer1", + ComputerFields( + "386", 1993, + ComputerFields.Screen("Screen", "640x480", null), + ), + ), + ), ), WithFragmentSpreadsQuery.Data( - listOf(WithFragmentSpreadsQuery.Computer("Computer", "Computer1", ComputerFields("386", 1993, - ComputerFields.Screen("Screen", "640x480", - ScreenFields(false) - ) - ) - ) - ) + listOf( + WithFragmentSpreadsQuery.Computer( + "Computer", "Computer1", + ComputerFields( + "386", 1993, + ComputerFields.Screen( + "Screen", "640x480", + ScreenFields(false), + ), + ), + ), + ), ), ) assertEquals(networkExpected, networkActual) @@ -213,23 +244,32 @@ class DeferNormalizedCacheTest { val networkExpected = listOf( WithFragmentSpreadsQuery.Data( - listOf(WithFragmentSpreadsQuery.Computer("Computer", "Computer1", null)) + listOf(WithFragmentSpreadsQuery.Computer("Computer", "Computer1", null)), ), WithFragmentSpreadsQuery.Data( - listOf(WithFragmentSpreadsQuery.Computer("Computer", "Computer1", ComputerFields("386", 1993, - ComputerFields.Screen("Screen", "640x480", null) - ) - ) - ) + listOf( + WithFragmentSpreadsQuery.Computer( + "Computer", "Computer1", + ComputerFields( + "386", 1993, + ComputerFields.Screen("Screen", "640x480", null), + ), + ), + ), ), WithFragmentSpreadsQuery.Data( - listOf(WithFragmentSpreadsQuery.Computer("Computer", "Computer1", ComputerFields("386", 1993, - ComputerFields.Screen("Screen", "640x480", - ScreenFields(false) - ) - ) - ) - ) + listOf( + WithFragmentSpreadsQuery.Computer( + "Computer", "Computer1", + ComputerFields( + "386", 1993, + ComputerFields.Screen( + "Screen", "640x480", + ScreenFields(false), + ), + ), + ), + ), ), ) assertEquals(networkExpected, networkActual) @@ -262,23 +302,32 @@ class DeferNormalizedCacheTest { val networkExpected = listOf( WithFragmentSpreadsQuery.Data( - listOf(WithFragmentSpreadsQuery.Computer("Computer", "Computer1", null)) + listOf(WithFragmentSpreadsQuery.Computer("Computer", "Computer1", null)), ), WithFragmentSpreadsQuery.Data( - listOf(WithFragmentSpreadsQuery.Computer("Computer", "Computer1", ComputerFields("386", 1993, - ComputerFields.Screen("Screen", "640x480", null) - ) - ) - ) + listOf( + WithFragmentSpreadsQuery.Computer( + "Computer", "Computer1", + ComputerFields( + "386", 1993, + ComputerFields.Screen("Screen", "640x480", null), + ), + ), + ), ), WithFragmentSpreadsQuery.Data( - listOf(WithFragmentSpreadsQuery.Computer("Computer", "Computer1", ComputerFields("386", 1993, - ComputerFields.Screen("Screen", "640x480", - ScreenFields(false) - ) - ) - ) - ) + listOf( + WithFragmentSpreadsQuery.Computer( + "Computer", "Computer1", + ComputerFields( + "386", 1993, + ComputerFields.Screen( + "Screen", "640x480", + ScreenFields(false), + ), + ), + ), + ), ), ) assertEquals(networkExpected, networkActual) @@ -299,23 +348,32 @@ class DeferNormalizedCacheTest { networkExpected.last(), WithFragmentSpreadsQuery.Data( - listOf(WithFragmentSpreadsQuery.Computer("Computer", "Computer2", null)) + listOf(WithFragmentSpreadsQuery.Computer("Computer", "Computer2", null)), ), WithFragmentSpreadsQuery.Data( - listOf(WithFragmentSpreadsQuery.Computer("Computer", "Computer2", ComputerFields("486", 1996, - ComputerFields.Screen("Screen", "800x600", null) - ) - ) - ) + listOf( + WithFragmentSpreadsQuery.Computer( + "Computer", "Computer2", + ComputerFields( + "486", 1996, + ComputerFields.Screen("Screen", "800x600", null), + ), + ), + ), ), WithFragmentSpreadsQuery.Data( - listOf(WithFragmentSpreadsQuery.Computer("Computer", "Computer2", ComputerFields("486", 1996, - ComputerFields.Screen("Screen", "800x600", - ScreenFields(true) - ) - ) - ) - ) + listOf( + WithFragmentSpreadsQuery.Computer( + "Computer", "Computer2", + ComputerFields( + "486", 1996, + ComputerFields.Screen( + "Screen", "800x600", + ScreenFields(true), + ), + ), + ), + ), ), ) @@ -344,21 +402,27 @@ class DeferNormalizedCacheTest { ApolloResponse.Builder( query, uuid, - ).data(WithFragmentSpreadsQuery.Data( - listOf(WithFragmentSpreadsQuery.Computer("Computer", "Computer1", null)) - ) + ).data( + WithFragmentSpreadsQuery.Data( + listOf(WithFragmentSpreadsQuery.Computer("Computer", "Computer1", null)), + ), ).build(), ApolloResponse.Builder( query, uuid, - ).data(WithFragmentSpreadsQuery.Data( - listOf(WithFragmentSpreadsQuery.Computer("Computer", "Computer1", ComputerFields("386", 1993, - ComputerFields.Screen("Screen", "640x480", null) - ) - ) - ) - ) + ).data( + WithFragmentSpreadsQuery.Data( + listOf( + WithFragmentSpreadsQuery.Computer( + "Computer", "Computer1", + ComputerFields( + "386", 1993, + ComputerFields.Screen("Screen", "640x480", null), + ), + ), + ), + ), ).build(), ApolloResponse.Builder( @@ -367,20 +431,24 @@ class DeferNormalizedCacheTest { ) .data( WithFragmentSpreadsQuery.Data( - listOf(WithFragmentSpreadsQuery.Computer("Computer", "Computer1", ComputerFields("386", 1993, - ComputerFields.Screen("Screen", "640x480", null) - ) - ) - ) - ) + listOf( + WithFragmentSpreadsQuery.Computer( + "Computer", "Computer1", + ComputerFields( + "386", 1993, + ComputerFields.Screen("Screen", "640x480", null), + ), + ), + ), + ), ) .errors( listOf( Error.Builder(message = "Cannot resolve isColor") .locations(listOf(Error.Location(1, 119))) .path(listOf("computers", 0, "screen", "isColor")) - .build() - ) + .build(), + ), ) .build(), ) @@ -403,21 +471,27 @@ class DeferNormalizedCacheTest { ApolloResponse.Builder( query, uuid, - ).data(WithFragmentSpreadsQuery.Data( - listOf(WithFragmentSpreadsQuery.Computer("Computer", "Computer1", null)) - ) + ).data( + WithFragmentSpreadsQuery.Data( + listOf(WithFragmentSpreadsQuery.Computer("Computer", "Computer1", null)), + ), ).build(), ApolloResponse.Builder( query, uuid, - ).data(WithFragmentSpreadsQuery.Data( - listOf(WithFragmentSpreadsQuery.Computer("Computer", "Computer1", ComputerFields("386", 1993, - ComputerFields.Screen("Screen", "640x480", null) - ) - ) - ) - ) + ).data( + WithFragmentSpreadsQuery.Data( + listOf( + WithFragmentSpreadsQuery.Computer( + "Computer", "Computer1", + ComputerFields( + "386", 1993, + ComputerFields.Screen("Screen", "640x480", null), + ), + ), + ), + ), ).build(), ) @@ -434,16 +508,17 @@ class DeferNormalizedCacheTest { emit(networkResponse as ApolloResponse) } delay(10) - emit(ApolloResponse.Builder(requestUuid = uuid, operation = query) - .exception(ApolloNetworkException("Network error")) - .isLast(true) - .build() as ApolloResponse + emit( + ApolloResponse.Builder(requestUuid = uuid, operation = query) + .exception(ApolloNetworkException("Network error")) + .isLast(true) + .build() as ApolloResponse, ) } } override fun dispose() {} - } + }, ) .build() @@ -475,23 +550,32 @@ class DeferNormalizedCacheTest { val networkExpected = listOf( WithFragmentSpreadsMutation.Data( - listOf(WithFragmentSpreadsMutation.Computer("Computer", "Computer1", null)) + listOf(WithFragmentSpreadsMutation.Computer("Computer", "Computer1", null)), ), WithFragmentSpreadsMutation.Data( - listOf(WithFragmentSpreadsMutation.Computer("Computer", "Computer1", ComputerFields("386", 1993, - ComputerFields.Screen("Screen", "640x480", null) - ) - ) - ) + listOf( + WithFragmentSpreadsMutation.Computer( + "Computer", "Computer1", + ComputerFields( + "386", 1993, + ComputerFields.Screen("Screen", "640x480", null), + ), + ), + ), ), WithFragmentSpreadsMutation.Data( - listOf(WithFragmentSpreadsMutation.Computer("Computer", "Computer1", ComputerFields("386", 1993, - ComputerFields.Screen("Screen", "640x480", - ScreenFields(false) - ) - ) - ) - ) + listOf( + WithFragmentSpreadsMutation.Computer( + "Computer", "Computer1", + ComputerFields( + "386", 1993, + ComputerFields.Screen( + "Screen", "640x480", + ScreenFields(false), + ), + ), + ), + ), ), ) assertEquals(networkExpected, networkActual) @@ -501,10 +585,12 @@ class DeferNormalizedCacheTest { println(cacheActual) // We get the last/fully formed data - val cacheExpected = ComputerFields("386", 1993, - ComputerFields.Screen("Screen", "640x480", - ScreenFields(false) - ) + val cacheExpected = ComputerFields( + "386", 1993, + ComputerFields.Screen( + "Screen", "640x480", + ScreenFields(false), + ), ) assertEquals(cacheExpected, cacheActual) } @@ -519,8 +605,8 @@ class DeferNormalizedCacheTest { mockServer.enqueueMultipart("application/json").enqueueStrings(jsonList) val responses = apolloClient.mutation(WithFragmentSpreadsMutation()).optimisticUpdates( WithFragmentSpreadsMutation.Data( - listOf(WithFragmentSpreadsMutation.Computer("Computer", "Computer1", null)) - ) + listOf(WithFragmentSpreadsMutation.Computer("Computer", "Computer1", null)), + ), ).toFlow() val exception = assertFailsWith { diff --git a/tests/garbage-collection/src/commonTest/kotlin/DanglingReferencesTest.kt b/tests/garbage-collection/src/commonTest/kotlin/DanglingReferencesTest.kt index ccf0bfab8..2cc05e0b0 100644 --- a/tests/garbage-collection/src/commonTest/kotlin/DanglingReferencesTest.kt +++ b/tests/garbage-collection/src/commonTest/kotlin/DanglingReferencesTest.kt @@ -5,6 +5,8 @@ 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.FieldPolicyCacheResolver +import com.apollographql.cache.normalized.api.TypePolicyCacheKeyGenerator import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy @@ -18,6 +20,7 @@ import com.apollographql.mockserver.MockServer import com.apollographql.mockserver.enqueueString import kotlinx.coroutines.test.TestResult import okio.use +import test.cache.Cache import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFalse @@ -25,14 +28,16 @@ import kotlin.test.assertTrue class DanglingReferencesTest { @Test - fun simpleMemory() = simple(CacheManager(MemoryCacheFactory())) + fun simpleMemory() = + simple(CacheManager(MemoryCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies))) @Test - fun simpleSql() = simple(CacheManager(SqlNormalizedCacheFactory())) + fun simpleSql() = + simple(CacheManager(SqlNormalizedCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies))) @Test fun simpleChained(): TestResult { - return simple(CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) + return simple(CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies))) } private fun simple(cacheManager: CacheManager) = runTest { @@ -68,13 +73,16 @@ class DanglingReferencesTest { } @Test - fun multipleMemory() = multiple(CacheManager(MemoryCacheFactory())) + fun multipleMemory() = + multiple(CacheManager(MemoryCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies))) @Test - fun multipleSql() = multiple(CacheManager(SqlNormalizedCacheFactory())) + fun multipleSql() = + multiple(CacheManager(SqlNormalizedCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies))) @Test - fun multipleChained() = multiple(CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) + fun multipleChained() = + multiple(CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies))) private fun multiple(cacheManager: CacheManager) = runTest { val mockServer = MockServer() diff --git a/tests/garbage-collection/src/commonTest/kotlin/GarbageCollectTest.kt b/tests/garbage-collection/src/commonTest/kotlin/GarbageCollectTest.kt index 6745813db..da8e637b1 100644 --- a/tests/garbage-collection/src/commonTest/kotlin/GarbageCollectTest.kt +++ b/tests/garbage-collection/src/commonTest/kotlin/GarbageCollectTest.kt @@ -5,7 +5,9 @@ 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.FieldPolicyCacheResolver import com.apollographql.cache.normalized.api.SchemaCoordinatesMaxAgeProvider +import com.apollographql.cache.normalized.api.TypePolicyCacheKeyGenerator import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.cacheHeaders import com.apollographql.cache.normalized.cacheManager @@ -26,13 +28,16 @@ import kotlin.time.Duration.Companion.seconds class GarbageCollectTest { @Test - fun garbageCollectMemory() = garbageCollect(CacheManager(MemoryCacheFactory())) + fun garbageCollectMemory() = + garbageCollect(CacheManager(MemoryCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies))) @Test - fun garbageCollectSql() = garbageCollect(CacheManager(SqlNormalizedCacheFactory())) + fun garbageCollectSql() = + garbageCollect(CacheManager(SqlNormalizedCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies))) @Test - fun garbageCollectChained() = garbageCollect(CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) + fun garbageCollectChained() = + garbageCollect(CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies))) private fun garbageCollect(cacheManager: CacheManager) = runTest { val mockServer = MockServer() diff --git a/tests/garbage-collection/src/commonTest/kotlin/ReachableCacheKeysTest.kt b/tests/garbage-collection/src/commonTest/kotlin/ReachableCacheKeysTest.kt index c9e6bbb91..2d7c1c985 100644 --- a/tests/garbage-collection/src/commonTest/kotlin/ReachableCacheKeysTest.kt +++ b/tests/garbage-collection/src/commonTest/kotlin/ReachableCacheKeysTest.kt @@ -5,6 +5,8 @@ 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.FieldPolicyCacheResolver +import com.apollographql.cache.normalized.api.TypePolicyCacheKeyGenerator import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy @@ -17,6 +19,7 @@ import com.apollographql.cache.normalized.testing.runTest import com.apollographql.mockserver.MockServer import com.apollographql.mockserver.enqueueString import okio.use +import test.cache.Cache import test.fragment.RepositoryFragment import test.fragment.RepositoryFragmentImpl import kotlin.test.Test @@ -24,13 +27,16 @@ import kotlin.test.assertEquals class ReachableCacheKeysTest { @Test - fun getReachableCacheKeysMemory() = getReachableCacheKeys(CacheManager(MemoryCacheFactory())) + fun getReachableCacheKeysMemory() = + getReachableCacheKeys(CacheManager(MemoryCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies))) @Test - fun getReachableCacheKeysSql() = getReachableCacheKeys(CacheManager(SqlNormalizedCacheFactory())) + fun getReachableCacheKeysSql() = + getReachableCacheKeys(CacheManager(SqlNormalizedCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies))) @Test - fun getReachableCacheKeysChained() = getReachableCacheKeys(CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) + fun getReachableCacheKeysChained() = + getReachableCacheKeys(CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies))) private fun getReachableCacheKeys(cacheManager: CacheManager) = runTest { val mockServer = MockServer() diff --git a/tests/garbage-collection/src/commonTest/kotlin/StaleFieldsTest.kt b/tests/garbage-collection/src/commonTest/kotlin/StaleFieldsTest.kt index 0f841100e..5a43f7d2c 100644 --- a/tests/garbage-collection/src/commonTest/kotlin/StaleFieldsTest.kt +++ b/tests/garbage-collection/src/commonTest/kotlin/StaleFieldsTest.kt @@ -8,8 +8,10 @@ import com.apollographql.cache.normalized.allRecords import com.apollographql.cache.normalized.api.ApolloCacheHeaders import com.apollographql.cache.normalized.api.CacheHeaders import com.apollographql.cache.normalized.api.CacheKey +import com.apollographql.cache.normalized.api.FieldPolicyCacheResolver import com.apollographql.cache.normalized.api.GlobalMaxAgeProvider import com.apollographql.cache.normalized.api.SchemaCoordinatesMaxAgeProvider +import com.apollographql.cache.normalized.api.TypePolicyCacheKeyGenerator import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.cacheHeaders import com.apollographql.cache.normalized.cacheManager @@ -33,14 +35,16 @@ import kotlin.time.Duration.Companion.seconds class StaleFieldsTest { @Test - fun clientControlledRemoveFieldsMemory() = clientControlledRemoveFields(CacheManager(MemoryCacheFactory())) + fun clientControlledRemoveFieldsMemory() = + clientControlledRemoveFields(CacheManager(MemoryCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies))) @Test - fun clientControlledRemoveFieldsSql() = clientControlledRemoveFields(CacheManager(SqlNormalizedCacheFactory())) + fun clientControlledRemoveFieldsSql() = + clientControlledRemoveFields(CacheManager(SqlNormalizedCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies))) @Test fun clientControlledRemoveFieldsChained() = - clientControlledRemoveFields(CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) + clientControlledRemoveFields(CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies))) private fun clientControlledRemoveFields(cacheManager: CacheManager) = runTest { val mockServer = MockServer() @@ -110,14 +114,16 @@ class StaleFieldsTest { } @Test - fun clientControlledRemoveRecordsMemory() = clientControlledRemoveRecords(CacheManager(MemoryCacheFactory())) + fun clientControlledRemoveRecordsMemory() = + clientControlledRemoveRecords(CacheManager(MemoryCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies))) @Test - fun clientControlledRemoveRecordsSql() = clientControlledRemoveRecords(CacheManager(SqlNormalizedCacheFactory())) + fun clientControlledRemoveRecordsSql() = + clientControlledRemoveRecords(CacheManager(SqlNormalizedCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies))) @Test fun clientControlledRemoveRecordsChained() = - clientControlledRemoveRecords(CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) + clientControlledRemoveRecords(CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies))) private fun clientControlledRemoveRecords(cacheManager: CacheManager) = runTest { val mockServer = MockServer() @@ -188,14 +194,16 @@ class StaleFieldsTest { } @Test - fun serverControlledRemoveFieldsMemory() = serverControlledRemoveFields(CacheManager(MemoryCacheFactory())) + fun serverControlledRemoveFieldsMemory() = + serverControlledRemoveFields(CacheManager(MemoryCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies))) @Test - fun serverControlledRemoveFieldsSql() = serverControlledRemoveFields(CacheManager(SqlNormalizedCacheFactory())) + fun serverControlledRemoveFieldsSql() = + serverControlledRemoveFields(CacheManager(SqlNormalizedCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies))) @Test fun serverControlledRemoveFieldsChained() = - serverControlledRemoveFields(CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()))) + serverControlledRemoveFields(CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies))) private fun serverControlledRemoveFields(cacheManager: CacheManager) = runTest { val mockServer = MockServer() diff --git a/tests/include-skip-operation-based/src/commonTest/kotlin/IncludeTest.kt b/tests/include-skip-operation-based/src/commonTest/kotlin/IncludeTest.kt index 8d7a247f0..b0f859cb8 100644 --- a/tests/include-skip-operation-based/src/commonTest/kotlin/IncludeTest.kt +++ b/tests/include-skip-operation-based/src/commonTest/kotlin/IncludeTest.kt @@ -1,6 +1,7 @@ import com.apollographql.apollo.api.Optional import com.apollographql.cache.normalized.api.CacheKey +import com.apollographql.cache.normalized.api.DefaultCacheKeyGenerator import com.apollographql.cache.normalized.internal.normalized import com.apollographql.cache.normalized.testing.runTest import com.example.GetCatIncludeVariableWithDefaultQuery @@ -21,7 +22,7 @@ class IncludeTest { } } - val normalized = data.normalized(operation) + val normalized = data.normalized(operation, DefaultCacheKeyGenerator) assertNull((normalized[CacheKey("animal")] as Map<*, *>)["species"]) } @@ -35,7 +36,7 @@ class IncludeTest { } } - val normalized = data.normalized(operation) + val normalized = data.normalized(operation, DefaultCacheKeyGenerator) assertNull((normalized[CacheKey("animal")] as Map<*, *>)["barf"]) } } diff --git a/tests/migration/src/commonTest/kotlin/MigrationTest.kt b/tests/migration/src/commonTest/kotlin/MigrationTest.kt index 3386cb184..5ee96765c 100644 --- a/tests/migration/src/commonTest/kotlin/MigrationTest.kt +++ b/tests/migration/src/commonTest/kotlin/MigrationTest.kt @@ -8,6 +8,8 @@ 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.IdCacheKeyGenerator +import com.apollographql.cache.normalized.api.IdCacheResolver import com.apollographql.cache.normalized.api.Record import com.apollographql.cache.normalized.api.RecordValue import com.apollographql.cache.normalized.cacheManager @@ -92,7 +94,8 @@ class MigrationTest { } // Open the legacy store which empties it. Add/read some data to make sure it works. - val cacheManager = CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory(name = name))) + val cacheManager = + CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory(name = name)), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheResolver()) ApolloClient.Builder() .serverUrl(mockServer.url()) .cacheManager(cacheManager) @@ -138,7 +141,8 @@ class MigrationTest { } // Create a modern store and migrate the legacy data - val cacheManager = CacheManager(SqlNormalizedCacheFactory(name = "modern.db")).also { it.clearAll() } + val cacheManager = + CacheManager(SqlNormalizedCacheFactory(name = "modern.db"), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheResolver()).also { it.clearAll() } cacheManager.migrateFrom(legacyStore) // Read the data back 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 27166246a..aa0b13854 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 @@ -10,6 +10,7 @@ import com.apollographql.apollo.api.Query 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.IdCacheResolver import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory @@ -32,7 +33,8 @@ class BasicTest { private suspend fun setUp() { cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), - cacheKeyGenerator = IdCacheKeyGenerator() + cacheKeyGenerator = IdCacheKeyGenerator(), + cacheResolver = IdCacheResolver(), ) mockServer = MockServer() apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() 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 43b16c5ef..ee606892b 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 @@ -10,6 +10,7 @@ import com.apollographql.apollo.ApolloClient 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.api.IdCacheResolver import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.testing.runTest @@ -28,7 +29,8 @@ class StoreTest { private suspend fun setUp() { cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), - cacheKeyGenerator = IdCacheKeyGenerator() + cacheKeyGenerator = IdCacheKeyGenerator(), + cacheResolver = IdCacheResolver(), ) mockServer = MockServer() apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() 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 27166246a..423bb07cb 100644 --- a/tests/models-operation-based/src/commonTest/kotlin/test/BasicTest.kt +++ b/tests/models-operation-based/src/commonTest/kotlin/test/BasicTest.kt @@ -9,6 +9,7 @@ import com.apollographql.apollo.api.Optional import com.apollographql.apollo.api.Query import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy +import com.apollographql.cache.normalized.api.DefaultCacheResolver import com.apollographql.cache.normalized.api.IdCacheKeyGenerator import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy @@ -32,7 +33,8 @@ class BasicTest { private suspend fun setUp() { cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), - cacheKeyGenerator = IdCacheKeyGenerator() + cacheKeyGenerator = IdCacheKeyGenerator(), + cacheResolver = DefaultCacheResolver, ) mockServer = MockServer() apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() 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 a334a2302..c3a700d01 100644 --- a/tests/models-operation-based/src/commonTest/kotlin/test/StoreTest.kt +++ b/tests/models-operation-based/src/commonTest/kotlin/test/StoreTest.kt @@ -10,6 +10,7 @@ import com.apollographql.apollo.ApolloClient 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.api.IdCacheResolver import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.testing.runTest @@ -28,7 +29,8 @@ class StoreTest { private suspend fun setUp() { cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), - cacheKeyGenerator = IdCacheKeyGenerator() + cacheKeyGenerator = IdCacheKeyGenerator(), + cacheResolver = IdCacheResolver(), ) mockServer = MockServer() apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() 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 c57f0eeb1..f762c9cf5 100644 --- a/tests/models-response-based/src/commonTest/kotlin/test/BasicTest.kt +++ b/tests/models-response-based/src/commonTest/kotlin/test/BasicTest.kt @@ -15,6 +15,7 @@ import com.apollographql.apollo.api.Query 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.IdCacheResolver import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory @@ -38,7 +39,8 @@ class BasicTest { private suspend fun setUp() { cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), - cacheKeyGenerator = IdCacheKeyGenerator() + cacheKeyGenerator = IdCacheKeyGenerator(), + cacheResolver = IdCacheResolver(), ) mockServer = MockServer() apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() @@ -61,7 +63,7 @@ class BasicTest { @Throws(Exception::class) fun heroParentTypeDependentField() = basicTest( HeroParentTypeDependentField, - HeroParentTypeDependentFieldQuery(Optional.Present(Episode.NEWHOPE)) + HeroParentTypeDependentFieldQuery(Optional.Present(Episode.NEWHOPE)), ) { assertFalse(hasErrors()) @@ -78,7 +80,7 @@ class BasicTest { @Test fun polymorphicDroidFieldsGetParsedToDroid() = basicTest( MergedFieldWithSameShape_Droid, - MergedFieldWithSameShapeQuery(Optional.Present(Episode.NEWHOPE)) + MergedFieldWithSameShapeQuery(Optional.Present(Episode.NEWHOPE)), ) { assertFalse(hasErrors()) @@ -89,7 +91,7 @@ class BasicTest { @Test fun polymorphicHumanFieldsGetParsedToHuman() = basicTest( MergedFieldWithSameShape_Human, - MergedFieldWithSameShapeQuery(Optional.Present(Episode.NEWHOPE)) + MergedFieldWithSameShapeQuery(Optional.Present(Episode.NEWHOPE)), ) { assertFalse(hasErrors()) @@ -100,7 +102,7 @@ class BasicTest { @Test fun canUseExhaustiveWhen() = basicTest( HeroHumanOrDroid, - HeroHumanOrDroidQuery(Optional.Present(Episode.NEWHOPE)) + HeroHumanOrDroidQuery(Optional.Present(Episode.NEWHOPE)), ) { val name = when (val hero = data!!.hero!!) { is HeroHumanOrDroidQuery.Data.DroidHero -> hero.name 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 7dacdaa43..999824904 100644 --- a/tests/models-response-based/src/commonTest/kotlin/test/StoreTest.kt +++ b/tests/models-response-based/src/commonTest/kotlin/test/StoreTest.kt @@ -11,6 +11,7 @@ import com.apollographql.apollo.ApolloClient 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.api.IdCacheResolver import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.testing.runTest @@ -29,7 +30,8 @@ class StoreTest { private suspend fun setUp() { cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), - cacheKeyGenerator = IdCacheKeyGenerator() + cacheKeyGenerator = IdCacheKeyGenerator(), + cacheResolver = IdCacheResolver(), ) mockServer = MockServer() apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() 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 a46b13e64..bdbad93be 100644 --- a/tests/normalization-tests/src/commonTest/kotlin/com/example/NormalizationTest.kt +++ b/tests/normalization-tests/src/commonTest/kotlin/com/example/NormalizationTest.kt @@ -11,6 +11,8 @@ import com.apollographql.cache.normalized.api.CacheKeyGenerator import com.apollographql.cache.normalized.api.CacheKeyGeneratorContext import com.apollographql.cache.normalized.api.CacheKeyResolver import com.apollographql.cache.normalized.api.CacheResolver +import com.apollographql.cache.normalized.api.DefaultCacheKeyGenerator +import com.apollographql.cache.normalized.api.DefaultCacheResolver import com.apollographql.cache.normalized.api.FieldPolicyCacheResolver import com.apollographql.cache.normalized.api.ResolverContext import com.apollographql.cache.normalized.api.TypePolicyCacheKeyGenerator @@ -39,13 +41,12 @@ import kotlin.test.Test import kotlin.test.assertEquals internal object IdBasedCacheKeyResolver : CacheResolver, CacheKeyGenerator { - override fun cacheKeyForObject(obj: Map, context: CacheKeyGeneratorContext) = obj["id"]?.toString()?.let(::CacheKey) - ?: @Suppress("DEPRECATION") TypePolicyCacheKeyGenerator.cacheKeyForObject(obj, context) + ?: TypePolicyCacheKeyGenerator(typePolicies = Cache.typePolicies, keyScope = CacheKey.Scope.TYPE).cacheKeyForObject(obj, context) override fun resolveField(context: ResolverContext): Any? { - return FieldPolicyCacheResolver(keyScope = CacheKey.Scope.TYPE).resolveField(context) + return FieldPolicyCacheResolver(fieldPolicies = Cache.fieldPolicies, keyScope = CacheKey.Scope.TYPE).resolveField(context) } } @@ -125,7 +126,7 @@ class NormalizationTest { val mockserver = MockServer() val apolloClient = ApolloClient.Builder() .serverUrl(mockserver.url()) - .normalizedCache(MemoryCacheFactory()) + .normalizedCache(MemoryCacheFactory(), cacheKeyGenerator = DefaultCacheKeyGenerator, cacheResolver = DefaultCacheResolver) .build() mockserver.enqueueString(""" @@ -245,10 +246,10 @@ class NormalizationTest { ) } - return FieldPolicyCacheResolver(keyScope = CacheKey.Scope.TYPE).resolveField(context) + return FieldPolicyCacheResolver(Cache.fieldPolicies, keyScope = CacheKey.Scope.TYPE).resolveField(context) } - } - ) + }, + ), ) .build() diff --git a/tests/normalization-tests/src/concurrentTest/kotlin/com/example/SqlNormalizationTest.kt b/tests/normalization-tests/src/concurrentTest/kotlin/com/example/SqlNormalizationTest.kt index c47dfd49f..a0762c1aa 100644 --- a/tests/normalization-tests/src/concurrentTest/kotlin/com/example/SqlNormalizationTest.kt +++ b/tests/normalization-tests/src/concurrentTest/kotlin/com/example/SqlNormalizationTest.kt @@ -4,6 +4,8 @@ import com.apollographql.apollo.ApolloClient 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.DefaultCacheKeyGenerator +import com.apollographql.cache.normalized.api.DefaultCacheResolver import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.normalizedCache @@ -22,7 +24,7 @@ class SqlNormalizationTest { val mockserver = MockServer() val apolloClient = ApolloClient.Builder() .serverUrl(mockserver.url()) - .normalizedCache(SqlNormalizedCacheFactory()) + .normalizedCache(SqlNormalizedCacheFactory(), cacheKeyGenerator = DefaultCacheKeyGenerator, cacheResolver = DefaultCacheResolver) .build() apolloClient.apolloStore.clearAll() diff --git a/tests/normalized-cache/src/commonTest/kotlin/BasicTest.kt b/tests/normalized-cache/src/commonTest/kotlin/BasicTest.kt index f489fd8b3..1272d8c62 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/BasicTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/BasicTest.kt @@ -6,6 +6,7 @@ import com.apollographql.apollo.api.Query 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.IdCacheResolver import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory @@ -50,7 +51,8 @@ class BasicTest { private suspend fun setUp() { cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), - cacheKeyGenerator = IdCacheKeyGenerator() + cacheKeyGenerator = IdCacheKeyGenerator(), + cacheResolver = IdCacheResolver(), ) mockServer = MockServer() apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() diff --git a/tests/normalized-cache/src/commonTest/kotlin/CacheFlagsTest.kt b/tests/normalized-cache/src/commonTest/kotlin/CacheFlagsTest.kt index f55ab4263..e134d14b1 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/CacheFlagsTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/CacheFlagsTest.kt @@ -13,6 +13,8 @@ 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.api.DefaultCacheKeyGenerator +import com.apollographql.cache.normalized.api.DefaultCacheResolver import com.apollographql.cache.normalized.cacheHeaders import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.doNotStore @@ -32,7 +34,11 @@ class CacheFlagsTest { private lateinit var cacheManager: CacheManager private fun setUp() { - cacheManager = CacheManager(MemoryCacheFactory()) + cacheManager = CacheManager( + normalizedCacheFactory = MemoryCacheFactory(), + cacheKeyGenerator = DefaultCacheKeyGenerator, + cacheResolver = DefaultCacheResolver, + ) apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).cacheManager(cacheManager).build() } @@ -46,7 +52,7 @@ class CacheFlagsTest { // Since the previous request was not stored, this should fail assertIs( - apolloClient.query(query).fetchPolicy(FetchPolicy.CacheOnly).execute().exception + apolloClient.query(query).fetchPolicy(FetchPolicy.CacheOnly).execute().exception, ) } @@ -54,7 +60,7 @@ class CacheFlagsTest { private val partialResponseErrors = listOf( Error.Builder(message = "An error Happened") .locations(listOf(Error.Location(0, 0))) - .build() + .build(), ) @Test @@ -75,30 +81,32 @@ class CacheFlagsTest { val query = HeroNameQuery() val data = HeroNameQuery.Data(HeroNameQuery.Hero(__typename = "Droid", name = "R2-D2")) - cacheManager = CacheManager(MemoryCacheFactory()) + cacheManager = CacheManager(MemoryCacheFactory(), cacheKeyGenerator = DefaultCacheKeyGenerator, cacheResolver = DefaultCacheResolver) val queueTestNetworkTransport = QueueTestNetworkTransport() apolloClient = ApolloClient.Builder() .cacheManager(cacheManager) - .networkTransport(object : NetworkTransport { - val delegate = queueTestNetworkTransport - override fun execute(request: ApolloRequest): Flow> { - return delegate.execute(request).map { response -> - // Parse data, errors or anything else and decide whether to store the response or not - response.newBuilder().cacheHeaders(CacheHeaders.Builder().addHeader(ApolloCacheHeaders.DO_NOT_STORE, "").build()).build() - } - } - - override fun dispose() { - } - - }) + .networkTransport( + object : NetworkTransport { + val delegate = queueTestNetworkTransport + override fun execute(request: ApolloRequest): Flow> { + return delegate.execute(request).map { response -> + // Parse data, errors or anything else and decide whether to store the response or not + response.newBuilder().cacheHeaders(CacheHeaders.Builder().addHeader(ApolloCacheHeaders.DO_NOT_STORE, "").build()).build() + } + } + + override fun dispose() { + } + + }, + ) .build() queueTestNetworkTransport.enqueue(ApolloResponse.Builder(query, uuid4()).data(data).build()) apolloClient.query(query).fetchPolicy(FetchPolicy.NetworkFirst).execute() // Since the previous request was not stored, this should fail assertIs( - apolloClient.query(query).fetchPolicy(FetchPolicy.CacheOnly).execute().exception + apolloClient.query(query).fetchPolicy(FetchPolicy.CacheOnly).execute().exception, ) } } diff --git a/tests/normalized-cache/src/commonTest/kotlin/CacheResolverTest.kt b/tests/normalized-cache/src/commonTest/kotlin/CacheResolverTest.kt index d753d5943..3666d963c 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/CacheResolverTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/CacheResolverTest.kt @@ -3,6 +3,7 @@ package test import com.apollographql.apollo.ApolloClient import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.CacheResolver +import com.apollographql.cache.normalized.api.DefaultCacheKeyGenerator import com.apollographql.cache.normalized.api.DefaultCacheResolver import com.apollographql.cache.normalized.api.ResolverContext import com.apollographql.cache.normalized.cacheManager @@ -27,8 +28,9 @@ class CacheResolverTest { .cacheManager( CacheManager( normalizedCacheFactory = MemoryCacheFactory(), - cacheResolver = resolver - ) + cacheKeyGenerator = DefaultCacheKeyGenerator, + cacheResolver = resolver, + ), ) .build() diff --git a/tests/normalized-cache/src/commonTest/kotlin/CancelTest.kt b/tests/normalized-cache/src/commonTest/kotlin/CancelTest.kt index 9be85a709..173e0e0c6 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/CancelTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/CancelTest.kt @@ -2,6 +2,8 @@ package test import com.apollographql.apollo.ApolloClient import com.apollographql.cache.normalized.FetchPolicy +import com.apollographql.cache.normalized.api.DefaultCacheKeyGenerator +import com.apollographql.cache.normalized.api.DefaultCacheResolver import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.normalizedCache @@ -44,7 +46,11 @@ class CancelTest { @Test fun canCancelQueryCacheAndNetwork() = runTest(before = { setUp() }, after = { tearDown() }) { mockServer.enqueueString(EpisodeHeroNameResponse, 500) - val apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).normalizedCache(MemoryCacheFactory()).build() + val apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).normalizedCache( + normalizedCacheFactory = MemoryCacheFactory(), + cacheKeyGenerator = DefaultCacheKeyGenerator, + cacheResolver = DefaultCacheResolver, + ).build() val job = launch { apolloClient.query(EpisodeHeroNameQuery(Episode.EMPIRE)).fetchPolicy(FetchPolicy.CacheAndNetwork).toFlow().toList() diff --git a/tests/normalized-cache/src/commonTest/kotlin/ExceptionsTest.kt b/tests/normalized-cache/src/commonTest/kotlin/ExceptionsTest.kt index 900108d0c..cc8747375 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/ExceptionsTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/ExceptionsTest.kt @@ -3,6 +3,8 @@ package test import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.exception.ApolloHttpException import com.apollographql.apollo.exception.ApolloNetworkException +import com.apollographql.cache.normalized.api.DefaultCacheKeyGenerator +import com.apollographql.cache.normalized.api.DefaultCacheResolver import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.normalizedCache import com.apollographql.cache.normalized.testing.runTest @@ -136,7 +138,11 @@ class ExceptionsTest { fun v3ExceptionHandlingKeepsPartialDataWithCache() = runTest(before = { setUp() }, after = { tearDown() }) { mockServer.enqueueString(PARTIAL_DATA_RESPONSE.trimIndent()) val errorClient = apolloClient.newBuilder() - .normalizedCache(MemoryCacheFactory(1024 * 1024)) + .normalizedCache( + normalizedCacheFactory = MemoryCacheFactory(1024 * 1024), + cacheKeyGenerator = DefaultCacheKeyGenerator, + cacheResolver = DefaultCacheResolver, + ) .build() val response = errorClient.query(HeroAndFriendsNamesQuery(Episode.EMPIRE)).executeV3() assertNotNull(response.data) diff --git a/tests/normalized-cache/src/commonTest/kotlin/FetchPolicyTest.kt b/tests/normalized-cache/src/commonTest/kotlin/FetchPolicyTest.kt index 6058286f8..70d0b1fe3 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/FetchPolicyTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/FetchPolicyTest.kt @@ -22,6 +22,8 @@ import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.DefaultFetchPolicyInterceptor import com.apollographql.cache.normalized.FetchPolicy import com.apollographql.cache.normalized.api.CacheKey +import com.apollographql.cache.normalized.api.DefaultCacheKeyGenerator +import com.apollographql.cache.normalized.api.DefaultCacheResolver import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.isFromCache @@ -60,7 +62,7 @@ class FetchPolicyTest { private lateinit var cacheManager: CacheManager private suspend fun setUp() { - cacheManager = CacheManager(MemoryCacheFactory()) + cacheManager = CacheManager(MemoryCacheFactory(), cacheKeyGenerator = DefaultCacheKeyGenerator, cacheResolver = DefaultCacheResolver) mockServer = MockServer() apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager = cacheManager).build() } @@ -545,11 +547,11 @@ class FetchPolicyTest { CharacterNameByIdQuery.Data( CharacterNameByIdQuery.Character( __typename = "Human", - name = "Luke" - ) - ) + name = "Luke", + ), + ), ) - } + }, ) apolloClient.query(operation2) @@ -569,11 +571,11 @@ class FetchPolicyTest { HeroNameQuery.Data( HeroNameQuery.Hero( __typename = "Human", - name = "Leila" - ) - ) + name = "Leila", + ), + ), ) - } + }, ) /** @@ -599,11 +601,11 @@ class FetchPolicyTest { HeroNameQuery.Data( HeroNameQuery.Hero( __typename = "Wookie", - name = "Chewbacca" - ) - ) + name = "Chewbacca", + ), + ), ) - } + }, ) cacheManager.publish(setOf(CacheKey.QUERY_ROOT.fieldKey("hero"))) diff --git a/tests/normalized-cache/src/commonTest/kotlin/IdCacheKeyGeneratorTest.kt b/tests/normalized-cache/src/commonTest/kotlin/IdCacheKeyGeneratorTest.kt index 69e535979..9f49fe84f 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/IdCacheKeyGeneratorTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/IdCacheKeyGeneratorTest.kt @@ -6,7 +6,7 @@ import com.apollographql.apollo.testing.enqueueTestResponse 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.api.IdCacheResolver import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory @@ -24,7 +24,7 @@ class IdCacheKeyGeneratorTest { val cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(), - cacheResolver = IdCacheKeyResolver(), + cacheResolver = IdCacheResolver(), ) val apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).cacheManager(cacheManager).build() val query = GetUser2Query("42") @@ -40,7 +40,7 @@ class IdCacheKeyGeneratorTest { val cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator("userId"), - cacheResolver = IdCacheKeyResolver(idFields = listOf("userId")), + cacheResolver = IdCacheResolver(listOf("userId")), ) val apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).cacheManager(cacheManager).build() val query = GetUserByIdQuery("42") @@ -56,7 +56,7 @@ class IdCacheKeyGeneratorTest { val cacheManager = CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator("id"), - cacheResolver = IdCacheKeyResolver(idListFields = listOf("ids", "userIds")), + cacheResolver = IdCacheResolver(listOf("ids", "userIds")), ) val apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).cacheManager(cacheManager).build() val query1 = GetUsersQuery(listOf("42", "43")) diff --git a/tests/normalized-cache/src/commonTest/kotlin/JsonScalarTest.kt b/tests/normalized-cache/src/commonTest/kotlin/JsonScalarTest.kt index 834e145d6..13eb698d3 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/JsonScalarTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/JsonScalarTest.kt @@ -4,6 +4,8 @@ import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.api.AnyAdapter import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy +import com.apollographql.cache.normalized.api.DefaultCacheKeyGenerator +import com.apollographql.cache.normalized.api.DefaultCacheResolver import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory @@ -24,7 +26,7 @@ class JsonScalarTest { private lateinit var cacheManager: CacheManager private suspend fun setUp() { - cacheManager = CacheManager(MemoryCacheFactory()) + cacheManager = CacheManager(MemoryCacheFactory(), cacheKeyGenerator = DefaultCacheKeyGenerator, cacheResolver = DefaultCacheResolver) mockServer = MockServer() apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()) .cacheManager(cacheManager) diff --git a/tests/normalized-cache/src/commonTest/kotlin/NormalizationTest.kt b/tests/normalized-cache/src/commonTest/kotlin/NormalizationTest.kt index 7b4938e8a..874636c8e 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/NormalizationTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/NormalizationTest.kt @@ -4,6 +4,8 @@ import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.testing.QueueTestNetworkTransport import com.apollographql.apollo.testing.enqueueTestResponse import com.apollographql.cache.normalized.FetchPolicy +import com.apollographql.cache.normalized.api.DefaultCacheKeyGenerator +import com.apollographql.cache.normalized.api.DefaultCacheResolver import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.normalizedCache @@ -17,7 +19,7 @@ class NormalizationTest { fun variableDefaultValuesTest() = runTest { val apolloClient = ApolloClient.Builder() .networkTransport(QueueTestNetworkTransport()) - .normalizedCache(MemoryCacheFactory()) + .normalizedCache(MemoryCacheFactory(), cacheKeyGenerator = DefaultCacheKeyGenerator, cacheResolver = DefaultCacheResolver) .build() val query = RepositoryListQuery() apolloClient.enqueueTestResponse( diff --git a/tests/normalized-cache/src/commonTest/kotlin/NormalizedCacheThreadingTest.kt b/tests/normalized-cache/src/commonTest/kotlin/NormalizedCacheThreadingTest.kt index 9803098c2..7d50d615b 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/NormalizedCacheThreadingTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/NormalizedCacheThreadingTest.kt @@ -3,6 +3,8 @@ package test import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.testing.QueueTestNetworkTransport import com.apollographql.apollo.testing.enqueueTestResponse +import com.apollographql.cache.normalized.api.DefaultCacheKeyGenerator +import com.apollographql.cache.normalized.api.DefaultCacheResolver import com.apollographql.cache.normalized.api.NormalizedCache import com.apollographql.cache.normalized.api.NormalizedCacheFactory import com.apollographql.cache.normalized.memory.MemoryCacheFactory @@ -23,12 +25,15 @@ class NormalizedCacheThreadingTest { var cacheCreateThreadName: String? = null val apolloClient = ApolloClient.Builder() .networkTransport(QueueTestNetworkTransport()) - .normalizedCache(object : NormalizedCacheFactory() { - override fun create(): NormalizedCache { - cacheCreateThreadName = currentThreadId() - return MemoryCacheFactory().create() - } - }).build() + .normalizedCache( + object : NormalizedCacheFactory() { + override fun create(): NormalizedCache { + cacheCreateThreadName = currentThreadId() + return MemoryCacheFactory().create() + } + }, + cacheKeyGenerator = DefaultCacheKeyGenerator, cacheResolver = DefaultCacheResolver, + ).build() assertNull(cacheCreateThreadName) val query = CharacterNameByIdQuery("") diff --git a/tests/normalized-cache/src/commonTest/kotlin/OptimisticCacheTest.kt b/tests/normalized-cache/src/commonTest/kotlin/OptimisticCacheTest.kt index 50579b361..b8e5417f9 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/OptimisticCacheTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/OptimisticCacheTest.kt @@ -6,6 +6,7 @@ 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.IdCacheResolver import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory @@ -42,7 +43,8 @@ class OptimisticCacheTest { private lateinit var cacheManager: CacheManager private suspend fun setUp() { - cacheManager = CacheManager(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(), enableOptimisticUpdates = true) + cacheManager = + CacheManager(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheResolver(), enableOptimisticUpdates = true) mockServer = MockServer() apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() } diff --git a/tests/normalized-cache/src/commonTest/kotlin/OtherCacheTest.kt b/tests/normalized-cache/src/commonTest/kotlin/OtherCacheTest.kt index b37d077fc..f45a6940e 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/OtherCacheTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/OtherCacheTest.kt @@ -7,7 +7,7 @@ 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.api.IdCacheResolver import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory @@ -41,7 +41,7 @@ class OtherCacheTest { private suspend fun setUp() { cacheManager = - CacheManager(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(keyScope = CacheKey.Scope.SERVICE), cacheResolver = IdCacheKeyResolver(keyScope = CacheKey.Scope.SERVICE)) + CacheManager(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(keyScope = CacheKey.Scope.SERVICE), cacheResolver = IdCacheResolver(keyScope = CacheKey.Scope.SERVICE)) mockServer = MockServer() apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() } diff --git a/tests/normalized-cache/src/commonTest/kotlin/StoreTest.kt b/tests/normalized-cache/src/commonTest/kotlin/StoreTest.kt index 7f023aeee..4bef61418 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/StoreTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/StoreTest.kt @@ -9,8 +9,10 @@ import com.apollographql.apollo.testing.enqueueTestResponse 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.DefaultCacheKeyGenerator +import com.apollographql.cache.normalized.api.DefaultCacheResolver import com.apollographql.cache.normalized.api.IdCacheKeyGenerator -import com.apollographql.cache.normalized.api.IdCacheKeyResolver +import com.apollographql.cache.normalized.api.IdCacheResolver import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy @@ -44,7 +46,7 @@ class StoreTest { private fun setUp() { cacheManager = - CacheManager(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(keyScope = CacheKey.Scope.SERVICE), cacheResolver = IdCacheKeyResolver(keyScope = CacheKey.Scope.SERVICE)) + CacheManager(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(keyScope = CacheKey.Scope.SERVICE), cacheResolver = IdCacheResolver(keyScope = CacheKey.Scope.SERVICE)) apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).cacheManager(cacheManager).build() } @@ -208,7 +210,8 @@ class StoreTest { storeAllFriends() assertFriendIsCached("1000", "Luke Skywalker") - val newCacheManager = CacheManager(MemoryCacheFactory()) + val newCacheManager = + CacheManager(MemoryCacheFactory(), cacheKeyGenerator = DefaultCacheKeyGenerator, cacheResolver = DefaultCacheResolver) val newClient = apolloClient.newBuilder().cacheManager(newCacheManager).build() assertFriendIsNotCached("1000", newClient) @@ -286,7 +289,7 @@ class StoreTest { apolloClient = ApolloClient.Builder() .networkTransport(QueueTestNetworkTransport()) .customScalarAdapters(customScalarAdapters) - .normalizedCache(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheKeyResolver()) + .normalizedCache(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheResolver()) .build() val query = ColorQuery() diff --git a/tests/normalized-cache/src/commonTest/kotlin/ThreadTests.kt b/tests/normalized-cache/src/commonTest/kotlin/ThreadTests.kt index 60af090a5..312cf828a 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/ThreadTests.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/ThreadTests.kt @@ -6,6 +6,8 @@ import com.apollographql.apollo.testing.enqueueTestResponse 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.DefaultCacheKeyGenerator +import com.apollographql.cache.normalized.api.DefaultCacheResolver import com.apollographql.cache.normalized.api.NormalizedCache import com.apollographql.cache.normalized.api.NormalizedCacheFactory import com.apollographql.cache.normalized.api.Record @@ -95,7 +97,7 @@ class ThreadTests { } val apolloClient = ApolloClient.Builder() - .normalizedCache(MyMemoryCacheFactory(currentThreadId())) + .normalizedCache(MyMemoryCacheFactory(currentThreadId()), cacheKeyGenerator = DefaultCacheKeyGenerator, cacheResolver = DefaultCacheResolver) .networkTransport(QueueTestNetworkTransport()) .build() diff --git a/tests/normalized-cache/src/commonTest/kotlin/WatcherErrorHandlingTest.kt b/tests/normalized-cache/src/commonTest/kotlin/WatcherErrorHandlingTest.kt index ef1b2878a..cdc213831 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/WatcherErrorHandlingTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/WatcherErrorHandlingTest.kt @@ -8,6 +8,7 @@ import com.apollographql.apollo.exception.CacheMissException 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.IdCacheResolver import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory @@ -36,7 +37,7 @@ class WatcherErrorHandlingTest { private lateinit var cacheManager: CacheManager private suspend fun setUp() { - cacheManager = CacheManager(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator()) + cacheManager = CacheManager(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheResolver()) mockServer = MockServer() apolloClient = ApolloClient.Builder().serverUrl(mockServer.url()).cacheManager(cacheManager).build() } diff --git a/tests/normalized-cache/src/commonTest/kotlin/WatcherTest.kt b/tests/normalized-cache/src/commonTest/kotlin/WatcherTest.kt index ec0ee4e85..7e36284b8 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/WatcherTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/WatcherTest.kt @@ -11,7 +11,10 @@ import com.apollographql.apollo.testing.enqueueTestNetworkError import com.apollographql.apollo.testing.enqueueTestResponse import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.FetchPolicy +import com.apollographql.cache.normalized.api.DefaultCacheKeyGenerator +import com.apollographql.cache.normalized.api.DefaultCacheResolver import com.apollographql.cache.normalized.api.IdCacheKeyGenerator +import com.apollographql.cache.normalized.api.IdCacheResolver import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory @@ -50,7 +53,7 @@ class WatcherTest { private lateinit var cacheManager: CacheManager private fun setUp() { - cacheManager = CacheManager(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator()) + cacheManager = CacheManager(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheResolver()) apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).cacheManager(cacheManager).build() } @@ -582,7 +585,7 @@ class WatcherTest { // This doesn't use TestNetworkTransport because we need timing control val mockServer = MockServer() val apolloClient = ApolloClient.Builder() - .normalizedCache(MemoryCacheFactory()) + .normalizedCache(MemoryCacheFactory(), cacheKeyGenerator = DefaultCacheKeyGenerator, cacheResolver = DefaultCacheResolver) .serverUrl(mockServer.url()) .build() diff --git a/tests/normalized-cache/src/commonTest/kotlin/circular/CircularCacheReadTest.kt b/tests/normalized-cache/src/commonTest/kotlin/circular/CircularCacheReadTest.kt index cb3b3a2a8..65c6479b8 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/circular/CircularCacheReadTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/circular/CircularCacheReadTest.kt @@ -2,6 +2,8 @@ package test.circular import circular.GetUserQuery import com.apollographql.cache.normalized.CacheManager +import com.apollographql.cache.normalized.api.DefaultCacheKeyGenerator +import com.apollographql.cache.normalized.api.DefaultCacheResolver import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.testing.runTest import kotlin.test.Test @@ -10,7 +12,8 @@ import kotlin.test.assertEquals class CircularCacheReadTest { @Test fun circularReferenceDoesNotStackOverflow() = runTest { - val cacheManager = CacheManager(MemoryCacheFactory()) + val cacheManager = + CacheManager(MemoryCacheFactory(), cacheKeyGenerator = DefaultCacheKeyGenerator, cacheResolver = DefaultCacheResolver) val operation = GetUserQuery() diff --git a/tests/normalized-cache/src/commonTest/kotlin/declarativecache/DeclarativeCacheTest.kt b/tests/normalized-cache/src/commonTest/kotlin/declarativecache/DeclarativeCacheTest.kt index ba900d8fb..90d330fdb 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/declarativecache/DeclarativeCacheTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/declarativecache/DeclarativeCacheTest.kt @@ -31,7 +31,8 @@ class DeclarativeCacheTest { @Test fun typePolicyIsWorking() = runTest { - val cacheManager = CacheManager(MemoryCacheFactory()) + val cacheManager = + CacheManager(MemoryCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies)) // Write a book at the "promo" path val promoOperation = GetPromoBookQuery() @@ -52,7 +53,7 @@ class DeclarativeCacheTest { @Test fun typePolicyWithAbstractTypes() = runTest { val cacheManager = - CacheManager(MemoryCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies)) + CacheManager(MemoryCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies)) val type2Data = GetType2Query.Data(GetType2Query.Type2(__typename = "Type2", type2Field = "type1Field", interface2KeyField = "42")) cacheManager.writeOperation(GetType2Query(), type2Data) @@ -94,7 +95,8 @@ class DeclarativeCacheTest { @Test fun fallbackIdIsWorking() = runTest { - val cacheManager = CacheManager(MemoryCacheFactory()) + val cacheManager = + CacheManager(MemoryCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies)) // Write a library at the "promo" path val promoOperation = GetPromoLibraryQuery() @@ -114,7 +116,8 @@ class DeclarativeCacheTest { @Test fun fieldPolicyIsWorking() = runTest { - val cacheManager = CacheManager(MemoryCacheFactory()) + val cacheManager = + CacheManager(MemoryCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies)) val bookQuery1 = GetPromoBookQuery() val bookData1 = GetPromoBookQuery.Data(GetPromoBookQuery.PromoBook(title = "Promo", isbn = "42", __typename = "Book")) @@ -145,7 +148,8 @@ class DeclarativeCacheTest { @Test fun fieldPolicyWithLists() = runTest { - val cacheManager = CacheManager(MemoryCacheFactory()) + val cacheManager = + CacheManager(MemoryCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies)) cacheManager.writeOperation(GetPromoBookQuery(), GetPromoBookQuery.Data(GetPromoBookQuery.PromoBook(title = "Promo", isbn = "42", __typename = "Book"))) cacheManager.writeOperation(GetOtherBookQuery(), GetOtherBookQuery.Data(GetOtherBookQuery.OtherBook(isbn = "43", title = "Other Book", __typename = "Book"))) @@ -170,10 +174,11 @@ class DeclarativeCacheTest { } } - return FieldPolicyCacheResolver(keyScope = CacheKey.Scope.TYPE).resolveField(context) + return FieldPolicyCacheResolver(Cache.fieldPolicies, keyScope = CacheKey.Scope.TYPE).resolveField(context) } } - val cacheManager = CacheManager(MemoryCacheFactory(), cacheResolver = cacheResolver) + val cacheManager = + CacheManager(MemoryCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = cacheResolver) val promoOperation = GetPromoBookQuery() cacheManager.writeOperation(promoOperation, GetPromoBookQuery.Data(GetPromoBookQuery.PromoBook(title = "Title1", isbn = "1", __typename = "Book"))) diff --git a/tests/normalized-cache/src/commonTest/kotlin/fragmentnormalizer/FragmentNormalizerTest.kt b/tests/normalized-cache/src/commonTest/kotlin/fragmentnormalizer/FragmentNormalizerTest.kt index 8f8e6ba4e..4ad891f65 100644 --- a/tests/normalized-cache/src/commonTest/kotlin/fragmentnormalizer/FragmentNormalizerTest.kt +++ b/tests/normalized-cache/src/commonTest/kotlin/fragmentnormalizer/FragmentNormalizerTest.kt @@ -2,6 +2,8 @@ package test.fragmentnormalizer import com.apollographql.apollo.ApolloClient import com.apollographql.cache.normalized.api.CacheKey +import com.apollographql.cache.normalized.api.DefaultCacheKeyGenerator +import com.apollographql.cache.normalized.api.DefaultCacheResolver import com.apollographql.cache.normalized.api.IdCacheKeyGenerator import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.internal.normalized @@ -22,7 +24,7 @@ class FragmentNormalizerTest { val apolloClient = ApolloClient.Builder() .serverUrl("https:/example.com") - .normalizedCache(cacheFactory) + .normalizedCache(cacheFactory, cacheKeyGenerator = DefaultCacheKeyGenerator, cacheResolver = DefaultCacheResolver) .build() var fragment1 = ConversationFragment( diff --git a/tests/normalized-cache/src/concurrentTest/kotlin/MemoryCacheOnlyTest.kt b/tests/normalized-cache/src/concurrentTest/kotlin/MemoryCacheOnlyTest.kt index d3fc45518..9fd9c9ae1 100644 --- a/tests/normalized-cache/src/concurrentTest/kotlin/MemoryCacheOnlyTest.kt +++ b/tests/normalized-cache/src/concurrentTest/kotlin/MemoryCacheOnlyTest.kt @@ -5,6 +5,8 @@ import com.apollographql.apollo.testing.enqueueTestResponse 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.IdCacheResolver import com.apollographql.cache.normalized.api.Record import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchPolicy @@ -23,7 +25,8 @@ import kotlin.test.assertIs class MemoryCacheOnlyTest { @Test fun memoryCacheOnlyDoesNotStoreInSqlCache() = runTest { - val cacheManager = CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory())).also { it.clearAll() } + val cacheManager = + CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheResolver()).also { it.clearAll() } val apolloClient = ApolloClient.Builder().networkTransport(QueueTestNetworkTransport()).cacheManager(cacheManager).build() val query = GetUserQuery() apolloClient.enqueueTestResponse(query, GetUserQuery.Data(GetUserQuery.User(__typename = "User", "John", "a@a.com"))) @@ -35,11 +38,13 @@ class MemoryCacheOnlyTest { @Test fun memoryCacheOnlyDoesNotReadFromSqlCache() = runTest { - val cacheManager = CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory())).also { it.clearAll() } + val cacheManager = + CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheResolver()).also { it.clearAll() } val query = GetUserQuery() cacheManager.writeOperation(query, GetUserQuery.Data(GetUserQuery.User(__typename = "User", "John", "a@a.com"))) - val store2 = CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory())) + val store2 = + CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheResolver()) 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( diff --git a/tests/normalized-cache/src/jvmTest/kotlin/CacheConcurrencyTest.kt b/tests/normalized-cache/src/jvmTest/kotlin/CacheConcurrencyTest.kt index 11dfd311b..979544ab0 100644 --- a/tests/normalized-cache/src/jvmTest/kotlin/CacheConcurrencyTest.kt +++ b/tests/normalized-cache/src/jvmTest/kotlin/CacheConcurrencyTest.kt @@ -4,6 +4,8 @@ import com.apollographql.apollo.ApolloClient import com.apollographql.apollo.testing.QueueTestNetworkTransport import com.apollographql.apollo.testing.enqueueTestResponse import com.apollographql.cache.normalized.CacheManager +import com.apollographql.cache.normalized.api.IdCacheKeyGenerator +import com.apollographql.cache.normalized.api.IdCacheResolver import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.testing.runTest @@ -18,7 +20,8 @@ class CacheConcurrencyTest { @Test fun storeConcurrently() = runTest { - val cacheManager = CacheManager(MemoryCacheFactory(maxSizeBytes = 1000)) + val cacheManager = + CacheManager(MemoryCacheFactory(maxSizeBytes = 1000), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheResolver()) val executor = Executors.newFixedThreadPool(10) val dispatcher = executor.asCoroutineDispatcher() diff --git a/tests/normalized-cache/src/jvmTest/kotlin/CacheMissLoggingInterceptorTest.kt b/tests/normalized-cache/src/jvmTest/kotlin/CacheMissLoggingInterceptorTest.kt index 62f1c9cf9..ba22a3d82 100644 --- a/tests/normalized-cache/src/jvmTest/kotlin/CacheMissLoggingInterceptorTest.kt +++ b/tests/normalized-cache/src/jvmTest/kotlin/CacheMissLoggingInterceptorTest.kt @@ -3,6 +3,8 @@ package test import com.apollographql.apollo.ApolloClient 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.IdCacheResolver import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.logCacheMisses import com.apollographql.cache.normalized.memory.MemoryCacheFactory @@ -34,7 +36,7 @@ class CacheMissLoggingInterceptorTest { recordedLogs.add(it) } } - .normalizedCache(MemoryCacheFactory()) + .normalizedCache(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheResolver()) .build() mockServer.enqueueString(""" diff --git a/tests/normalized-cache/src/jvmTest/kotlin/WriteToCacheAsynchronouslyTest.kt b/tests/normalized-cache/src/jvmTest/kotlin/WriteToCacheAsynchronouslyTest.kt index 9a5f35203..1300c0bad 100644 --- a/tests/normalized-cache/src/jvmTest/kotlin/WriteToCacheAsynchronouslyTest.kt +++ b/tests/normalized-cache/src/jvmTest/kotlin/WriteToCacheAsynchronouslyTest.kt @@ -4,6 +4,8 @@ import com.apollographql.apollo.ApolloClient 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.IdCacheKeyGenerator +import com.apollographql.cache.normalized.api.IdCacheResolver import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.testing.runTest @@ -31,7 +33,7 @@ class WriteToCacheAsynchronouslyTest { private var dispatcher = Executors.newSingleThreadExecutor().asCoroutineDispatcher() private suspend fun setUp() { - cacheManager = CacheManager(MemoryCacheFactory()) + cacheManager = CacheManager(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheResolver()) mockServer = MockServer() apolloClient = ApolloClient.Builder() .serverUrl(mockServer.url()) diff --git a/tests/number-scalar/src/commonTest/kotlin/test/NumberTest.kt b/tests/number-scalar/src/commonTest/kotlin/test/NumberTest.kt index 28a410c66..13e0a3de6 100644 --- a/tests/number-scalar/src/commonTest/kotlin/test/NumberTest.kt +++ b/tests/number-scalar/src/commonTest/kotlin/test/NumberTest.kt @@ -9,6 +9,8 @@ import com.apollographql.apollo.api.json.JsonWriter import com.apollographql.apollo.testing.QueueTestNetworkTransport import com.apollographql.apollo.testing.enqueueTestResponse import com.apollographql.cache.normalized.FetchPolicy +import com.apollographql.cache.normalized.api.DefaultCacheKeyGenerator +import com.apollographql.cache.normalized.api.DefaultCacheResolver import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.normalizedCache @@ -23,7 +25,7 @@ class NumberTest { fun test() = runTest { ApolloClient.Builder() .networkTransport(QueueTestNetworkTransport()) - .normalizedCache(MemoryCacheFactory()) + .normalizedCache(MemoryCacheFactory(), cacheKeyGenerator = DefaultCacheKeyGenerator, cacheResolver = DefaultCacheResolver) .addCustomScalarAdapter(com.example.type.Number.type, NumberAdapter()) .build() .use { apolloClient -> diff --git a/tests/optimistic-data/src/jvmTest/kotlin/test/OptimisticDataTest.kt b/tests/optimistic-data/src/jvmTest/kotlin/test/OptimisticDataTest.kt index 45eb9c07b..b3eba0360 100644 --- a/tests/optimistic-data/src/jvmTest/kotlin/test/OptimisticDataTest.kt +++ b/tests/optimistic-data/src/jvmTest/kotlin/test/OptimisticDataTest.kt @@ -2,6 +2,8 @@ package test import app.cash.turbine.test import com.apollographql.apollo.ApolloClient +import com.apollographql.cache.normalized.api.IdCacheKeyGenerator +import com.apollographql.cache.normalized.api.IdCacheResolver import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.normalizedCache import com.apollographql.cache.normalized.optimisticUpdates @@ -49,7 +51,7 @@ class OptimisticDataTest { val server = MockServer() val apolloClient = ApolloClient.Builder() .serverUrl(server.url()) - .normalizedCache(MemoryCacheFactory(), enableOptimisticUpdates = true) + .normalizedCache(MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(), cacheResolver = IdCacheResolver(), enableOptimisticUpdates = true) .build() server.enqueueString(""" diff --git a/tests/pagination/src/commonTest/kotlin/ConnectionPaginationTest.kt b/tests/pagination/src/commonTest/kotlin/ConnectionPaginationTest.kt index 856242282..90acc2056 100644 --- a/tests/pagination/src/commonTest/kotlin/ConnectionPaginationTest.kt +++ b/tests/pagination/src/commonTest/kotlin/ConnectionPaginationTest.kt @@ -7,7 +7,9 @@ import com.apollographql.cache.normalized.api.ConnectionFieldKeyGenerator import com.apollographql.cache.normalized.api.ConnectionMetadataGenerator import com.apollographql.cache.normalized.api.ConnectionRecordMerger import com.apollographql.cache.normalized.api.DefaultEmbeddedFieldsProvider +import com.apollographql.cache.normalized.api.FieldPolicyCacheResolver import com.apollographql.cache.normalized.api.NormalizedCacheFactory +import com.apollographql.cache.normalized.api.TypePolicyCacheKeyGenerator import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.testing.SqlNormalizedCacheFactory import com.apollographql.cache.normalized.testing.runTest @@ -39,6 +41,8 @@ class ConnectionPaginationTest { private fun test(cacheFactory: NormalizedCacheFactory) = runTest { val cacheManager = CacheManager( normalizedCacheFactory = cacheFactory, + cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), + cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies), metadataGenerator = ConnectionMetadataGenerator(Cache.connectionTypes), recordMerger = ConnectionRecordMerger, fieldKeyGenerator = ConnectionFieldKeyGenerator(Cache.connectionTypes), @@ -364,6 +368,8 @@ class ConnectionPaginationTest { private fun errorTest(cacheFactory: NormalizedCacheFactory) = runTest { val cacheManager = CacheManager( normalizedCacheFactory = cacheFactory, + cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), + cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies), metadataGenerator = ConnectionMetadataGenerator(Cache.connectionTypes), recordMerger = ConnectionRecordMerger, fieldKeyGenerator = ConnectionFieldKeyGenerator(Cache.connectionTypes), diff --git a/tests/pagination/src/commonTest/kotlin/ConnectionProgrammaticConnectionsPaginationTest.kt b/tests/pagination/src/commonTest/kotlin/ConnectionProgrammaticConnectionsPaginationTest.kt index e86ac61fd..0df84624e 100644 --- a/tests/pagination/src/commonTest/kotlin/ConnectionProgrammaticConnectionsPaginationTest.kt +++ b/tests/pagination/src/commonTest/kotlin/ConnectionProgrammaticConnectionsPaginationTest.kt @@ -6,11 +6,14 @@ import com.apollographql.cache.normalized.api.ConnectionEmbeddedFieldsProvider import com.apollographql.cache.normalized.api.ConnectionFieldKeyGenerator import com.apollographql.cache.normalized.api.ConnectionMetadataGenerator import com.apollographql.cache.normalized.api.ConnectionRecordMerger +import com.apollographql.cache.normalized.api.FieldPolicyCacheResolver import com.apollographql.cache.normalized.api.NormalizedCacheFactory +import com.apollographql.cache.normalized.api.TypePolicyCacheKeyGenerator import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.testing.SqlNormalizedCacheFactory import com.apollographql.cache.normalized.testing.runTest import pagination.connectionProgrammaticConnections.UsersQuery +import pagination.connectionProgrammaticConnections.cache.Cache import pagination.connectionProgrammaticConnections.type.UserConnection import pagination.connectionProgrammaticConnections.type.buildPageInfo import pagination.connectionProgrammaticConnections.type.buildUser @@ -39,6 +42,8 @@ class ConnectionProgrammaticConnectionsPaginationTest { val connectionTypes = setOf(UserConnection.type.name) val cacheManager = CacheManager( normalizedCacheFactory = cacheFactory, + cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), + cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies), metadataGenerator = ConnectionMetadataGenerator(connectionTypes), recordMerger = ConnectionRecordMerger, fieldKeyGenerator = ConnectionFieldKeyGenerator(connectionTypes), diff --git a/tests/pagination/src/commonTest/kotlin/ConnectionProgrammaticTypePoliciesPaginationTest.kt b/tests/pagination/src/commonTest/kotlin/ConnectionProgrammaticTypePoliciesPaginationTest.kt index a2712bc32..d32255ae4 100644 --- a/tests/pagination/src/commonTest/kotlin/ConnectionProgrammaticTypePoliciesPaginationTest.kt +++ b/tests/pagination/src/commonTest/kotlin/ConnectionProgrammaticTypePoliciesPaginationTest.kt @@ -7,7 +7,7 @@ import com.apollographql.cache.normalized.api.ConnectionFieldKeyGenerator import com.apollographql.cache.normalized.api.ConnectionMetadataGenerator import com.apollographql.cache.normalized.api.ConnectionRecordMerger import com.apollographql.cache.normalized.api.IdCacheKeyGenerator -import com.apollographql.cache.normalized.api.IdCacheKeyResolver +import com.apollographql.cache.normalized.api.IdCacheResolver import com.apollographql.cache.normalized.api.NormalizedCacheFactory import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.testing.SqlNormalizedCacheFactory @@ -42,7 +42,7 @@ class ConnectionProgrammaticTypePoliciesPaginationTest { normalizedCacheFactory = cacheFactory, cacheKeyGenerator = IdCacheKeyGenerator(), metadataGenerator = ConnectionMetadataGenerator(Cache.connectionTypes), - cacheResolver = IdCacheKeyResolver(), + cacheResolver = IdCacheResolver(), recordMerger = ConnectionRecordMerger, fieldKeyGenerator = ConnectionFieldKeyGenerator(Cache.connectionTypes), embeddedFieldsProvider = ConnectionEmbeddedFieldsProvider(Cache.connectionTypes), diff --git a/tests/pagination/src/commonTest/kotlin/ConnectionWithNodesPaginationTest.kt b/tests/pagination/src/commonTest/kotlin/ConnectionWithNodesPaginationTest.kt index 4f6225c42..d17f9504e 100644 --- a/tests/pagination/src/commonTest/kotlin/ConnectionWithNodesPaginationTest.kt +++ b/tests/pagination/src/commonTest/kotlin/ConnectionWithNodesPaginationTest.kt @@ -6,7 +6,9 @@ import com.apollographql.cache.normalized.api.ConnectionFieldKeyGenerator import com.apollographql.cache.normalized.api.ConnectionMetadataGenerator import com.apollographql.cache.normalized.api.ConnectionRecordMerger import com.apollographql.cache.normalized.api.DefaultEmbeddedFieldsProvider +import com.apollographql.cache.normalized.api.FieldPolicyCacheResolver import com.apollographql.cache.normalized.api.NormalizedCacheFactory +import com.apollographql.cache.normalized.api.TypePolicyCacheKeyGenerator import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.testing.SqlNormalizedCacheFactory import com.apollographql.cache.normalized.testing.runTest @@ -37,6 +39,8 @@ class ConnectionWithNodesPaginationTest { private fun test(cacheFactory: NormalizedCacheFactory) = runTest { val cacheManager = CacheManager( normalizedCacheFactory = cacheFactory, + cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), + cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies), metadataGenerator = ConnectionMetadataGenerator(Cache.connectionTypes), recordMerger = ConnectionRecordMerger, fieldKeyGenerator = ConnectionFieldKeyGenerator(Cache.connectionTypes), diff --git a/tests/pagination/src/commonTest/kotlin/ConnectionWithUnionPaginationTest.kt b/tests/pagination/src/commonTest/kotlin/ConnectionWithUnionPaginationTest.kt index 6c3cf7e82..aa5e0075e 100644 --- a/tests/pagination/src/commonTest/kotlin/ConnectionWithUnionPaginationTest.kt +++ b/tests/pagination/src/commonTest/kotlin/ConnectionWithUnionPaginationTest.kt @@ -7,7 +7,9 @@ import com.apollographql.cache.normalized.api.ConnectionFieldKeyGenerator import com.apollographql.cache.normalized.api.ConnectionMetadataGenerator import com.apollographql.cache.normalized.api.ConnectionRecordMerger import com.apollographql.cache.normalized.api.DefaultEmbeddedFieldsProvider +import com.apollographql.cache.normalized.api.FieldPolicyCacheResolver import com.apollographql.cache.normalized.api.NormalizedCacheFactory +import com.apollographql.cache.normalized.api.TypePolicyCacheKeyGenerator import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.testing.SqlNormalizedCacheFactory import com.apollographql.cache.normalized.testing.runTest @@ -40,6 +42,8 @@ class ConnectionWithUnionPaginationTest { private fun test(cacheFactory: NormalizedCacheFactory) = runTest { val cacheManager = CacheManager( normalizedCacheFactory = cacheFactory, + cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), + cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies), metadataGenerator = ConnectionMetadataGenerator(Cache.connectionTypes), recordMerger = ConnectionRecordMerger, fieldKeyGenerator = ConnectionFieldKeyGenerator(Cache.connectionTypes), @@ -387,6 +391,8 @@ class ConnectionWithUnionPaginationTest { private fun errorTest(cacheFactory: NormalizedCacheFactory) = runTest { val cacheManager = CacheManager( normalizedCacheFactory = cacheFactory, + cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), + cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies), metadataGenerator = ConnectionMetadataGenerator(Cache.connectionTypes), recordMerger = ConnectionRecordMerger, fieldKeyGenerator = ConnectionFieldKeyGenerator(Cache.connectionTypes), diff --git a/tests/pagination/src/commonTest/kotlin/CursorBasedPaginationTest.kt b/tests/pagination/src/commonTest/kotlin/CursorBasedPaginationTest.kt index 9c1983758..3f5b90e7c 100644 --- a/tests/pagination/src/commonTest/kotlin/CursorBasedPaginationTest.kt +++ b/tests/pagination/src/commonTest/kotlin/CursorBasedPaginationTest.kt @@ -11,7 +11,9 @@ import com.apollographql.cache.normalized.api.ConnectionRecordMerger import com.apollographql.cache.normalized.api.DefaultEmbeddedFieldsProvider import com.apollographql.cache.normalized.api.FieldKeyContext import com.apollographql.cache.normalized.api.FieldKeyGenerator +import com.apollographql.cache.normalized.api.FieldPolicyCacheResolver import com.apollographql.cache.normalized.api.NormalizedCacheFactory +import com.apollographql.cache.normalized.api.TypePolicyCacheKeyGenerator import com.apollographql.cache.normalized.fetchPolicy import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.normalizedCache @@ -47,9 +49,11 @@ class CursorBasedPaginationTest { private fun test(cacheFactory: NormalizedCacheFactory) = runTest { val cacheManager = CacheManager( normalizedCacheFactory = cacheFactory, + cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), + cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies), metadataGenerator = ConnectionMetadataGenerator(setOf("UserConnection")), recordMerger = ConnectionRecordMerger, - fieldKeyGenerator = object : FieldKeyGenerator{ + fieldKeyGenerator = object : FieldKeyGenerator { override fun getFieldKey(context: FieldKeyContext): String { return if (context.field.type.rawType().name == "UserConnection") { context.field.newBuilder() @@ -65,7 +69,7 @@ class CursorBasedPaginationTest { } } }, - embeddedFieldsProvider = DefaultEmbeddedFieldsProvider(Cache.embeddedFields) + embeddedFieldsProvider = DefaultEmbeddedFieldsProvider(Cache.embeddedFields), ) cacheManager.clearAll() @@ -375,9 +379,11 @@ class CursorBasedPaginationTest { .networkTransport(QueueTestNetworkTransport()) .normalizedCache( normalizedCacheFactory = MemoryCacheFactory(), + cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), + cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies), metadataGenerator = ConnectionMetadataGenerator(setOf("UserConnection")), recordMerger = ConnectionRecordMerger, - fieldKeyGenerator = object : FieldKeyGenerator{ + fieldKeyGenerator = object : FieldKeyGenerator { override fun getFieldKey(context: FieldKeyContext): String { return if (context.field.type.rawType().name == "UserConnection") { context.field.newBuilder() @@ -393,7 +399,7 @@ class CursorBasedPaginationTest { } } }, - embeddedFieldsProvider = DefaultEmbeddedFieldsProvider(Cache.embeddedFields) + embeddedFieldsProvider = DefaultEmbeddedFieldsProvider(Cache.embeddedFields), ) .build() diff --git a/tests/pagination/src/commonTest/kotlin/EmbedTest.kt b/tests/pagination/src/commonTest/kotlin/EmbedTest.kt index 463c09129..e658e3ae0 100644 --- a/tests/pagination/src/commonTest/kotlin/EmbedTest.kt +++ b/tests/pagination/src/commonTest/kotlin/EmbedTest.kt @@ -5,6 +5,8 @@ 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.api.DefaultEmbeddedFieldsProvider +import com.apollographql.cache.normalized.api.FieldPolicyCacheResolver +import com.apollographql.cache.normalized.api.TypePolicyCacheKeyGenerator import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.internal.normalized import com.apollographql.cache.normalized.memory.MemoryCacheFactory @@ -42,7 +44,9 @@ class EmbedTest { val client = ApolloClient.Builder() .normalizedCache( normalizedCacheFactory = MemoryCacheFactory(), - embeddedFieldsProvider = DefaultEmbeddedFieldsProvider(Cache.embeddedFields) + cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), + cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies), + embeddedFieldsProvider = DefaultEmbeddedFieldsProvider(Cache.embeddedFields), ) .serverUrl("unused") .build() diff --git a/tests/pagination/src/commonTest/kotlin/OffsetBasedWithArrayPaginationTest.kt b/tests/pagination/src/commonTest/kotlin/OffsetBasedWithArrayPaginationTest.kt index aa83bc5ea..364a57dc9 100644 --- a/tests/pagination/src/commonTest/kotlin/OffsetBasedWithArrayPaginationTest.kt +++ b/tests/pagination/src/commonTest/kotlin/OffsetBasedWithArrayPaginationTest.kt @@ -5,14 +5,17 @@ import com.apollographql.apollo.api.json.ApolloJsonElement import com.apollographql.cache.normalized.CacheManager import com.apollographql.cache.normalized.api.FieldKeyContext import com.apollographql.cache.normalized.api.FieldKeyGenerator +import com.apollographql.cache.normalized.api.FieldPolicyCacheResolver import com.apollographql.cache.normalized.api.FieldRecordMerger import com.apollographql.cache.normalized.api.MetadataGenerator import com.apollographql.cache.normalized.api.MetadataGeneratorContext import com.apollographql.cache.normalized.api.NormalizedCacheFactory +import com.apollographql.cache.normalized.api.TypePolicyCacheKeyGenerator import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.testing.SqlNormalizedCacheFactory import com.apollographql.cache.normalized.testing.runTest import pagination.offsetBasedWithArray.UsersQuery +import pagination.offsetBasedWithArray.cache.Cache import pagination.offsetBasedWithArray.type.buildUser import kotlin.math.max import kotlin.math.min @@ -38,6 +41,8 @@ class OffsetBasedWithArrayPaginationTest { private fun test(cacheFactory: NormalizedCacheFactory) = runTest { val cacheManager = CacheManager( normalizedCacheFactory = cacheFactory, + cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), + cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies), metadataGenerator = OffsetPaginationMetadataGenerator("users"), recordMerger = FieldRecordMerger(OffsetPaginationFieldMerger()), fieldKeyGenerator = object : FieldKeyGenerator{ diff --git a/tests/pagination/src/commonTest/kotlin/OffsetBasedWithPageAndInputPaginationTest.kt b/tests/pagination/src/commonTest/kotlin/OffsetBasedWithPageAndInputPaginationTest.kt index c7bd734c5..2eaa8035a 100644 --- a/tests/pagination/src/commonTest/kotlin/OffsetBasedWithPageAndInputPaginationTest.kt +++ b/tests/pagination/src/commonTest/kotlin/OffsetBasedWithPageAndInputPaginationTest.kt @@ -16,11 +16,12 @@ import com.apollographql.cache.normalized.api.FieldRecordMerger import com.apollographql.cache.normalized.api.MetadataGenerator import com.apollographql.cache.normalized.api.MetadataGeneratorContext import com.apollographql.cache.normalized.api.NormalizedCacheFactory +import com.apollographql.cache.normalized.api.TypePolicyCacheKeyGenerator import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.testing.SqlNormalizedCacheFactory import com.apollographql.cache.normalized.testing.runTest -import pagination.offsetBasedWithPageAndInput.cache.Cache import pagination.offsetBasedWithPageAndInput.UsersQuery +import pagination.offsetBasedWithPageAndInput.cache.Cache import pagination.offsetBasedWithPageAndInput.type.buildUser import pagination.offsetBasedWithPageAndInput.type.buildUserPage import kotlin.math.max @@ -47,13 +48,14 @@ class OffsetBasedWithPageAndInputPaginationTest { private fun test(cacheFactory: NormalizedCacheFactory) = runTest { val cacheManager = CacheManager( normalizedCacheFactory = cacheFactory, + cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies, keyScope = CacheKey.Scope.TYPE), metadataGenerator = OffsetPaginationMetadataGenerator("UserPage"), - cacheResolver = FieldPolicyCacheResolver(keyScope = CacheKey.Scope.TYPE), + cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies, keyScope = CacheKey.Scope.TYPE), recordMerger = FieldRecordMerger(OffsetPaginationFieldMerger()), fieldKeyGenerator = UsersFieldKeyGenerator, - embeddedFieldsProvider = DefaultEmbeddedFieldsProvider(Cache.embeddedFields) + embeddedFieldsProvider = DefaultEmbeddedFieldsProvider(Cache.embeddedFields), - ) + ) cacheManager.clearAll() // First page diff --git a/tests/pagination/src/commonTest/kotlin/OffsetBasedWithPagePaginationTest.kt b/tests/pagination/src/commonTest/kotlin/OffsetBasedWithPagePaginationTest.kt index e8a4da2ec..572a6cc42 100644 --- a/tests/pagination/src/commonTest/kotlin/OffsetBasedWithPagePaginationTest.kt +++ b/tests/pagination/src/commonTest/kotlin/OffsetBasedWithPagePaginationTest.kt @@ -7,11 +7,13 @@ import com.apollographql.cache.normalized.api.CacheKey import com.apollographql.cache.normalized.api.DefaultEmbeddedFieldsProvider import com.apollographql.cache.normalized.api.FieldKeyContext import com.apollographql.cache.normalized.api.FieldKeyGenerator +import com.apollographql.cache.normalized.api.FieldPolicyCacheResolver import com.apollographql.cache.normalized.api.FieldRecordMerger import com.apollographql.cache.normalized.api.MetadataGenerator import com.apollographql.cache.normalized.api.MetadataGeneratorContext import com.apollographql.cache.normalized.api.NormalizedCacheFactory import com.apollographql.cache.normalized.api.Record +import com.apollographql.cache.normalized.api.TypePolicyCacheKeyGenerator import com.apollographql.cache.normalized.memory.MemoryCacheFactory import com.apollographql.cache.normalized.testing.SqlNormalizedCacheFactory import com.apollographql.cache.normalized.testing.runTest @@ -43,9 +45,11 @@ class OffsetBasedWithPagePaginationTest { private fun test(cacheFactory: NormalizedCacheFactory) = runTest { val cacheManager = CacheManager( normalizedCacheFactory = cacheFactory, + cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), + cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies), metadataGenerator = OffsetPaginationMetadataGenerator("UserPage"), recordMerger = FieldRecordMerger(OffsetPaginationFieldMerger()), - fieldKeyGenerator = object : FieldKeyGenerator{ + fieldKeyGenerator = object : FieldKeyGenerator { override fun getFieldKey(context: FieldKeyContext): String { return if (context.field.type.rawType().name == "UserPage") { // Exclude offset and limit arguments from the field key @@ -62,7 +66,7 @@ class OffsetBasedWithPagePaginationTest { } } }, - embeddedFieldsProvider = DefaultEmbeddedFieldsProvider(Cache.embeddedFields) + embeddedFieldsProvider = DefaultEmbeddedFieldsProvider(Cache.embeddedFields), ) cacheManager.clearAll() diff --git a/tests/partial-results/src/commonTest/kotlin/test/CachePartialResultTest.kt b/tests/partial-results/src/commonTest/kotlin/test/CachePartialResultTest.kt index 797594d76..eada71b0c 100644 --- a/tests/partial-results/src/commonTest/kotlin/test/CachePartialResultTest.kt +++ b/tests/partial-results/src/commonTest/kotlin/test/CachePartialResultTest.kt @@ -14,10 +14,12 @@ import com.apollographql.cache.normalized.api.CacheControlCacheResolver 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.FieldPolicyCacheResolver import com.apollographql.cache.normalized.api.IdCacheKeyGenerator -import com.apollographql.cache.normalized.api.IdCacheKeyResolver +import com.apollographql.cache.normalized.api.IdCacheResolver import com.apollographql.cache.normalized.api.Record import com.apollographql.cache.normalized.api.SchemaCoordinatesMaxAgeProvider +import com.apollographql.cache.normalized.api.TypePolicyCacheKeyGenerator import com.apollographql.cache.normalized.apolloStore import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.fetchFromCache @@ -72,7 +74,7 @@ class CachePartialResultTest { ) ApolloClient.Builder() .serverUrl(mockServer.url()) - .normalizedCache(MemoryCacheFactory()) + .normalizedCache(MemoryCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies)) .build() .use { apolloClient -> val networkResult = apolloClient.query(MeWithoutNickNameWithEmailQuery()) @@ -175,8 +177,8 @@ class CachePartialResultTest { CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(), - cacheResolver = IdCacheKeyResolver() - ) + cacheResolver = IdCacheResolver(), + ), ) .build() .use { apolloClient -> @@ -266,7 +268,7 @@ class CachePartialResultTest { ) ApolloClient.Builder() .serverUrl(mockServer.url()) - .normalizedCache(MemoryCacheFactory()) + .normalizedCache(MemoryCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies)) .build() .use { apolloClient -> // Prime the cache @@ -449,8 +451,8 @@ class CachePartialResultTest { CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(), - cacheResolver = IdCacheKeyResolver() - ) + cacheResolver = IdCacheResolver(), + ), ) .build() .use { apolloClient -> @@ -513,8 +515,8 @@ class CachePartialResultTest { CacheManager( normalizedCacheFactory = MemoryCacheFactory(), cacheKeyGenerator = IdCacheKeyGenerator(), - cacheResolver = IdCacheKeyResolver() - ) + cacheResolver = IdCacheResolver(), + ), ) .build() .use { apolloClient -> @@ -602,7 +604,7 @@ class CachePartialResultTest { ) ApolloClient.Builder() .serverUrl(mockServer.url()) - .normalizedCache(MemoryCacheFactory()) + .normalizedCache(MemoryCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies)) .build() .use { apolloClient -> val networkResult = apolloClient.query(WithFragmentsQuery()) @@ -720,7 +722,7 @@ class CachePartialResultTest { ) ApolloClient.Builder() .serverUrl(mockServer.url()) - .normalizedCache(MemoryCacheFactory(), cacheResolver = CacheControlCacheResolver(SchemaCoordinatesMaxAgeProvider(Cache.maxAges, Duration.INFINITE))) + .normalizedCache(MemoryCacheFactory(), cacheResolver = CacheControlCacheResolver(SchemaCoordinatesMaxAgeProvider(Cache.maxAges, Duration.INFINITE), FieldPolicyCacheResolver(Cache.fieldPolicies)), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies)) .storeReceivedDate(true) .build() .use { apolloClient -> @@ -791,7 +793,7 @@ class CachePartialResultTest { ) ApolloClient.Builder() .serverUrl(mockServer.url()) - .normalizedCache(MemoryCacheFactory(), cacheResolver = CacheControlCacheResolver(SchemaCoordinatesMaxAgeProvider(Cache.maxAges, Duration.INFINITE))) + .normalizedCache(MemoryCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = CacheControlCacheResolver(SchemaCoordinatesMaxAgeProvider(Cache.maxAges, Duration.INFINITE), FieldPolicyCacheResolver(Cache.fieldPolicies))) .storeReceivedDate(true) .build() .use { apolloClient -> @@ -860,7 +862,7 @@ class CachePartialResultTest { ) ApolloClient.Builder() .serverUrl(mockServer.url()) - .normalizedCache(MemoryCacheFactory(), cacheResolver = CacheControlCacheResolver(SchemaCoordinatesMaxAgeProvider(Cache.maxAges, Duration.INFINITE))) + .normalizedCache(MemoryCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = CacheControlCacheResolver(SchemaCoordinatesMaxAgeProvider(Cache.maxAges, Duration.INFINITE), FieldPolicyCacheResolver(Cache.fieldPolicies))) .storeReceivedDate(true) .build() .use { apolloClient -> diff --git a/tests/schema-changes/src/commonTest/kotlin/test/SchemaChanges.kt b/tests/schema-changes/src/commonTest/kotlin/test/SchemaChanges.kt index 4f540b21f..dfc04e0ff 100644 --- a/tests/schema-changes/src/commonTest/kotlin/test/SchemaChanges.kt +++ b/tests/schema-changes/src/commonTest/kotlin/test/SchemaChanges.kt @@ -2,6 +2,7 @@ package test import com.apollographql.apollo.api.CustomScalarAdapters import com.apollographql.apollo.api.json.jsonReader +import com.apollographql.cache.normalized.api.DefaultCacheKeyGenerator import com.apollographql.cache.normalized.internal.normalized import com.apollographql.cache.normalized.testing.runTest import okio.Buffer @@ -36,9 +37,9 @@ class SchemaChangesTest { val data = operation.adapter().fromJson( Buffer().writeUtf8(v2Data).jsonReader(), - CustomScalarAdapters.Empty + CustomScalarAdapters.Empty, ) - data.normalized(operation) + data.normalized(operation, DefaultCacheKeyGenerator) } } diff --git a/tests/store-errors/src/commonTest/kotlin/test/StoreErrorsTest.kt b/tests/store-errors/src/commonTest/kotlin/test/StoreErrorsTest.kt index d8276e434..8f8a3a47d 100644 --- a/tests/store-errors/src/commonTest/kotlin/test/StoreErrorsTest.kt +++ b/tests/store-errors/src/commonTest/kotlin/test/StoreErrorsTest.kt @@ -10,7 +10,9 @@ import com.apollographql.apollo.interceptor.ApolloInterceptorChain 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.FieldPolicyCacheResolver import com.apollographql.cache.normalized.api.Record +import com.apollographql.cache.normalized.api.TypePolicyCacheKeyGenerator import com.apollographql.cache.normalized.api.withErrors import com.apollographql.cache.normalized.cacheManager import com.apollographql.cache.normalized.errorsReplaceCachedValues @@ -25,6 +27,7 @@ import com.apollographql.mockserver.MockServer import com.apollographql.mockserver.enqueueString import kotlinx.coroutines.flow.Flow import okio.use +import test.cache.Cache import test.fragment.UserFields import kotlin.test.Test import kotlin.test.assertEquals @@ -43,11 +46,14 @@ class StoreErrorsTest { mockServer.close() } - private val memoryCacheManager = CacheManager(MemoryCacheFactory()) + private val memoryCacheManager = + CacheManager(MemoryCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies)) - private val sqlCacheManager = CacheManager(SqlNormalizedCacheFactory()) + private val sqlCacheManager = + CacheManager(SqlNormalizedCacheFactory(), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies)) - private val memoryThenSqlCacheManager = CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory())) + private val memoryThenSqlCacheManager = + CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory()), cacheKeyGenerator = TypePolicyCacheKeyGenerator(Cache.typePolicies), cacheResolver = FieldPolicyCacheResolver(Cache.fieldPolicies)) @Test fun simpleMemory() = runTest(before = { setUp() }, after = { tearDown() }) {