Skip to content

Commit 10063d2

Browse files
authored
Add more documentation to @typePolicy (#6542)
* Add more documentation to `@typePolicy` * Add a case for objects inheriting multiple keyfields * oops
1 parent 4b54077 commit 10063d2

File tree

1 file changed

+36
-3
lines changed
  • libraries/apollo-ast/src/commonMain/kotlin/com/apollographql/apollo/ast/internal

1 file changed

+36
-3
lines changed

libraries/apollo-ast/src/commonMain/kotlin/com/apollographql/apollo/ast/internal/definitions.kt

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.apollographql.apollo.ast.internal
22

3-
import com.apollographql.apollo.annotations.ApolloInternal
4-
53
/**
64
* This file contains several groups of GraphQL definitions we use during codegen:
75
*
@@ -35,7 +33,42 @@ internal val kotlinLabsDefinitions_0_3 = """
3533
""${'"'}
3634
directive @typePolicy(
3735
""${'"'}
38-
a selection set containing fields used to compute the cache key of an object. Order is important.
36+
A selection set containing fields used to compute the cache key of an object.
37+
Nested selection sets are currently not supported. Order is important.
38+
39+
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.
40+
If a type implements multiple interfaces with keyfields, the keyfields must match across all interfaces with keyfields.
41+
42+
The key fields are automatically added to the operations by the compiler.
43+
Aliased key fields are not recognized and the compiler adds a non-aliased version of the field if that happens.
44+
If a type is queried through an interface/union, this may add fragments.
45+
46+
For an example, this query:
47+
48+
```graphql
49+
query {
50+
product {
51+
price
52+
}
53+
}
54+
```
55+
56+
is turned into this one after compilation:
57+
58+
```graphql
59+
query {
60+
product {
61+
... on Book {
62+
isbn
63+
}
64+
... on Movie {
65+
id
66+
}
67+
price
68+
}
69+
}
70+
```
71+
3972
""${'"'}
4073
keyFields: String! = "",
4174
""${'"'}

0 commit comments

Comments
 (0)