-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to render Kotlin functions with suspend modifier
- Loading branch information
Showing
16 changed files
with
165 additions
and
2 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
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
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
62 changes: 62 additions & 0 deletions
62
src/test/java/com/kobylynskyi/graphql/codegen/kotlin/GraphQLCodegenSuspendTest.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,62 @@ | ||
package com.kobylynskyi.graphql.codegen.kotlin; | ||
|
||
import com.kobylynskyi.graphql.codegen.MaxQueryTokensExtension; | ||
import com.kobylynskyi.graphql.codegen.TestUtils; | ||
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 org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import java.io.File; | ||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
import static com.kobylynskyi.graphql.codegen.TestUtils.assertSameTrimmedContent; | ||
import static java.util.Arrays.asList; | ||
import static java.util.Collections.singletonList; | ||
import static java.util.stream.Collectors.toSet; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@ExtendWith(MaxQueryTokensExtension.class) | ||
class GraphQLCodegenSuspendTest { | ||
|
||
private final File outputBuildDir = new File("build/generated"); | ||
private final MappingConfig mappingConfig = new MappingConfig(); | ||
|
||
@BeforeEach | ||
void init() { | ||
mappingConfig.setGenerateApisWithSuspendFunctions(true); | ||
mappingConfig.setGeneratedLanguage(GeneratedLanguage.KOTLIN); | ||
} | ||
|
||
@AfterEach | ||
void cleanup() { | ||
Utils.deleteDir(outputBuildDir); | ||
} | ||
|
||
@Test | ||
void generate_ApiWithSuspendFunction() throws Exception { | ||
new KotlinGraphQLCodegen( | ||
singletonList("src/test/resources/schemas/kt/suspend.graphqls"), | ||
outputBuildDir, mappingConfig, TestUtils.getStaticGeneratedInfo(mappingConfig) | ||
).generate(); | ||
|
||
File[] files = Objects.requireNonNull(outputBuildDir.listFiles()); | ||
|
||
Set<String> generatedFileNames = Arrays.stream(files).map(File::getName).collect(toSet()); | ||
assertEquals(new HashSet<>(asList("FriendsQueryResolver.kt", "QueryResolver.kt", "Friend.kt")), | ||
generatedFileNames); | ||
|
||
for (File file : files) { | ||
assertSameTrimmedContent( | ||
new File(String.format("src/test/resources/expected-classes/kt/suspend/%s.txt", file.getName())), | ||
file); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.