/
GraphQLPluginExtension.kt
65 lines (56 loc) · 2.77 KB
/
GraphQLPluginExtension.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* Copyright 2020 Expedia, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.expediagroup.graphql.plugin.gradle
import com.expediagroup.graphql.plugin.config.TimeoutConfig
import com.expediagroup.graphql.plugin.generator.ScalarConverterMapping
import java.io.File
/**
* GraphQL Kotlin Gradle Plugin extension.
*/
@Suppress("UnstableApiUsage")
open class GraphQLPluginExtension {
private var clientExtensionConfigured: Boolean = false
internal val clientExtension: GraphQLPluginClientExtension by lazy {
clientExtensionConfigured = true
GraphQLPluginClientExtension()
}
/** Plugin configuration for generating GraphQL client. */
fun client(config: GraphQLPluginClientExtension.() -> Unit = {}) {
clientExtension.apply(config)
}
internal fun isClientConfigurationAvailable(): Boolean = clientExtensionConfigured
}
open class GraphQLPluginClientExtension {
/** GraphQL server endpoint that will be used to for running introspection queries. Alternatively you can download schema directly from [sdlEndpoint]. */
var endpoint: String? = null
/** GraphQL server SDL endpoint that will be used to download schema. Alternatively you can run introspection query against [endpoint]. */
var sdlEndpoint: String? = null
/** Target package name to be used for generated classes. */
var packageName: String? = null
/** Optional HTTP headers to be specified on an introspection query or SDL request. */
var headers: MutableMap<String, Any> = mutableMapOf()
/** Boolean flag indicating whether or not selection of deprecated fields is allowed. */
var allowDeprecatedFields: Boolean = false
/** Custom GraphQL scalar to converter mapping containing information about corresponding Java type and converter that should be used to serialize/deserialize values. */
var converters: MutableMap<String, ScalarConverterMapping> = mutableMapOf()
/** List of query files to be processed. */
var queryFiles: MutableList<File> = mutableListOf()
/** Connect and read timeout configuration for executing introspection query/download schema */
internal val timeoutConfig: TimeoutConfig = TimeoutConfig()
fun timeout(config: TimeoutConfig.() -> Unit = {}) {
timeoutConfig.apply(config)
}
}