Skip to content

Commit 9705f31

Browse files
committed
Add support of subReturnType, genToString, jsonConfFile. Bump to 1.3.0
1 parent 42b2e18 commit 9705f31

File tree

4 files changed

+85
-22
lines changed

4 files changed

+85
-22
lines changed

README.md

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This Gradle plugin is able to generate the following classes based on your Graph
1818

1919
```groovy
2020
plugins {
21-
id "io.github.kobylynskyi.graphql.codegen" version "1.2.3"
21+
id "io.github.kobylynskyi.graphql.codegen" version "1.3.0"
2222
}
2323
```
2424

@@ -32,7 +32,7 @@ buildscript {
3232
}
3333
}
3434
dependencies {
35-
classpath "io.github.kobylynskyi.graphql.codegen:graphql-codegen-gradle-plugin:1.2.3"
35+
classpath "io.github.kobylynskyi.graphql.codegen:graphql-codegen-gradle-plugin:1.3.0"
3636
}
3737
}
3838
@@ -91,21 +91,38 @@ check.dependsOn(graphqlCodegen)
9191

9292
#### Plugin Options
9393

94-
| Key | Data Type | Default value | Description |
95-
| ------------------------- | ------------------ | ------------------------------------- | ----------- |
96-
| graphqlSchemaPaths | List(String) | None | GraphQL schema locations. You can supply multiple paths to GraphQL schemas. |
97-
| packageName | String | Empty | Java package for generated classes. |
98-
| outputDir | String | None | The output target directory into which code will be generated. |
99-
| apiPackage | String | Empty | Java package for generated api classes (Query, Mutation, Subscription). |
100-
| modelPackage | String | Empty | Java package for generated model classes (type, input, interface, enum, union). |
101-
| generateApis | Boolean | True | Specifies whether api classes should be generated as well as model classes. |
102-
| customTypesMapping | Map(String,String) | Empty | Can be used to supply custom mappings for scalars. <br/> Supports:<br/> * Map of (GraphqlObjectName.fieldName) to (JavaType) <br/> * Map of (GraphqlType) to (JavaType) |
103-
| customAnnotationsMapping | Map(String,String) | Empty | Can be used to supply custom annotations (serializers) for scalars. <br/> Supports:<br/> * Map of (GraphqlObjectName.fieldName) to (JavaType) <br/> * Map of (GraphqlType) to (JavaType) |
94+
| Key | Data Type | Default value | Description |
95+
| ------------------------- | ------------------ | ----------------------------------------- | ----------- |
96+
| graphqlSchemaPaths | List(String) | None | GraphQL schema locations. You can supply multiple paths to GraphQL schemas. |
97+
| packageName | String | Empty | Java package for generated classes. |
98+
| outputDir | String | None | The output target directory into which code will be generated. |
99+
| apiPackage | String | Empty | Java package for generated api classes (Query, Mutation, Subscription). |
100+
| modelPackage | String | Empty | Java package for generated model classes (type, input, interface, enum, union). |
101+
| generateApis | Boolean | True | Specifies whether api classes should be generated as well as model classes. |
102+
| customTypesMapping | Map(String,String) | Empty | Can be used to supply custom mappings for scalars. <br/> Supports:<br/> * Map of (GraphqlObjectName.fieldName) to (JavaType) <br/> * Map of (GraphqlType) to (JavaType) |
103+
| customAnnotationsMapping | Map(String,String) | Empty | Can be used to supply custom annotations (serializers) for scalars. <br/> Supports:<br/> * Map of (GraphqlObjectName.fieldName) to (JavaType) <br/> * Map of (GraphqlType) to (JavaType) |
104104
| modelValidationAnnotation | String | @javax.validation.<br>constraints.NotNull | Annotation for mandatory (NonNull) fields. Can be null/empty. |
105-
| modelNamePrefix | String | Empty | Sets the prefix for GraphQL model classes (type, input, interface, enum, union). |
106-
| modelNameSuffix | String | Empty | Sets the suffix for GraphQL model classes (type, input, interface, enum, union). |
107-
| generateEqualsAndHashCode | Boolean | False | Specifies whether generated model classes should have equals and hashCode methods defined. |
108-
105+
| modelNamePrefix | String | Empty | Sets the prefix for GraphQL model classes (type, input, interface, enum, union). |
106+
| modelNameSuffix | String | Empty | Sets the suffix for GraphQL model classes (type, input, interface, enum, union). |
107+
| subscriptionReturnType | String | Empty | Return type for subscription methods. For example: `org.reactivestreams.Publisher`, `io.reactivex.Observable`, etc. |
108+
| generateEqualsAndHashCode | Boolean | False | Specifies whether generated model classes should have equals and hashCode methods defined. |
109+
| generateToString | Boolean | False | Specifies whether generated model classes should have toString method defined. |
110+
| jsonConfigurationFile | String | Empty | Path to an external mapping configuration. |
111+
112+
#### External mapping configuration
113+
114+
Provide a path to external file via property `jsonConfigurationFile`
115+
Sample content of the file:
116+
117+
```json
118+
{
119+
"generateApis": true,
120+
"packageName": "com.kobylynskyi.graphql.testconfigjson",
121+
"customTypesMapping": {
122+
"Price.amount": "java.math.BigDecimal"
123+
}
124+
}
125+
```
109126

110127
### Different configuration for each graphql schema
111128

graphql-codegen-gradle-plugin-example/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
id "idea"
44
id "application"
55
id "net.ltgt.apt" version "0.20"
6-
id "io.github.kobylynskyi.graphql.codegen" version "1.2.3"
6+
id "io.github.kobylynskyi.graphql.codegen" version "1.3.0"
77
}
88

99
mainClassName = "io.github.kobylynskyi.bikeshop.Application"

graphql-codegen-gradle-plugin/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ apply plugin: "idea"
1717
apply plugin: "maven-publish"
1818

1919
group = "io.github.kobylynskyi"
20-
version = "1.2.3"
20+
version = "1.3.0"
2121
description = "Provides a task for generating Java code based on GraphQL schema"
2222

2323
dependencies {
2424
compile gradleApi()
2525

26-
compile 'io.github.kobylynskyi:graphql-java-codegen:1.2.3'
26+
compile 'io.github.kobylynskyi:graphql-java-codegen:1.3.0'
2727

2828
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.1'
2929
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.5.1'

graphql-codegen-gradle-plugin/src/main/java/io/github/kobylynskyi/graphql/codegen/gradle/GraphqlCodegenGradleTask.java

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.kobylynskyi.graphql.codegen.GraphqlCodegen;
44
import com.kobylynskyi.graphql.codegen.model.MappingConfig;
5+
import com.kobylynskyi.graphql.codegen.supplier.JsonMappingConfigSupplier;
6+
import com.kobylynskyi.graphql.codegen.supplier.MappingConfigSupplier;
57
import org.gradle.api.DefaultTask;
68
import org.gradle.api.tasks.Input;
79
import org.gradle.api.tasks.Optional;
@@ -29,9 +31,12 @@ public class GraphqlCodegenGradleTask extends DefaultTask {
2931
private String modelPackageName;
3032
private String modelNamePrefix;
3133
private String modelNameSuffix;
34+
private String subscriptionReturnType;
3235
private Boolean generateApis = true;
3336
private String modelValidationAnnotation;
3437
private Boolean generateEqualsAndHashCode = false;
38+
private Boolean generateToString = false;
39+
private String jsonConfigurationFile;
3540

3641
@TaskAction
3742
public void generate() throws Exception {
@@ -44,9 +49,19 @@ public void generate() throws Exception {
4449
mappingConfig.setModelPackageName(modelPackageName);
4550
mappingConfig.setGenerateApis(generateApis);
4651
mappingConfig.setModelValidationAnnotation(modelValidationAnnotation);
52+
mappingConfig.setSubscriptionReturnType(subscriptionReturnType);
4753
mappingConfig.setCustomAnnotationsMapping(customAnnotationsMapping);
4854
mappingConfig.setGenerateEqualsAndHashCode(generateEqualsAndHashCode);
49-
new GraphqlCodegen(graphqlSchemaPaths, outputDir, mappingConfig).generate();
55+
mappingConfig.setGenerateToString(generateToString);
56+
57+
new GraphqlCodegen(graphqlSchemaPaths, outputDir, mappingConfig, buildJsonSupplier()).generate();
58+
}
59+
60+
private MappingConfigSupplier buildJsonSupplier() {
61+
if (jsonConfigurationFile != null && !jsonConfigurationFile.isEmpty()) {
62+
return new JsonMappingConfigSupplier(jsonConfigurationFile);
63+
}
64+
return null;
5065
}
5166

5267
@Input
@@ -160,10 +175,41 @@ public void setCustomAnnotationsMapping(Map<String, String> customAnnotationsMap
160175
@Input
161176
@Optional
162177
public boolean getGenerateEqualsAndHashCode() {
163-
return generateEqualsAndHashCode;
178+
return generateEqualsAndHashCode;
164179
}
165180

166181
public void setGenerateEqualsAndHashCode(Boolean generateEqualsAndHashCode) {
167-
this.generateEqualsAndHashCode = generateEqualsAndHashCode;
182+
this.generateEqualsAndHashCode = generateEqualsAndHashCode;
183+
}
184+
185+
@Input
186+
@Optional
187+
public Boolean getGenerateToString() {
188+
return generateToString;
189+
}
190+
191+
public void setGenerateToString(Boolean generateToString) {
192+
this.generateToString = generateToString;
193+
}
194+
195+
@Input
196+
@Optional
197+
public String getSubscriptionReturnType() {
198+
return subscriptionReturnType;
199+
}
200+
201+
public void setSubscriptionReturnType(String subscriptionReturnType) {
202+
this.subscriptionReturnType = subscriptionReturnType;
168203
}
204+
205+
@Input
206+
@Optional
207+
public String getJsonConfigurationFile() {
208+
return jsonConfigurationFile;
209+
}
210+
211+
public void setJsonConfigurationFile(String jsonConfigurationFile) {
212+
this.jsonConfigurationFile = jsonConfigurationFile;
213+
}
214+
169215
}

0 commit comments

Comments
 (0)