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
Apollo Kotlin's default configuration works for the majority of use cases. If you're getting started, see the [getting started guide](../) for an overview of the default Gradle configuration.
5
+
Apollo Kotlin's default configuration works for the majority of use cases. If you're getting started, see
6
+
the [getting started guide](../) for an overview of the default Gradle configuration.
6
7
7
8
This article describes configuration options for advanced use cases when using Gradle.
8
9
9
10
## Using multiple GraphQL APIs
10
11
11
-
Apollo Kotlin supports communicating with multiple GraphQL endpoints with different schemas. To do so, create multiple services like so:
12
+
Apollo Kotlin supports communicating with multiple GraphQL endpoints with different schemas. To do so, create multiple
13
+
services like so:
12
14
13
15
```kotlin
14
16
apollo {
@@ -39,9 +41,11 @@ apollo {
39
41
40
42
## Combining multiple schema files
41
43
42
-
Apollo Kotlin supports a collection of client directives, including `@nonnull`, `@optional`, and `@typePolicy`. These directives enable you to extend your server's base schema with client-specific types and fields.
44
+
Apollo Kotlin supports a collection of client directives, including `@nonnull`, `@optional`, and `@typePolicy`. These
45
+
directives enable you to extend your server's base schema with client-specific types and fields.
43
46
44
-
If you expand your schema in a separate file, you can instruct Apollo Kotlin to construct its schema from a combination of multiple files, like so:
47
+
If you expand your schema in a separate file, you can instruct Apollo Kotlin to construct its schema from a combination
48
+
of multiple files, like so:
45
49
46
50
```kotlin
47
51
apollo {
@@ -61,7 +65,8 @@ By default, Apollo Kotlin adds generated source:
61
65
- to `commonMain` for multiplatform projects
62
66
- to all non-test variants for Android projects
63
67
64
-
You can customize this behavior with the `outputDirConnection` property. For example, to wire a service to the test source set of a Kotlin
68
+
You can customize this behavior with the `outputDirConnection` property. For example, to wire a service to the test
69
+
source set of a Kotlin
65
70
JVM project:
66
71
67
72
```kotlin
@@ -76,7 +81,8 @@ apollo {
76
81
77
82
## Android variants support
78
83
79
-
It is sometimes useful to have different operations or schemas depending on the [variant](https://developer.android.com/studio/build/build-variants) of your Android project.
84
+
It is sometimes useful to have different operations or schemas depending on
85
+
the [variant](https://developer.android.com/studio/build/build-variants) of your Android project.
80
86
81
87
To do this, you can instruct the Gradle plugin to automatically configure a Service per variant, like so:
82
88
@@ -89,10 +95,13 @@ apollo {
89
95
}
90
96
```
91
97
92
-
-`sourceFolder` where to find the GraphQL relative to "src/$sourceSetName/graphql". Pass "." to look into "src/$sourceSetName/graphql".
98
+
-`sourceFolder` where to find the GraphQL relative to "src/$sourceSetName/graphql". Pass "." to look into "
99
+
src/$sourceSetName/graphql".
93
100
-`nameSuffix` a suffix to use for the service name. Leave blank to use the variant name as is.
94
101
95
-
Similarly to what the Android variant system does with source code, the GraphQL files are handled additively, and files in `src/main/graphql` are included in all services. This means your project could look like this (e.g. when certain operations must only exist in debug builds):
102
+
Similarly to what the Android variant system does with source code, the GraphQL files are handled additively, and files
103
+
in `src/main/graphql` are included in all services. This means your project could look like this (e.g. when certain
104
+
operations must only exist in debug builds):
96
105
97
106
```
98
107
- main
@@ -118,7 +127,8 @@ Or for instance like this (specific backend per flavor):
118
127
- operations.graphql // Operations specific to the 'full' flavor
119
128
```
120
129
121
-
If you have many variants and don't need to configure an Apollo Service for each one of them, it may be simpler to declare the Services manually, for instance:
130
+
If you have many variants and don't need to configure an Apollo Service for each one of them, it may be simpler to
131
+
declare the Services manually, for instance:
122
132
123
133
```kotlin
124
134
apollo {
@@ -139,7 +149,6 @@ apollo {
139
149
}
140
150
```
141
151
142
-
143
152
## Downloading a schema
144
153
145
154
By default, the Gradle plugin registers a `downloadApolloSchema` task that you can use from the command line:
@@ -169,9 +178,11 @@ apollo {
169
178
}
170
179
```
171
180
172
-
This will create a task named `download<ServiceName>ApolloSchemaFromIntrospection` (`downloadServiceApolloSchemaFromIntrospection` by default).
181
+
This will create a task
182
+
named `download<ServiceName>ApolloSchemaFromIntrospection` (`downloadServiceApolloSchemaFromIntrospection` by default).
173
183
174
-
If you register your schema with [Apollo Studio](https://www.apollographql.com/docs/studio/), use the `registry` block instead:
184
+
If you register your schema with [Apollo Studio](https://www.apollographql.com/docs/studio/), use the `registry` block
185
+
instead:
175
186
176
187
```kotlin
177
188
apollo {
@@ -189,4 +200,152 @@ apollo {
189
200
}
190
201
```
191
202
192
-
This will create a task named `download<ServiceName>ApolloSchemaFromRegistry` (`downloadServiceApolloSchemaFromRegistry` by default).
203
+
This will create a task named `download<ServiceName>ApolloSchemaFromRegistry` (`downloadServiceApolloSchemaFromRegistry`
204
+
by default).
205
+
206
+
## All options
207
+
208
+
Below is a summary of the Gradle options in a single code block. For more details, take a look at the [ApolloExtension KDoc](https://www.apollographql.com/docs/kotlin/kdoc/apollo-gradle-plugin-external/com.apollographql.apollo3.gradle.api/-apollo-extension/index.html)
209
+
210
+
```kotlin
211
+
apollo {
212
+
service("api") {
213
+
// The package name for the generated models
214
+
packageName.set("com.example")
215
+
216
+
// Adds the given directory as a GraphQL source root
0 commit comments