Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

customTypesMapping and directiveAnnotationsMapping replace enumeration values when used together #1298

Merged
merged 3 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
id "java-library"
id "signing"
id "maven-publish"
id "org.sonarqube" version "4.3.0.3225"
id "org.sonarqube" version "4.0.0.2929"
}

def graphqlCodegenVersion = '5.8.1-SNAPSHOT' // This variable used in the automatic release process
Expand All @@ -20,7 +20,7 @@ repositories {

dependencies {
compileOnly "org.freemarker:freemarker:2.3.32"
compileOnly "com.graphql-java:graphql-java:21.0"
compileOnly "com.graphql-java:graphql-java:20.2"
compileOnly "com.fasterxml.jackson.core:jackson-databind:2.15.2"
compileOnly "com.typesafe:config:1.4.2"

Expand Down
2 changes: 1 addition & 1 deletion plugins/gradle/example-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mainClassName = "io.github.kobylynskyi.product.Application"

dependencies {
implementation "org.springframework.boot:spring-boot-starter-web:2.7.14"
implementation "org.springframework.boot:spring-boot-starter-data-mongodb:2.7.13"
implementation "org.springframework.boot:spring-boot-starter-data-mongodb:2.7.14"

implementation "com.graphql-java-kickstart:graphql-spring-boot-starter:11.0.0"
implementation "com.graphql-java-kickstart:graphiql-spring-boot-starter:11.1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies {
implementation "io.github.kobylynskyi:graphql-java-codegen:${version}"

implementation "org.freemarker:freemarker:2.3.32"
implementation "com.graphql-java:graphql-java:21.0"
implementation "com.graphql-java:graphql-java:20.2"
implementation "com.fasterxml.jackson.core:jackson-databind:2.15.2"
implementation "com.typesafe:config:1.4.2"

Expand Down
2 changes: 1 addition & 1 deletion plugins/maven/example-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<version>2.7.13</version>
<version>2.7.14</version>
</dependency>

<dependency>
Expand Down
4 changes: 2 additions & 2 deletions plugins/maven/example-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.7.13</version>
<version>2.7.14</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<version>2.7.13</version>
<version>2.7.14</version>
</dependency>

<dependency>
Expand Down
6 changes: 3 additions & 3 deletions plugins/maven/graphql-java-codegen-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
</ciManagement>

<properties>
<version.maven-plugin-api>3.9.3</version.maven-plugin-api>
<version.maven-core>3.9.3</version.maven-core>
<version.maven-plugin-api>3.9.4</version.maven-plugin-api>
<version.maven-core>3.9.4</version.maven-core>
<version.maven-plugin-annotations>3.9.0</version.maven-plugin-annotations>
<version.maven-plugin-plugin>3.9.0</version.maven-plugin-plugin>
<version.maven-compiler-plugin>3.11.0</version.maven-compiler-plugin>
Expand Down Expand Up @@ -121,7 +121,7 @@
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java</artifactId>
<version>21.0</version>
<version>20.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -122,6 +123,11 @@ public String map(MappingContext mappingContext, Value<?> value, Type<?> graphQL

private String mapEnum(MappingContext mappingContext, EnumValue value, Type<?> graphQLType) {
if (graphQLType == null) {
Map<String, String> customTypesMapping = mappingContext.getCustomTypesMapping();
if (customTypesMapping.containsKey(value.getName())) {
return customTypesMapping.get(value.getName());
}

return value.getName();
}
if (graphQLType instanceof TypeName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,21 @@ void generate_CustomAnnotationMappings_FieldType() throws Exception {
" val createdDateTime: org.joda.time.DateTime?");
}

@Test
void generate_CustomAnnotationMappings_With_Annotations() throws Exception {
mappingConfig.setCustomTypesMapping(new HashMap<>(
singletonMap("CAMS", "com.intuit.identity.manage.enum.CamsGroup::class")));
mappingConfig.setDirectiveAnnotationsMapping(new HashMap<>(singletonMap("NotNull",
singletonList("@javax.validation.constraints.NotNull(message = {{message}}, groups = {{groups}})"))));

generate("src/test/resources/schemas/kt/customTypesMapping-directive.graphqls");

File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
assertFileContainsElements(files, "TrustAccountInput.kt",
"@field:javax.validation.constraints.NotNull(message = \"test\", " +
"groups = com.intuit.identity.manage.enum.CamsGroup::class)");
}

private void generate(String path) throws IOException {
new KotlinGraphQLCodegen(singletonList(path), outputBuildDir, mappingConfig,
TestUtils.getStaticGeneratedInfo(mappingConfig)).generate();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
directive @NotNull(message : String, groups: ValidationGroup) on INPUT_FIELD_DEFINITION

schema {
query: Query
}

input TrustAccountInput
{
accountId: String! @NotNull(message: "test", groups: CAMS)
}