Gradle configuration options
Apollo Android comes with logical defaults that will work for the majority of use cases. If you're getting started, see the getting started guide for an overview of the most common options. This page describes the different options individually.
ApolloExtension, Services and CompilationUnit
The Gradle DSL exposes three types of objects:
ApolloExtension is the global entry point of the plugin and will configure global options.
A Service is the configuration of a single GraphQL endpoint. If your app uses multiple GraphQL endpoints, you will need to define several services.
A CompilationUnit is an invocation of the Apollo compiler. It happens for each Service and Variant in your project.
These 3 objects inherit from CompilerParams
and compiler options can be set in all of them. Options set on the most reduced scopes will override those set on the more global scopes:
Default compiler parameters are taken from
ApolloExtension
Compiler parameters from
Service
override the ones fromApolloExtension
Compiler parameters from
CompilerUnit
override the ones fromService
A complete configuration block with multiple services will look like this:
1apollo {
2 // configure ApolloExtension here
3 generateKotlinModels.set(true) // Generate Kotlin models for all services
4
5 service("starwars") {
6 // Overwrite some options here for the starwars Service here if needed
7 sourceFolder = "starwars"
8 rootPackageName = "com.starwars"
9 }
10 service("githunt") {
11 // Overwrite some options here for the githunt Service here if needed
12 sourceFolder = "githunt"
13 rootPackageName = "com.starwars"
14 }
15
16 onCompilationUnit {
17 // Overwrite some options here for single CompilationUnit if needed
18 }
19}
20
The up-to-date list of options can be found in CompilerParams:
1 /**
2 * Whether to generate Java or Kotlin models
3 *
4 * Default value: false
5 */
6 val generateKotlinModels: Property<Boolean>
7
8 /**
9 * Whether to generate operationOutput.json. operationOutput.json contains information such as
10 * operation id, name and complete source sent to the server. This can be used to upload
11 * a query's exact content to a server that doesn't support automatic persisted queries.
12 *
13 * The operation output is written in [CompilationUnit.operationOutputFile]
14 *
15 * Default value: false
16 */
17 val generateOperationOutput: Property<Boolean>
18
19
20 /**
21 * For custom scalar types like Date, map from the GraphQL type to the jvm/kotlin type.
22 *
23 * Default value: the empty map
24 */
25 val customTypeMapping: MapProperty<String, String>
26
27 /**
28 * By default, Apollo uses `Sha256` hashing algorithm to generate an ID for the query.
29 * To provide a custom ID generation logic, pass an `instance` that implements the [OperationIdGenerator]. How the ID is generated is
30 * indifferent to the compiler. It can be an hashing algorithm or generated by a backend.
31 *
32 * Example Md5 hash generator:
33 *
34 * import com.apollographql.apollo.compiler.OperationIdGenerator
35 *
36 * apollo {
37 * operationIdGenerator = new OperationIdGenerator() {
38 * String apply(String operationDocument, String operationFilepath) {
39 * return operationDocument.md5()
40 * }
41 *
42 * /**
43 * * Use this version override to indicate an update to the implementation.
44 * * This invalidates the current cache.
45 * */
46 * String version = "v1"
47 * }
48 * }
49 *
50 * Default value: [OperationIdGenerator.Sha256]
51 */
52 val operationIdGenerator: Property<OperationIdGenerator>
53
54 /**
55 * The custom types code generate some warnings that might make the build fail.
56 * suppressRawTypesWarning will add the appropriate SuppressWarning annotation
57 *
58 * Default value: false
59 */
60 val suppressRawTypesWarning: Property<Boolean>
61
62 /**
63 * When true, Apollo Android will make sure all the generated classes end with 'Query' or 'Mutation'.
64 * If you write `query droid { ... }`, the generated class will be named 'DroidQuery'.
65 *
66 * Default value: true
67 */
68 val useSemanticNaming: Property<Boolean>
69
70 /**
71 * The nullable value type to use. One of: "annotated", "apolloOptional", "guavaOptional", "javaOptional", "inputType"
72 *
73 * Default value: "annotated"
74 * Only valid for java models as kotlin has proper nullability support
75 */
76 val nullableValueType: Property<String>
77
78 /**
79 * Whether to generate builders for java models
80 *
81 * Default value: false
82 * Only valid for java models as kotlin has data classes
83 */
84 val generateModelBuilder: Property<Boolean>
85
86 /**
87 * When true, Apollo Android will use java beans getters in the models. If you request a property named 'user', the generated
88 * model will have a `getUser()` property instead of `user()`
89 *
90 * Default value: false
91 * Only valid for java as kotlin has properties
92 */
93 val useJavaBeansSemanticNaming: Property<Boolean>
94
95 /**
96 * Apollo Gradle plugin supports generating visitors for compile-time safe handling of polymorphic datatypes.
97 * Enabling this requires source/target compatibility with Java 1.8.
98 *
99 * Default value: false
100 */
101 val generateVisitorForPolymorphicDatatypes: Property<Boolean>
102
103 /**
104 * The package name of the models is computed from their folder hierarchy like for java sources.
105 *
106 * If you want, you can prepend a custom package name here to namespace your models.
107 *
108 * Default value: the empty string
109 */
110 val rootPackageName: Property<String>
111
112 /**
113 * The graphql files containing the queries.
114 *
115 * This SourceDirectorySet includes .graphql and .gql files by default.
116 *
117 * By default, it will use [Service.sourceFolder] to populate the SourceDirectorySet.
118 * You can override it from [ApolloExtension.onCompilationUnit] for more advanced use cases
119 */
120 val graphqlSourceDirectorySet: SourceDirectorySet
121
122 /**
123 * The schema file
124 *
125 * By default, it will use [Service.schemaPath] to set schemaFile.
126 * You can override it from [ApolloExtension.onCompilationUnit] for more advanced use cases
127 */
128 val schemaFile: RegularFileProperty
129
130 /**
131 * Whether to generate Kotlin models with `internal` visibility modifier.
132 *
133 * Default value: false
134 */
135 val generateAsInternal: Property<Boolean>
136
137 /**
138 * A list of [Regex] patterns for GraphQL enums that should be generated as Kotlin sealed classes instead of the default Kotlin enums.
139 *
140 * Use this if you want your client to have access to the rawValue of the enum. This can be useful if new GraphQL enums are added but
141 * the client was compiled against an older schema that doesn't have knowledge of the new enums.
142 */
143 val sealedClassesForEnumsMatching: ListProperty<String>