-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support {TYPE} placeholder in apiReturnType and apiReturnListType #1167…
… (#1200)
- Loading branch information
1 parent
a3e7551
commit 8d9d0de
Showing
7 changed files
with
408 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
src/test/java/com/kobylynskyi/graphql/codegen/GraphQLCodegenApiReturnTypeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package com.kobylynskyi.graphql.codegen; | ||
|
||
import com.kobylynskyi.graphql.codegen.java.JavaGraphQLCodegen; | ||
import com.kobylynskyi.graphql.codegen.model.GeneratedLanguage; | ||
import com.kobylynskyi.graphql.codegen.model.MappingConfig; | ||
import com.kobylynskyi.graphql.codegen.utils.Utils; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
import static com.kobylynskyi.graphql.codegen.TestUtils.assertFileContainsElements; | ||
import static java.util.Collections.singletonList; | ||
|
||
class GraphQLCodegenApiReturnTypeTest { | ||
|
||
private final File outputBuildDir = new File("build/generated"); | ||
private final File outputJavaClassesDir = new File("build/generated/com/kobylynskyi/graphql/test1"); | ||
|
||
private MappingConfig mappingConfig; | ||
|
||
@BeforeEach | ||
void init() { | ||
mappingConfig = new MappingConfig(); | ||
mappingConfig.setPackageName("com.kobylynskyi.graphql.test1"); | ||
mappingConfig.setGeneratedLanguage(GeneratedLanguage.JAVA); | ||
} | ||
|
||
@AfterEach | ||
void cleanup() { | ||
Utils.deleteDir(outputBuildDir); | ||
} | ||
|
||
@Test | ||
void generate_ApiReturnType_WithPlaceHolder() throws Exception { | ||
mappingConfig.setApiReturnType( | ||
"java.util.concurrent.CompletionStage<graphql.execution.DataFetcherResult<{{TYPE}}>>" | ||
); | ||
|
||
generate("src/test/resources/schemas/test.graphqls"); | ||
|
||
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles()); | ||
|
||
String requireChildText = getChildText( | ||
"java.util.concurrent.CompletionStage<graphql.execution.DataFetcherResult" + | ||
"<java.util.List<EventProperty>>>" | ||
); | ||
assertFileContainsElements( | ||
files, | ||
"EventPropertyResolver.java", | ||
requireChildText | ||
); | ||
|
||
String requireParentText = getParentText( | ||
"java.util.concurrent.CompletionStage<graphql.execution.DataFetcherResult<Event>>" | ||
); | ||
assertFileContainsElements(files, "EventPropertyResolver.java", | ||
requireParentText | ||
); | ||
} | ||
|
||
@Test | ||
void generate_ApiReturnType_And_ApiReturnListType_WithPlaceHolder() throws Exception { | ||
mappingConfig.setApiReturnType( | ||
"java.util.concurrent.CompletionStage<graphql.execution.DataFetcherResult<{{TYPE}}>>" | ||
); | ||
mappingConfig.setApiReturnListType( | ||
"reactor.core.publisher.Mono<graphql.execution.DataFetcherResult<{{TYPE}}>>" | ||
); | ||
|
||
generate("src/test/resources/schemas/test.graphqls"); | ||
|
||
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles()); | ||
|
||
assertFileContainsElements( | ||
files, | ||
"EventPropertyResolver.java", | ||
getChildText( | ||
"reactor.core.publisher.Mono<graphql.execution.DataFetcherResult<EventProperty>>" | ||
) | ||
); | ||
|
||
assertFileContainsElements( | ||
files, | ||
"EventPropertyResolver.java", | ||
getParentText( | ||
"java.util.concurrent.CompletionStage<graphql.execution.DataFetcherResult<Event>>" | ||
) | ||
); | ||
} | ||
|
||
private String getChildText(String returnType) { | ||
return returnType + " child(EventProperty eventProperty, Integer first, Integer last) throws Exception;"; | ||
} | ||
|
||
private String getParentText(String returnType) { | ||
return returnType + | ||
" parent(EventProperty eventProperty, EventStatus withStatus, String createdAfter) throws Exception;"; | ||
} | ||
|
||
private void generate(String path) throws IOException { | ||
new JavaGraphQLCodegen(singletonList(path), outputBuildDir, mappingConfig, | ||
TestUtils.getStaticGeneratedInfo(mappingConfig)).generate(); | ||
} | ||
|
||
} |
Oops, something went wrong.