Skip to content

Commit a48c872

Browse files
committed
Merge branch 'refs/heads/main' into alpha
# Conflicts: # docs/docs/inheritance.md # test/unit/should_handle_reserved_kotlin_keywords/expected.kt # test/unit/should_handle_top_level_types_properly/expected.kt
2 parents 92387c8 + 499886d commit a48c872

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

docs/docs/inheritance.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ open class MyType {
3737
Source code:
3838

3939
```kotlin
40-
import com.expediagroup.graphql.generator.annotations.GraphQLIgnore
4140
import com.expediagroup.graphql.server.operations.Query
4241
import com.types.generated.MyType as MyTypeInterface
4342
import com.types.generated.Query as QueryInterface
@@ -46,7 +45,6 @@ class MyQuery : Query, QueryInterface() {
4645
override fun resolveMyType(): MyTypeInterface = MyType()
4746
}
4847

49-
@GraphQLIgnore
5048
class MyType : MyTypeInterface() {
5149
override fun resolveMe(input: String): String = "Hello world!"
5250
}
@@ -55,11 +53,14 @@ class MyType : MyTypeInterface() {
5553
As you can see, the generated code is not part of the implementation. Rather, it becomes an interface to inherit from in your implementation.
5654
This enforces a type contract between the schema and your resolver code.
5755

58-
## Top Level Types
56+
Note that GraphQL Kotlin will use the implementation classes to generate the schema, not the generated interfaces.
57+
This means that all `@GraphQLDescription` and `@Deprecated` annotations have to be added to implementation classes
58+
in order to be propagated to the resulting schema.
5959

60-
When dealing with top-level types, such as `Query` or `Mutation`, you can inherit from the generated class directly. This is because the generated class is open by default.
60+
## Top Level Types
6161

62-
Given the following executable schema:
62+
When dealing with top-level types, i.e. `Query` and `Mutation`, you can inherit from the corresponding generated class
63+
to enforce the type contract. This is fine as long as all of your resolvers are contained in the same Query or Mutation class.
6364

6465
```graphql
6566
type Query {
@@ -68,7 +69,17 @@ type Query {
6869
}
6970
```
7071

71-
You might want to separate the implementation into multiple classes like so:
72+
```kotlin
73+
import com.expediagroup.graphql.server.operations.Query
74+
import com.types.generated.Query as QueryInterface
75+
76+
class MyQuery : Query, QueryInterface() {
77+
override fun foo(): String = "Hello"
78+
override fun bar(): String = "World"
79+
}
80+
```
81+
82+
However, you might want to separate the implementation into multiple classes like so:
7283

7384
```kotlin
7485
import com.expediagroup.graphql.server.operations.Query
@@ -82,7 +93,7 @@ class BarQuery : Query {
8293
}
8394
```
8495

85-
However, if you try to inherit from the generated `Query` class, you will get an error during schema generation.
96+
If you try to inherit from the generated `Query` class, you will get an error during schema generation.
8697

8798
```kotlin
8899
import com.expediagroup.graphql.server.operations.Query
@@ -97,7 +108,7 @@ class BarQuery : Query, QueryInterface() {
97108
}
98109
```
99110

100-
This is because the generated `Query` class contains both `foo` and `bar` fields, which causes a conflict when inherited by multiple implementation classes.
111+
This is because the generated `Query` class contains both `foo` and `bar` fields, which creates a conflict when inherited by multiple implementation classes.
101112

102113
Instead, you should inherit from the field-level generated `Query` classes like so:
103114

@@ -114,3 +125,5 @@ class BarQuery : Query, BarQueryInterface() {
114125
override fun bar(): String = "World"
115126
}
116127
```
128+
129+
This way, schema generation can complete without conflict, and you can separate your implementation into multiple classes!

0 commit comments

Comments
 (0)