|
3 | 3 | import com.kobylynskyi.graphql.codegen.GraphQLCodegen; |
4 | 4 | import com.kobylynskyi.graphql.codegen.java.JavaGraphQLCodegen; |
5 | 5 | import com.kobylynskyi.graphql.codegen.kotlin.KotlinGraphQLCodegen; |
6 | | -import com.kobylynskyi.graphql.codegen.model.ApiInterfaceStrategy; |
7 | | -import com.kobylynskyi.graphql.codegen.model.ApiNamePrefixStrategy; |
8 | | -import com.kobylynskyi.graphql.codegen.model.ApiRootInterfaceStrategy; |
9 | | -import com.kobylynskyi.graphql.codegen.model.GeneratedLanguage; |
10 | | -import com.kobylynskyi.graphql.codegen.model.GraphQLCodegenConfiguration; |
11 | | -import com.kobylynskyi.graphql.codegen.model.MappingConfig; |
12 | | -import com.kobylynskyi.graphql.codegen.model.MappingConfigConstants; |
| 6 | +import com.kobylynskyi.graphql.codegen.model.*; |
13 | 7 | import com.kobylynskyi.graphql.codegen.model.exception.LanguageNotSupportedException; |
14 | 8 | import com.kobylynskyi.graphql.codegen.scala.ScalaGraphQLCodegen; |
15 | 9 | import com.kobylynskyi.graphql.codegen.supplier.JsonMappingConfigSupplier; |
|
18 | 12 | import org.gradle.api.Action; |
19 | 13 | import org.gradle.api.DefaultTask; |
20 | 14 | import org.gradle.api.plugins.JavaPluginConvention; |
21 | | -import org.gradle.api.tasks.Input; |
22 | | -import org.gradle.api.tasks.InputFile; |
23 | | -import org.gradle.api.tasks.InputFiles; |
24 | | -import org.gradle.api.tasks.Internal; |
25 | | -import org.gradle.api.tasks.Nested; |
26 | 15 | import org.gradle.api.tasks.Optional; |
27 | | -import org.gradle.api.tasks.OutputDirectory; |
28 | | -import org.gradle.api.tasks.SourceSet; |
29 | | -import org.gradle.api.tasks.TaskAction; |
| 16 | +import org.gradle.api.tasks.*; |
30 | 17 |
|
31 | 18 | import java.io.File; |
32 | 19 | import java.io.IOException; |
33 | 20 | import java.nio.file.Path; |
34 | 21 | import java.nio.file.Paths; |
35 | | -import java.util.Collections; |
36 | | -import java.util.HashMap; |
37 | | -import java.util.HashSet; |
38 | | -import java.util.List; |
39 | | -import java.util.Map; |
40 | | -import java.util.Set; |
| 22 | +import java.util.*; |
| 23 | +import java.util.function.Supplier; |
41 | 24 |
|
42 | 25 | /** |
43 | 26 | * Gradle task for GraphQL code generation |
@@ -163,15 +146,17 @@ public void generate() throws Exception { |
163 | 146 | } |
164 | 147 |
|
165 | 148 | private GraphQLCodegen instantiateCodegen(MappingConfig mappingConfig) throws IOException { |
166 | | - switch (generatedLanguage) { |
| 149 | + java.util.Optional<MappingConfigSupplier> mappingConfigSupplier = buildJsonSupplier(); |
| 150 | + GeneratedLanguage language = mappingConfigSupplier.map(Supplier::get).map(MappingConfig::getGeneratedLanguage).orElse(generatedLanguage); |
| 151 | + switch (language) { |
167 | 152 | case JAVA: |
168 | | - return new JavaGraphQLCodegen(getActualSchemaPaths(), graphqlQueryIntrospectionResultPath, outputDir, mappingConfig, buildJsonSupplier()); |
| 153 | + return new JavaGraphQLCodegen(getActualSchemaPaths(), graphqlQueryIntrospectionResultPath, outputDir, mappingConfig, mappingConfigSupplier.orElse(null)); |
169 | 154 | case SCALA: |
170 | | - return new ScalaGraphQLCodegen(getActualSchemaPaths(), graphqlQueryIntrospectionResultPath, outputDir, mappingConfig, buildJsonSupplier()); |
| 155 | + return new ScalaGraphQLCodegen(getActualSchemaPaths(), graphqlQueryIntrospectionResultPath, outputDir, mappingConfig, mappingConfigSupplier.orElse(null)); |
171 | 156 | case KOTLIN: |
172 | | - return new KotlinGraphQLCodegen(getActualSchemaPaths(), graphqlQueryIntrospectionResultPath, outputDir, mappingConfig, buildJsonSupplier()); |
| 157 | + return new KotlinGraphQLCodegen(getActualSchemaPaths(), graphqlQueryIntrospectionResultPath, outputDir, mappingConfig, mappingConfigSupplier.orElse(null)); |
173 | 158 | default: |
174 | | - throw new LanguageNotSupportedException(generatedLanguage); |
| 159 | + throw new LanguageNotSupportedException(language); |
175 | 160 | } |
176 | 161 | } |
177 | 162 |
|
@@ -216,11 +201,11 @@ private java.util.Optional<Path> findDefaultResourcesDir() { |
216 | 201 | .map(File::toPath); |
217 | 202 | } |
218 | 203 |
|
219 | | - private MappingConfigSupplier buildJsonSupplier() { |
| 204 | + private java.util.Optional<MappingConfigSupplier> buildJsonSupplier() { |
220 | 205 | if (jsonConfigurationFile != null && !jsonConfigurationFile.isEmpty()) { |
221 | | - return new JsonMappingConfigSupplier(jsonConfigurationFile); |
| 206 | + return java.util.Optional.of(new JsonMappingConfigSupplier(jsonConfigurationFile)); |
222 | 207 | } |
223 | | - return null; |
| 208 | + return java.util.Optional.empty(); |
224 | 209 | } |
225 | 210 |
|
226 | 211 | @InputFiles |
|
0 commit comments