Skip to content

Commit 0198f41

Browse files
authored
Merge pull request #953 from kobylynskyi/develop
5.4.0 release
2 parents 8eaef37 + 0443f98 commit 0198f41

File tree

120 files changed

+1537
-89
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+1537
-89
lines changed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ plugins {
99
id "org.sonarqube" version "3.2.0"
1010
}
1111

12-
def graphqlCodegenVersion = '5.3.0' // This variable used in the automatic release process
12+
def graphqlCodegenVersion = '5.4.0' // This variable used in the automatic release process
1313

1414
group = "io.github.kobylynskyi"
1515
version = graphqlCodegenVersion

docs/codegen-options.md

+6
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,13 @@ See [DirectiveAnnotationsMapping](#option-directiveannotationsmapping)* |
5656
| `responseProjectionMaxDepth` | Integer | 3 | Sets max depth when use `all$()` which for facilitating the construction of projection automatically, the fields on all projections are provided when it be invoked. This is a global configuration, of course, you can use `all$(max)` to set for each method. For self recursive types, too big depth may result in a large number of returned data!|
5757
| `generatedLanguage` | Enum | GeneratedLanguage.JAVA | Choose which language you want to generate, Java,Scala,Kotlin were supported. Note that due to language features, there are slight differences in default values between languages.|
5858
| `generateModelOpenClasses` | Boolean | false | The class type of the generated model. If true, generate normal classes, else generate data classes. It only support in kotlin(```data class```) and scala(```case class```). Maybe we will consider to support Java ```record``` in the future.|
59+
| `initializeNullableTypes` | Boolean | false | Adds a default null value to nullable arguments. Only supported in Kotlin.
60+
| `generateSealedInterfaces` | Boolean | false | This applies to generated interfaces on unions and interfaces. If true, generate sealed interfaces, else generate normal ones. It is only supported in Kotlin. |
5961
| `typesAsInterfaces` | Set(String) | Empty | Types that must generated as interfaces should be defined here in format: `TypeName` or `@directive`. E.g.: `User`, `@asInterface`. |
62+
| `useObjectMapperForRequestSerialization` | Set(String) | Empty | Fields that require serialization using `com.fasterxml.jackson.databind.ObjectMapper#writeValueAsString(Object)`. Values should be defined here in the following format: `GraphqlObjectName.fieldName` or `GraphqlTypeName`. If just type is specified, then all fields of this type will be serialized using ObjectMapper. E.g.: `["Person.createdDateTime", ZonedDateTime"]` |
63+
| `supportUnknownFields` | Boolean | false | Specifies whether api classes should support unknown fields during serialization or deserialization. If `true`, classes will include a property of type [`java.util.Map<String,Object>`](https://docs.oracle.com/javase/8/docs/api/index.html?java/util/Map.html) that will store unknown fields.|
64+
| `unknownFieldsPropertyName` | String | userDefinedFields | Specifies the name of the property to be included in api classes to support unknown fields during serialization or deserialization|
65+
6066

6167
### Option `graphqlSchemas`
6268

plugins/gradle/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
```groovy
1919
plugins {
20-
id "io.github.kobylynskyi.graphql.codegen" version "5.3.0"
20+
id "io.github.kobylynskyi.graphql.codegen" version "5.4.0"
2121
}
2222
```
2323

@@ -31,7 +31,7 @@ buildscript {
3131
}
3232
}
3333
dependencies {
34-
classpath "io.github.kobylynskyi.graphql.codegen:graphql-codegen-gradle-plugin:5.3.0"
34+
classpath "io.github.kobylynskyi.graphql.codegen:graphql-codegen-gradle-plugin:5.4.0"
3535
}
3636
}
3737

plugins/gradle/example-client-kotlin/build.gradle

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import io.github.kobylynskyi.graphql.codegen.gradle.GraphQLCodegenGradleTask
44
plugins {
55
id 'java'
66
id "org.jetbrains.kotlin.jvm" version "1.3.71"
7-
id "io.github.kobylynskyi.graphql.codegen" version "5.3.0"
7+
id "io.github.kobylynskyi.graphql.codegen" version "5.4.0"
88
}
99

10-
def graphqlCodegenClientKotlinVersion = '5.3.0' // Variable used in the automatic release process
10+
def graphqlCodegenClientKotlinVersion = '5.4.0' // Variable used in the automatic release process
1111

1212
group = 'io.github.dreamylost'
1313
version = graphqlCodegenClientKotlinVersion
@@ -29,7 +29,7 @@ repositories {
2929

3030

3131
dependencies {
32-
implementation "io.github.kobylynskyi:graphql-java-codegen:5.3.0"
32+
implementation "io.github.kobylynskyi:graphql-java-codegen:5.4.0"
3333
implementation "javax.validation:validation-api:2.0.1.Final"
3434
implementation "com.squareup.okhttp3:okhttp:4.2.2"
3535
implementation "com.fasterxml.jackson.core:jackson-core:2.12.0"
@@ -57,11 +57,13 @@ task graphqlCodegenKotlinService(type: GraphQLCodegenGradleTask) {
5757
apiPackageName = "io.github.dreamylost.api"
5858
modelPackageName = "io.github.dreamylost.model"
5959
generateModelOpenClasses = true
60+
generateSealedInterfaces = true
6061
customAnnotationsMapping = [
6162
"Character": ["@com.fasterxml.jackson.annotation.JsonTypeInfo(use=com.fasterxml.jackson.annotation.JsonTypeInfo.Id.NAME, include=com.fasterxml.jackson.annotation.JsonTypeInfo.As.PROPERTY,property = \"__typename\")",
6263
"@com.fasterxml.jackson.annotation.JsonSubTypes(value = arrayOf(" + System.lineSeparator() +
6364
" com.fasterxml.jackson.annotation.JsonSubTypes.Type(value = HumanTO::class, name = \"Human\"), " + System.lineSeparator() +
6465
" com.fasterxml.jackson.annotation.JsonSubTypes.Type(value = DroidTO::class, name = \"Droid\")))"],
6566
]
6667
modelNameSuffix = "TO"
68+
supportUnknownFields = true
6769
}

plugins/gradle/example-client/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77

88
// use the latest available version:
99
// https://plugins.gradle.org/plugin/io.github.kobylynskyi.graphql.codegen
10-
id "io.github.kobylynskyi.graphql.codegen" version "5.3.0"
10+
id "io.github.kobylynskyi.graphql.codegen" version "5.4.0"
1111
}
1212

1313
mainClassName = "io.github.kobylynskyi.order.Application"
@@ -22,7 +22,7 @@ dependencies {
2222

2323
// use the latest available version:
2424
// https://search.maven.org/artifact/io.github.kobylynskyi/graphql-java-codegen
25-
implementation "io.github.kobylynskyi:graphql-java-codegen:5.3.0"
25+
implementation "io.github.kobylynskyi:graphql-java-codegen:5.4.0"
2626

2727
implementation "org.apache.httpcomponents:httpclient:4.5.13"
2828
implementation "javax.validation:validation-api:2.0.1.Final"

plugins/gradle/example-server/build.gradle

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
//
77
// use the latest available version:
88
// https://plugins.gradle.org/plugin/io.github.kobylynskyi.graphql.codegen
9-
id "io.github.kobylynskyi.graphql.codegen" version "5.3.0"
9+
id "io.github.kobylynskyi.graphql.codegen" version "5.4.0"
1010
}
1111

1212
mainClassName = "io.github.kobylynskyi.product.Application"
@@ -48,6 +48,9 @@ graphqlCodegen {
4848
}
4949
modelNameSuffix = "TO"
5050
generateApis = true
51+
supportUnknownFields = true
52+
unknownFieldsPropertyName = "additionalFields"
53+
5154
}
5255

5356
repositories {

plugins/gradle/example-server/src/main/java/io/github/kobylynskyi/product/Application.java

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
@SpringBootApplication
77
public class Application {
88

9+
910
public static void main(String[] args) {
1011
SpringApplication.run(Application.class, args);
1112
}

plugins/gradle/graphql-java-codegen-gradle-plugin/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ apply plugin: "java"
1616
apply plugin: "idea"
1717
apply plugin: "maven-publish"
1818

19-
def graphqlCodegenGradlePluginVersion = '5.3.0' // This variable used in the automatic release process
19+
def graphqlCodegenGradlePluginVersion = '5.4.0' // This variable used in the automatic release process
2020

2121
group = "io.github.kobylynskyi"
2222
version = graphqlCodegenGradlePluginVersion

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

+55
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ public class GraphQLCodegenGradleTask extends DefaultTask implements GraphQLCode
103103
private List<String> configurationFiles;
104104
private GeneratedLanguage generatedLanguage = MappingConfigConstants.DEFAULT_GENERATED_LANGUAGE;
105105
private Boolean generateModelOpenClasses = MappingConfigConstants.DEFAULT_GENERATE_MODEL_OPEN_CLASSES;
106+
private Boolean initializeNullableTypes = MappingConfigConstants.DEFAULT_INITIALIZE_NULLABLE_TYPES;
107+
private Boolean generateSealedInterfaces = MappingConfigConstants.DEFAULT_GENERATE_SEALED_INTERFACES;
108+
109+
private Boolean supportUnknownFields = MappingConfigConstants.DEFAULT_SUPPORT_UNKNOWN_FIELDS;
110+
private String unknownFieldsPropertyName = MappingConfigConstants.DEFAULT_UNKNOWN_FIELDS_PROPERTY_NAME;
106111

107112
public GraphQLCodegenGradleTask() {
108113
setGroup("codegen");
@@ -178,6 +183,10 @@ public void generate() throws Exception {
178183

179184
mappingConfig.setGeneratedLanguage(generatedLanguage);
180185
mappingConfig.setGenerateModelOpenClasses(generateModelOpenClasses);
186+
mappingConfig.setInitializeNullableTypes(initializeNullableTypes);
187+
188+
mappingConfig.setSupportUnknownFields(isSupportUnknownFields());
189+
mappingConfig.setUnknownFieldsPropertyName(getUnknownFieldsPropertyName());
181190

182191
instantiateCodegen(mappingConfig).generate();
183192
}
@@ -844,4 +853,50 @@ public Boolean isGenerateModelOpenClasses() {
844853
public void setGenerateModelOpenClasses(Boolean generateModelOpenClasses) {
845854
this.generateModelOpenClasses = generateModelOpenClasses;
846855
}
856+
857+
@Input
858+
@Optional
859+
@Override
860+
public Boolean isInitializeNullableTypes() {
861+
return initializeNullableTypes;
862+
}
863+
864+
public void setInitializeNullableTypes(Boolean initializeNullableTypes) {
865+
this.initializeNullableTypes = initializeNullableTypes;
866+
}
867+
868+
@Input
869+
@Optional
870+
@Override
871+
public Boolean isGenerateSealedInterfaces() {
872+
return generateSealedInterfaces;
873+
}
874+
875+
public void setGenerateSealedInterfaces(Boolean generateSealedInterfaces) {
876+
this.generateSealedInterfaces = generateSealedInterfaces;
877+
}
878+
879+
@Input
880+
@Optional
881+
@Override
882+
public Boolean isSupportUnknownFields() {
883+
return supportUnknownFields;
884+
}
885+
886+
public void setSupportUnknownFields(boolean supportUnknownFields) {
887+
this.supportUnknownFields = supportUnknownFields;
888+
}
889+
890+
@Input
891+
@Optional
892+
@Override
893+
public String getUnknownFieldsPropertyName() {
894+
return unknownFieldsPropertyName;
895+
}
896+
897+
public void setUnknownFieldsPropertyName(String unknownFieldsPropertyName) {
898+
this.unknownFieldsPropertyName = unknownFieldsPropertyName;
899+
}
900+
901+
847902
}

plugins/maven/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<plugin>
2121
<groupId>io.github.kobylynskyi</groupId>
2222
<artifactId>graphql-codegen-maven-plugin</artifactId>
23-
<version>5.3.0</version>
23+
<version>5.4.0</version>
2424
<executions>
2525
<execution>
2626
<goals>

plugins/maven/example-client/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>io.github.kobylynskyi</groupId>
66
<artifactId>graphql-codegen-maven-plugin-example-client</artifactId>
7-
<version>5.3.0</version>
7+
<version>5.4.0</version>
88
<name>graphql-codegen-maven-plugin-example-client</name>
99

1010
<build>

plugins/maven/example-server/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>io.github.kobylynskyi</groupId>
66
<artifactId>graphql-codegen-maven-plugin-example-server</artifactId>
7-
<version>5.3.0</version>
7+
<version>5.4.0</version>
88
<name>graphql-codegen-maven-plugin-example-server</name>
99

1010
<build>

plugins/maven/graphql-java-codegen-maven-plugin/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>io.github.kobylynskyi</groupId>
55
<artifactId>graphql-codegen-maven-plugin</artifactId>
6-
<version>5.3.1-SNAPSHOT</version>
6+
<version>5.4.0</version>
77
<packaging>maven-plugin</packaging>
88

99
<name>graphql-codegen-maven-plugin</name>
@@ -72,7 +72,7 @@
7272
<version.maven-gpg-plugin>3.0.1</version.maven-gpg-plugin>
7373
<version.maven-shared-utils>3.3.4</version.maven-shared-utils>
7474

75-
<version.graphql-java-codegen>5.3.0</version.graphql-java-codegen>
75+
<version.graphql-java-codegen>5.4.0</version.graphql-java-codegen>
7676
</properties>
7777

7878
<dependencies>

plugins/maven/graphql-java-codegen-maven-plugin/src/main/java/io/github/kobylynskyi/graphql/codegen/GraphQLCodegenMojo.java

+45
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ public class GraphQLCodegenMojo extends AbstractMojo implements GraphQLCodegenCo
200200
@Parameter
201201
private String[] configurationFiles;
202202

203+
@Parameter(defaultValue = MappingConfigConstants.DEFAULT_SUPPORT_UNKNOWN_FIELDS_STRING)
204+
private boolean supportUnknownFields;
205+
206+
@Parameter(defaultValue = MappingConfigConstants.DEFAULT_UNKNOWN_FIELDS_PROPERTY_NAME)
207+
private String unknownFieldsPropertyName;
208+
203209
/**
204210
* The project being built.
205211
*/
@@ -209,6 +215,12 @@ public class GraphQLCodegenMojo extends AbstractMojo implements GraphQLCodegenCo
209215
@Parameter(defaultValue = MappingConfigConstants.DEFAULT_GENERATE_MODEL_OPEN_CLASSES_STRING)
210216
private boolean generateModelOpenClasses;
211217

218+
@Parameter(defaultValue = MappingConfigConstants.DEFAULT_INITIALIZE_NULLABLE_TYPES_STRING)
219+
private boolean initializeNullableTypes;
220+
221+
@Parameter(defaultValue = MappingConfigConstants.DEFAULT_GENERATE_SEALED_INTERFACES_STRING)
222+
private boolean generateSealedInterfaces;
223+
212224
@Override
213225
public void execute() throws MojoExecutionException {
214226
addCompileSourceRootIfConfigured();
@@ -267,6 +279,11 @@ public void execute() throws MojoExecutionException {
267279

268280
mappingConfig.setGeneratedLanguage(generatedLanguage);
269281
mappingConfig.setGenerateModelOpenClasses(isGenerateModelOpenClasses());
282+
mappingConfig.setInitializeNullableTypes(isInitializeNullableTypes());
283+
mappingConfig.setGenerateSealedInterfaces(isGenerateSealedInterfaces());
284+
285+
mappingConfig.setSupportUnknownFields(isSupportUnknownFields());
286+
mappingConfig.setUnknownFieldsPropertyName(getUnknownFieldsPropertyName());
270287

271288
try {
272289
instantiateCodegen(mappingConfig).generate();
@@ -603,6 +620,16 @@ public Boolean isGenerateModelOpenClasses() {
603620
return generateModelOpenClasses;
604621
}
605622

623+
@Override
624+
public Boolean isInitializeNullableTypes() {
625+
return initializeNullableTypes;
626+
}
627+
628+
@Override
629+
public Boolean isGenerateSealedInterfaces() {
630+
return generateSealedInterfaces;
631+
}
632+
606633
public ParentInterfacesConfig getParentInterfaces() {
607634
return parentInterfaces;
608635
}
@@ -611,6 +638,24 @@ public String[] getConfigurationFiles() {
611638
return configurationFiles;
612639
}
613640

641+
@Override
642+
public Boolean isSupportUnknownFields() {
643+
return supportUnknownFields;
644+
}
645+
646+
public void setSupportUnknownFields(boolean supportUnknownFields) {
647+
this.supportUnknownFields = supportUnknownFields;
648+
}
649+
650+
@Override
651+
public String getUnknownFieldsPropertyName() {
652+
return unknownFieldsPropertyName;
653+
}
654+
655+
public void setUnknownFieldsPropertyName(String unknownFieldsPropertyName) {
656+
this.unknownFieldsPropertyName = unknownFieldsPropertyName;
657+
}
658+
614659
private static Map<String, List<String>> convertToListsMap(Map<String, Properties> sourceMap) {
615660
if (sourceMap == null) {
616661
return new HashMap<>();

plugins/sbt/graphql-java-codegen-sbt-plugin/src/main/scala/io/github/dreamylost/graphql/codegen/GraphQLCodegenKeys.scala

+5
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ trait GraphQLCodegenKeys {
124124

125125
val generateModelOpenClasses = settingKey[Boolean]("The class type of the generated model. If true, generate normal classes, else generate case class.")
126126

127+
val generateSealedInterfaces = settingKey[Boolean]("If true, generate sealed interfaces for GraphQL unions and interfaces, else generate normal interfaces.")
128+
127129
val generateJacksonTypeIdResolver = settingKey[Boolean]("Specifies whether generated union interfaces should be annotated with a custom Jackson type id resolver generated in model package")
128130

129131
//for version
@@ -133,4 +135,7 @@ trait GraphQLCodegenKeys {
133135
//some others for sbt
134136
val generateCodegenTargetPath = settingKey[File]("Where to store generated files and add the generated code to the classpath, so that they can be referenced.")
135137

138+
val supportUnknownFields = settingKey[Boolean]("supportUnknownFields")
139+
val unknownFieldsPropertyName = settingKey[String]("unknownFieldsPropertyName")
140+
136141
}

plugins/sbt/graphql-java-codegen-sbt-plugin/src/main/scala/io/github/dreamylost/graphql/codegen/GraphQLCodegenPlugin.scala

+9-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class GraphQLCodegenPlugin(configuration: Configuration, private[codegen] val co
7171
graphqlJavaCodegenVersion := None,
7272
// suffix/prefix/strategies:
7373
generateModelOpenClasses := MappingConfigConstants.DEFAULT_GENERATE_MODEL_OPEN_CLASSES,
74+
generateSealedInterfaces := MappingConfigConstants.DEFAULT_GENERATE_SEALED_INTERFACES,
7475
generatedLanguage := MappingConfigConstants.DEFAULT_GENERATED_LANGUAGE,
7576
apiNamePrefix := None,
7677
apiNameSuffix := MappingConfigConstants.DEFAULT_RESOLVER_SUFFIX,
@@ -116,7 +117,10 @@ class GraphQLCodegenPlugin(configuration: Configuration, private[codegen] val co
116117
// parent interfaces configs:
117118
parentInterfaces := parentInterfacesConfig,
118119
generateAllMethodInProjection := MappingConfigConstants.DEFAULT_GENERATE_ALL_METHOD,
119-
responseProjectionMaxDepth := MappingConfigConstants.DEFAULT_RESPONSE_PROJECTION_MAX_DEPTH
120+
responseProjectionMaxDepth := MappingConfigConstants.DEFAULT_RESPONSE_PROJECTION_MAX_DEPTH,
121+
122+
supportUnknownFields := MappingConfigConstants.DEFAULT_SUPPORT_UNKNOWN_FIELDS,
123+
unknownFieldsPropertyName := MappingConfigConstants.DEFAULT_UNKNOWN_FIELDS_PROPERTY_NAME
120124
)
121125

122126
private def getMappingConfig(): Def.Initialize[MappingConfig] = Def.setting {
@@ -171,6 +175,10 @@ class GraphQLCodegenPlugin(configuration: Configuration, private[codegen] val co
171175
mappingConfig.setGeneratedLanguage((generatedLanguage in GraphQLCodegenConfig).value)
172176
mappingConfig.setGenerateModelOpenClasses((generateModelOpenClasses in GraphQLCodegenConfig).value)
173177
mappingConfig.setGenerateJacksonTypeIdResolver((generateJacksonTypeIdResolver in GraphQLCodegenConfig).value);
178+
179+
mappingConfig.setSupportUnknownFields((supportUnknownFields in GraphQLCodegenConfig).value)
180+
mappingConfig.setUnknownFieldsPropertyName((unknownFieldsPropertyName in GraphQLCodegenConfig).value)
181+
174182
mappingConfig
175183
}
176184

Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
addSbtPlugin("io.github.jxnu-liguobin" % "graphql-codegen-sbt-plugin" % "5.3.0")
1+
addSbtPlugin("io.github.jxnu-liguobin" % "graphql-codegen-sbt-plugin" % "5.4.0")
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version in ThisBuild := "5.3.0"
1+
version in ThisBuild := "5.4.0"
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
addSbtPlugin("io.github.jxnu-liguobin" % "graphql-codegen-sbt-plugin" % "5.3.0")
1+
addSbtPlugin("io.github.jxnu-liguobin" % "graphql-codegen-sbt-plugin" % "5.4.0")
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version in ThisBuild := "5.3.0"
1+
version in ThisBuild := "5.4.0"

plugins/sbt/graphql-java-codegen-sbt-plugin/src/sbt-test/graphql-codegen-sbt-plugin/simple/project/plugins.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
sys.props.get("plugin.version").orElse(Some("5.3.0")) match {
1+
sys.props.get("plugin.version").orElse(Some("5.4.0")) match {
22
case Some(x) => addSbtPlugin("io.github.jxnu-liguobin" % "graphql-codegen-sbt-plugin" % x)
33
case _ => sys.error("""|The system property 'plugin.version' is not defined.
44
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version in ThisBuild := "5.3.0"
1+
version in ThisBuild := "5.4.0"

0 commit comments

Comments
 (0)