From 294af7354471456a3283adf696ce71ad67f7d1e3 Mon Sep 17 00:00:00 2001 From: Martin Bonnin Date: Fri, 30 May 2025 14:55:14 +0200 Subject: [PATCH 1/3] Add more documentation to `@typePolicy` --- .../apollo/ast/internal/definitions.kt | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/libraries/apollo-ast/src/commonMain/kotlin/com/apollographql/apollo/ast/internal/definitions.kt b/libraries/apollo-ast/src/commonMain/kotlin/com/apollographql/apollo/ast/internal/definitions.kt index 0a39c97378a..c7d4cccfb68 100644 --- a/libraries/apollo-ast/src/commonMain/kotlin/com/apollographql/apollo/ast/internal/definitions.kt +++ b/libraries/apollo-ast/src/commonMain/kotlin/com/apollographql/apollo/ast/internal/definitions.kt @@ -35,7 +35,41 @@ internal val kotlinLabsDefinitions_0_3 = """ ""${'"'} directive @typePolicy( ""${'"'} - a selection set containing fields used to compute the cache key of an object. Order is important. + A selection set containing fields used to compute the cache key of an object. + Nested selection sets are currently not supported. Order is important. + + Key fields can be defined on interfaces. In that case, the key fields apply to all sub-types. Sub-types are not allowed to define their own key fields. + + The key fields are automatically added to the operations by the compiler. + Aliased key fields are not recognized and the compiler adds a non-aliased version of the field if that happens. + If a type is queried through an interface/union, this may add fragments. + + For an example, this query: + + ```graphql + query { + product { + price + } + } + ``` + + is turned into this one after compilation: + + ```graphql + query { + product { + ... on Book { + isbn + } + ... on Movie { + id + } + price + } + } + ``` + ""${'"'} keyFields: String! = "", ""${'"'} From 130b8ca617167bab5f79118d52061beb5aebcf0b Mon Sep 17 00:00:00 2001 From: Martin Bonnin Date: Fri, 30 May 2025 16:19:48 +0200 Subject: [PATCH 2/3] Add a case for objects inheriting multiple keyfields --- .../com/apollographql/apollo/ast/internal/definitions.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/apollo-ast/src/commonMain/kotlin/com/apollographql/apollo/ast/internal/definitions.kt b/libraries/apollo-ast/src/commonMain/kotlin/com/apollographql/apollo/ast/internal/definitions.kt index c7d4cccfb68..0348a68f620 100644 --- a/libraries/apollo-ast/src/commonMain/kotlin/com/apollographql/apollo/ast/internal/definitions.kt +++ b/libraries/apollo-ast/src/commonMain/kotlin/com/apollographql/apollo/ast/internal/definitions.kt @@ -1,7 +1,5 @@ package com.apollographql.apollo.ast.internal -import com.apollographql.apollo.annotations.ApolloInternal - /** * This file contains several groups of GraphQL definitions we use during codegen: * @@ -39,6 +37,7 @@ internal val kotlinLabsDefinitions_0_3 = """ Nested selection sets are currently not supported. Order is important. Key fields can be defined on interfaces. In that case, the key fields apply to all sub-types. Sub-types are not allowed to define their own key fields. + If a type implements multiple interfaces with keyfields, the keyfields must match across all interfaces with keyfields. The key fields are automatically added to the operations by the compiler. Aliased key fields are not recognized and the compiler adds a non-aliased version of the field if that happens. From 63f9a891d9c2c92fd7974c037ba26973ec5af3b2 Mon Sep 17 00:00:00 2001 From: Martin Bonnin Date: Fri, 30 May 2025 16:20:50 +0200 Subject: [PATCH 3/3] oops --- .../kotlin/com/apollographql/apollo/ast/internal/definitions.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/apollo-ast/src/commonMain/kotlin/com/apollographql/apollo/ast/internal/definitions.kt b/libraries/apollo-ast/src/commonMain/kotlin/com/apollographql/apollo/ast/internal/definitions.kt index 0348a68f620..0f85c6fc47e 100644 --- a/libraries/apollo-ast/src/commonMain/kotlin/com/apollographql/apollo/ast/internal/definitions.kt +++ b/libraries/apollo-ast/src/commonMain/kotlin/com/apollographql/apollo/ast/internal/definitions.kt @@ -36,7 +36,7 @@ internal val kotlinLabsDefinitions_0_3 = """ A selection set containing fields used to compute the cache key of an object. Nested selection sets are currently not supported. Order is important. - Key fields can be defined on interfaces. In that case, the key fields apply to all sub-types. Sub-types are not allowed to define their own key fields. + Key fields can be defined on interfaces. In that case, the key fields apply to all sub-types and sub-types are not allowed to define their own key fields. If a type implements multiple interfaces with keyfields, the keyfields must match across all interfaces with keyfields. The key fields are automatically added to the operations by the compiler.