Skip to content

Commit e6f58ec

Browse files
jxnu-liguobinkobylynskyidependabot[bot]
authored
customTypesMapping and directiveAnnotationsMapping replace enumeration values when used together (#1298)
* test on kotlin is ok * fix style * Pull all changes from the latest main (#1303) * Revert sonar version back to 4.0.0.2929 * Revert graphql-java back to 20.2 (#1302) * Bump org.apache.maven:maven-core (#1301) Bumps [org.apache.maven:maven-core](https://github.com/apache/maven) from 3.9.3 to 3.9.4. - [Release notes](https://github.com/apache/maven/releases) - [Commits](apache/maven@maven-3.9.3...maven-3.9.4) --- updated-dependencies: - dependency-name: org.apache.maven:maven-core dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump org.apache.maven:maven-plugin-api (#1300) Bumps [org.apache.maven:maven-plugin-api](https://github.com/apache/maven) from 3.9.3 to 3.9.4. - [Release notes](https://github.com/apache/maven/releases) - [Commits](apache/maven@maven-3.9.3...maven-3.9.4) --- updated-dependencies: - dependency-name: org.apache.maven:maven-plugin-api dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump org.springframework.boot:spring-boot-starter-data-mongodb (#1296) Bumps [org.springframework.boot:spring-boot-starter-data-mongodb](https://github.com/spring-projects/spring-boot) from 2.7.13 to 2.7.14. - [Release notes](https://github.com/spring-projects/spring-boot/releases) - [Commits](spring-projects/spring-boot@v2.7.13...v2.7.14) --- updated-dependencies: - dependency-name: org.springframework.boot:spring-boot-starter-data-mongodb dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump org.springframework.boot:spring-boot-starter-data-mongodb (#1295) Bumps [org.springframework.boot:spring-boot-starter-data-mongodb](https://github.com/spring-projects/spring-boot) from 2.7.13 to 2.7.14. - [Release notes](https://github.com/spring-projects/spring-boot/releases) - [Commits](spring-projects/spring-boot@v2.7.13...v2.7.14) --- updated-dependencies: - dependency-name: org.springframework.boot:spring-boot-starter-data-mongodb dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump org.springframework.boot:spring-boot-starter-data-mongodb (#1292) Bumps [org.springframework.boot:spring-boot-starter-data-mongodb](https://github.com/spring-projects/spring-boot) from 2.7.13 to 2.7.14. - [Release notes](https://github.com/spring-projects/spring-boot/releases) - [Commits](spring-projects/spring-boot@v2.7.13...v2.7.14) --- updated-dependencies: - dependency-name: org.springframework.boot:spring-boot-starter-data-mongodb dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump org.springframework.boot:spring-boot-starter-web (#1291) Bumps [org.springframework.boot:spring-boot-starter-web](https://github.com/spring-projects/spring-boot) from 2.7.13 to 2.7.14. - [Release notes](https://github.com/spring-projects/spring-boot/releases) - [Commits](spring-projects/spring-boot@v2.7.13...v2.7.14) --- updated-dependencies: - dependency-name: org.springframework.boot:spring-boot-starter-web dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Bogdan Kobylynskyi <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent 37ffc68 commit e6f58ec

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/main/java/com/kobylynskyi/graphql/codegen/mapper/ValueMapper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.util.Collections;
1919
import java.util.List;
20+
import java.util.Map;
2021
import java.util.stream.Collectors;
2122

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

123124
private String mapEnum(MappingContext mappingContext, EnumValue value, Type<?> graphQLType) {
124125
if (graphQLType == null) {
126+
Map<String, String> customTypesMapping = mappingContext.getCustomTypesMapping();
127+
if (customTypesMapping.containsKey(value.getName())) {
128+
return customTypesMapping.get(value.getName());
129+
}
130+
125131
return value.getName();
126132
}
127133
if (graphQLType instanceof TypeName) {

src/test/java/com/kobylynskyi/graphql/codegen/kotlin/GraphQLCodegenAnnotationsTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,21 @@ void generate_CustomAnnotationMappings_FieldType() throws Exception {
119119
" val createdDateTime: org.joda.time.DateTime?");
120120
}
121121

122+
@Test
123+
void generate_CustomAnnotationMappings_With_Annotations() throws Exception {
124+
mappingConfig.setCustomTypesMapping(new HashMap<>(
125+
singletonMap("CAMS", "com.intuit.identity.manage.enum.CamsGroup::class")));
126+
mappingConfig.setDirectiveAnnotationsMapping(new HashMap<>(singletonMap("NotNull",
127+
singletonList("@javax.validation.constraints.NotNull(message = {{message}}, groups = {{groups}})"))));
128+
129+
generate("src/test/resources/schemas/kt/customTypesMapping-directive.graphqls");
130+
131+
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
132+
assertFileContainsElements(files, "TrustAccountInput.kt",
133+
"@field:javax.validation.constraints.NotNull(message = \"test\", " +
134+
"groups = com.intuit.identity.manage.enum.CamsGroup::class)");
135+
}
136+
122137
private void generate(String path) throws IOException {
123138
new KotlinGraphQLCodegen(singletonList(path), outputBuildDir, mappingConfig,
124139
TestUtils.getStaticGeneratedInfo(mappingConfig)).generate();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
directive @NotNull(message : String, groups: ValidationGroup) on INPUT_FIELD_DEFINITION
2+
3+
schema {
4+
query: Query
5+
}
6+
7+
input TrustAccountInput
8+
{
9+
accountId: String! @NotNull(message: "test", groups: CAMS)
10+
}

0 commit comments

Comments
 (0)