11package io .github .kobylynskyi .graphql .codegen .gradle ;
22
33import com .kobylynskyi .graphql .codegen .GraphQLCodegen ;
4- import com .kobylynskyi .graphql .codegen .model .DefaultMappingConfigValues ;
54import com .kobylynskyi .graphql .codegen .model .GraphQLCodegenConfiguration ;
65import com .kobylynskyi .graphql .codegen .model .MappingConfig ;
6+ import com .kobylynskyi .graphql .codegen .model .MappingConfigConstants ;
77import com .kobylynskyi .graphql .codegen .supplier .JsonMappingConfigSupplier ;
88import com .kobylynskyi .graphql .codegen .supplier .MappingConfigSupplier ;
99import com .kobylynskyi .graphql .codegen .supplier .SchemaFinder ;
1010import org .gradle .api .Action ;
1111import org .gradle .api .DefaultTask ;
1212import org .gradle .api .plugins .JavaPluginConvention ;
13- import org .gradle .api .tasks .Input ;
14- import org .gradle .api .tasks .InputFile ;
15- import org .gradle .api .tasks .InputFiles ;
16- import org .gradle .api .tasks .Nested ;
1713import org .gradle .api .tasks .Optional ;
18- import org .gradle .api .tasks .OutputDirectory ;
19- import org .gradle .api .tasks .SourceSet ;
20- import org .gradle .api .tasks .TaskAction ;
14+ import org .gradle .api .tasks .*;
2115
2216import java .io .File ;
2317import java .io .IOException ;
@@ -43,20 +37,21 @@ public class GraphQLCodegenGradleTask extends DefaultTask implements GraphQLCode
4337 private String modelNamePrefix ;
4438 private String modelNameSuffix ;
4539 private String subscriptionReturnType ;
46- private Boolean generateBuilder = DefaultMappingConfigValues .DEFAULT_BUILDER ;
47- private Boolean generateApis = DefaultMappingConfigValues .DEFAULT_GENERATE_APIS ;
40+ private Boolean generateBuilder = MappingConfigConstants .DEFAULT_BUILDER ;
41+ private Boolean generateApis = MappingConfigConstants .DEFAULT_GENERATE_APIS ;
4842 private String modelValidationAnnotation ;
49- private Boolean generateEqualsAndHashCode = DefaultMappingConfigValues .DEFAULT_EQUALS_AND_HASHCODE ;
50- private Boolean generateToString = DefaultMappingConfigValues .DEFAULT_TO_STRING ;
51- private Boolean generateAsyncApi = DefaultMappingConfigValues .DEFAULT_GENERATE_ASYNC_APIS ;
52- private Boolean generateParameterizedFieldsResolvers = DefaultMappingConfigValues .DEFAULT_GENERATE_PARAMETERIZED_FIELDS_RESOLVERS ;
53- private Boolean generateExtensionFieldsResolvers = DefaultMappingConfigValues .DEFAULT_GENERATE_EXTENSION_FIELDS_RESOLVERS ;
54- private Boolean generateDataFetchingEnvironmentArgumentInApis = DefaultMappingConfigValues .DEFAULT_GENERATE_DATA_FETCHING_ENV ;
43+ private Boolean generateEqualsAndHashCode = MappingConfigConstants .DEFAULT_EQUALS_AND_HASHCODE ;
44+ private Boolean generateToString = MappingConfigConstants .DEFAULT_TO_STRING ;
45+ private Boolean generateAsyncApi = MappingConfigConstants .DEFAULT_GENERATE_ASYNC_APIS ;
46+ private Boolean generateParameterizedFieldsResolvers = MappingConfigConstants .DEFAULT_GENERATE_PARAMETERIZED_FIELDS_RESOLVERS ;
47+ private Boolean generateExtensionFieldsResolvers = MappingConfigConstants .DEFAULT_GENERATE_EXTENSION_FIELDS_RESOLVERS ;
48+ private Boolean generateDataFetchingEnvironmentArgumentInApis = MappingConfigConstants .DEFAULT_GENERATE_DATA_FETCHING_ENV ;
5549 private Set <String > fieldsWithResolvers = new HashSet <>();
5650 private Set <String > fieldsWithoutResolvers = new HashSet <>();
5751 private Boolean generateRequests ;
5852 private String requestSuffix ;
5953 private String responseProjectionSuffix ;
54+ private final ParentInterfacesConfig parentInterfaces = new ParentInterfacesConfig ();
6055 private String jsonConfigurationFile ;
6156
6257 public GraphQLCodegenGradleTask () {
@@ -89,6 +84,10 @@ public void generate() throws Exception {
8984 mappingConfig .setGenerateRequests (generateRequests );
9085 mappingConfig .setRequestSuffix (requestSuffix );
9186 mappingConfig .setResponseProjectionSuffix (responseProjectionSuffix );
87+ mappingConfig .setResolverParentInterface (getResolverParentInterface ());
88+ mappingConfig .setQueryResolverParentInterface (getQueryResolverParentInterface ());
89+ mappingConfig .setMutationResolverParentInterface (getMutationResolverParentInterface ());
90+ mappingConfig .setSubscriptionResolverParentInterface (getSubscriptionResolverParentInterface ());
9291
9392 new GraphQLCodegen (getActualSchemaPaths (), outputDir , mappingConfig , buildJsonSupplier ()).generate ();
9493 }
@@ -120,15 +119,15 @@ private Path getSchemasRootDir() {
120119
121120 private java .util .Optional <Path > findDefaultResourcesDir () {
122121 return getProject ().getConvention ()
123- .getPlugin (JavaPluginConvention .class )
124- .getSourceSets ()
125- .getByName (SourceSet .MAIN_SOURCE_SET_NAME )
126- .getResources ()
127- .getSourceDirectories ()
128- .getFiles ()
129- .stream ()
130- .findFirst ()
131- .map (File ::toPath );
122+ .getPlugin (JavaPluginConvention .class )
123+ .getSourceSets ()
124+ .getByName (SourceSet .MAIN_SOURCE_SET_NAME )
125+ .getResources ()
126+ .getSourceDirectories ()
127+ .getFiles ()
128+ .stream ()
129+ .findFirst ()
130+ .map (File ::toPath );
132131 }
133132
134133 private MappingConfigSupplier buildJsonSupplier () {
@@ -409,6 +408,40 @@ public void setResponseProjectionSuffix(String responseProjectionSuffix) {
409408 this .responseProjectionSuffix = responseProjectionSuffix ;
410409 }
411410
411+ @ Nested
412+ @ Optional
413+ public ParentInterfacesConfig getParentInterfaces () {
414+ return parentInterfaces ;
415+ }
416+
417+ public void parentInterfaces (Action <? super ParentInterfacesConfig > action ) {
418+ action .execute (parentInterfaces );
419+ }
420+
421+ @ Internal
422+ @ Override
423+ public String getQueryResolverParentInterface () {
424+ return parentInterfaces .getQueryResolver ();
425+ }
426+
427+ @ Internal
428+ @ Override
429+ public String getMutationResolverParentInterface () {
430+ return parentInterfaces .getMutationResolver ();
431+ }
432+
433+ @ Internal
434+ @ Override
435+ public String getSubscriptionResolverParentInterface () {
436+ return parentInterfaces .getSubscriptionResolver ();
437+ }
438+
439+ @ Internal
440+ @ Override
441+ public String getResolverParentInterface () {
442+ return parentInterfaces .getResolver ();
443+ }
444+
412445 @ InputFile
413446 @ Optional
414447 public String getJsonConfigurationFile () {
0 commit comments