You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/advanced/multi-modules.mdx
+25-3Lines changed: 25 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,7 +60,30 @@ apollo {
60
60
61
61
By default, Apollo Kotlin generates all the types in your schema module. This is because there is no way to know in advance what types are going to be used by feature modules.
62
62
63
-
For large schemas, this can generate a lot of code and increase your build time significantly. In this case, you can opt in auto-detection of used types. This works by splitting the codegen task in different steps so that feature modules can let the schema module know what types are used before actually generating the models. To opt in, call `dependsOn()` with the `bidirectional` argument set to true:
63
+
For large schemas, this can generate a lot of code and increase your build time significantly. In this case, you can opt in auto-detection of used types.
64
+
65
+
This works by splitting the codegen task in different steps so that feature modules can let the schema module know what types are used before actually generating the models. To opt in, call `isADependencyOf()` to establish the bidirectional dependency between your feature module and your schema module:
Once you opt in auto-detection of used types, it's important that **all** modules are doubly linked like above. If not the feature modules will fail to compile due to some missing schema classes.
83
+
84
+
## bidirectional parameter (Experimental)
85
+
86
+
Using `isADependencyOf()` requires listing all your feature modules in your schema module which duplicates code. To keep things minimal and configure the dependency automatically, use `bidirectional = true`:
64
87
65
88
```kotlin
66
89
// feature/build.gradle.kts
@@ -76,8 +99,7 @@ apollo {
76
99
77
100
<ExperimentalFeature>
78
101
79
-
The `bidirectional` parameter is experimental because it may break <ahref="https://docs.gradle.org/current/userguide/build_environment.html">Gradle project isolation</a>. For a project-isolation compatible method, try <ahref="https://www.apollographql.com/docs/kotlin/kdoc/apollo-gradle-plugin-external/com.apollographql.apollo.gradle.api/-service/is-a-dependency-of.html">isADependencyOf</a>
102
+
The `bidirectional` parameter is experimental and not compatible with <ahref="https://docs.gradle.org/current/userguide/build_environment.html">Gradle project isolation</a>.
80
103
81
104
</ExperimentalFeature>
82
105
83
-
Once you opt in auto-detection of used types, it's important that **all** modules are doubly linked like above. If not the feature modules will fail to compile due to some missing schema classes.
Copy file name to clipboardExpand all lines: docs/source/advanced/operation-variables.mdx
+18-29Lines changed: 18 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,7 @@ title: Using GraphQL variables in Apollo Kotlin
4
4
5
5
GraphQL supports passing argument values to your operations with [variables](https://graphql.org/graphql-js/passing-arguments/). This enables you to write a single query that you can reuse with multiple variable values (this is a [recommended best practice](/react/data/operation-best-practices/#use-variables-to-provide-graphql-arguments)).
6
6
7
-
In GraphQL, non-nullable variables are required, and nullable variables are optional. However, because variables are rarely omitted in practice, Apollo Kotlin provides a mechanism to make variables non-optional in generated code. This makes the structure of generated code more straightforward.
8
-
9
-
Because you might still need to omit variables, the default is to generate them as optional, but you can configure this (for specific variables or globally).
7
+
In GraphQL, non-nullable variables are required, and nullable variables are always optional. Apollo Kotlin uses its own [`Optional`](https://apollographql.github.io/apollo-kotlin/kdoc/apollo-api/com.apollographql.apollo.api/-optional/index.html) type to distinguish between present (but maybe nullable) and absent types.
10
8
11
9
Consider the following GraphQL query with two nullable variables:
12
10
@@ -39,45 +37,36 @@ val query = GetTodosQuery(Optional.Present(null), Optional.Present(null))
39
37
val query =GetTodosQuery(Optional.Present(100), Optional.Present(0))
40
38
```
41
39
42
-
## Making nullable variables non-optional
40
+
## Using input builders
41
+
42
+
For both operations and input objects, having to wrap values in an [`Optional`](https://apollographql.github.io/apollo-kotlin/kdoc/apollo-api/com.apollographql.apollo.api/-optional/index.html) wrapper can be cumbersome.
43
43
44
-
To disable optional variables globally, update your Gradle config like so:
44
+
For those cases, use `generateInputBuilders`:
45
45
46
46
```kotlin
47
47
apollo {
48
48
service("service") {
49
49
// ...
50
-
generateOptionalOperationVariables.set(false)
50
+
generateInputBuilders.set(true)
51
51
}
52
52
}
53
53
```
54
54
55
-
If you do, in the case of the `GetTodos` query shown above, Apollo Kotlin now generates the following code:
56
-
57
-
```kotlin
58
-
classGetTodosQuery(valfirst:Int?, valoffset:Int?)
59
-
```
60
-
61
-
This makes the calling code less verbose to use:
55
+
If you do, in the case of the `GetTodos` query shown above, Apollo Kotlin now generates a `Builder` for each operation:
62
56
63
57
```kotlin
58
+
// Omit values for both variables
59
+
val query =GetTodosQuery.Builder()
60
+
.build()
64
61
// Provide null for both variables
65
-
val query =GetTodosQuery(null, null)
62
+
val query =GetTodosQuery.Builder()
63
+
.first(null)
64
+
.offset(null)
65
+
.build()
66
66
// Send explicit values for both variables
67
-
val query =GetTodosQuery(100, 0)
68
-
```
69
-
70
-
If you pass `null` as the value for either of these variables, Apollo Kotlin sends `null` to the server _as the value of that variable_ instead of omitting it entirely.
71
-
72
-
Although doing this can simplify your code in most cases, you might still need to omit variables for certain operations. To achieve this, you can allow optional variables on a case-by-case basis with the `@optional` directive:
0 commit comments