|
12 | 12 | import java.io.File; |
13 | 13 | import java.io.IOException; |
14 | 14 | import java.nio.file.Paths; |
| 15 | +import java.util.HashMap; |
15 | 16 | import java.util.Objects; |
16 | 17 |
|
| 18 | +import static com.kobylynskyi.graphql.codegen.TestUtils.assertFileContainsElements; |
17 | 19 | import static com.kobylynskyi.graphql.codegen.TestUtils.assertSameTrimmedContent; |
18 | 20 | import static com.kobylynskyi.graphql.codegen.TestUtils.getFileByName; |
19 | 21 |
|
@@ -98,6 +100,26 @@ void generate_OptionalFieldInInterfaceAndMandatoryInType() throws Exception { |
98 | 100 | getFileByName(files, "TypeWithMandatoryField.java")); |
99 | 101 | } |
100 | 102 |
|
| 103 | + /** |
| 104 | + * @see <a href="https://github.com/kobylynskyi/graphql-java-codegen/issues/1023">Related issue in GitHub</a> |
| 105 | + */ |
| 106 | + @Test |
| 107 | + void generate_ObjectsInsteadOfPrimitives() throws Exception { |
| 108 | + mappingConfig.setCustomTypesMapping(new HashMap<String, String>() {{ |
| 109 | + put("Int!", "Integer"); |
| 110 | + }}); |
| 111 | + schemaFinder.setIncludePattern("optional-vs-mandatory-types.graphqls"); |
| 112 | + |
| 113 | + generate(); |
| 114 | + |
| 115 | + File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles()); |
| 116 | + |
| 117 | + // Integer is generated instead of int |
| 118 | + assertFileContainsElements(files, "TypeWithMandatoryField.java", |
| 119 | + " @javax.validation.constraints.NotNull", |
| 120 | + " private Integer test;"); |
| 121 | + } |
| 122 | + |
101 | 123 | private void generate() throws IOException { |
102 | 124 | new JavaGraphQLCodegen(schemaFinder.findSchemas(), outputBuildDir, mappingConfig, |
103 | 125 | TestUtils.getStaticGeneratedInfo(mappingConfig)).generate(); |
|
0 commit comments