-
-
Notifications
You must be signed in to change notification settings - Fork 114
Upstream/985 combine multiple response projections #1032
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
Closed
jxnu-liguobin
wants to merge
2
commits into
kobylynskyi:985-combine-multiple-response-projections
from
jxnu-liguobin:upstream/985-combine-multiple-response-projections
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -44,10 +44,10 @@ void init() { | |
| mappingConfig.setGenerateEqualsAndHashCode(true); | ||
| } | ||
|
|
||
| @AfterEach | ||
| void cleanup() { | ||
| Utils.deleteDir(outputBuildDir); | ||
| } | ||
| // @AfterEach | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jxnu-liguobin can you please revert this |
||
| // void cleanup() { | ||
| // Utils.deleteDir(outputBuildDir); | ||
| // } | ||
|
|
||
| @Test | ||
| void generate_MultipleInterfacesPerType() throws Exception { | ||
|
|
||
51 changes: 51 additions & 0 deletions
51
src/test/java/com/kobylynskyi/graphql/codegen/kotlin/GraphQLCodegenVerifyCompileTest.java
This file contains hidden or 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,51 @@ | ||
| package com.kobylynskyi.graphql.codegen.kotlin; | ||
|
|
||
| import com.kobylynskyi.graphql.codegen.TestUtils; | ||
| import com.kobylynskyi.graphql.codegen.model.GeneratedLanguage; | ||
| import com.kobylynskyi.graphql.codegen.model.MappingConfig; | ||
| 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 java.util.Collections.singletonList; | ||
|
|
||
| class GraphQLCodegenVerifyCompileTest { | ||
|
|
||
| private final String path = "src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass"; | ||
| private final File outputBuildDir = new File(path); | ||
|
|
||
| private MappingConfig mappingConfig; | ||
|
|
||
| @BeforeEach | ||
| void init() { | ||
| mappingConfig = new MappingConfig(); | ||
| mappingConfig.setGenerateParameterizedFieldsResolvers(true); | ||
| mappingConfig.setPackageName("com.github.graphql"); | ||
| mappingConfig.setGeneratedLanguage(GeneratedLanguage.KOTLIN); | ||
| mappingConfig.setGenerateToString(true); | ||
| mappingConfig.setGenerateApis(true); | ||
| mappingConfig.setGenerateClient(true); | ||
| mappingConfig.setAddGeneratedAnnotation(false); | ||
| mappingConfig.setGenerateEqualsAndHashCode(true); | ||
| mappingConfig.setModelValidationAnnotation(""); | ||
| } | ||
|
|
||
| @Test | ||
| void generate_CheckFiles_Kotlin_Files_Compile_Pass() throws Exception { | ||
| mappingConfig.setPackageName(""); | ||
| generate("src/test/resources/schemas/test.graphqls"); | ||
|
|
||
| File outputJavaClassesDir = new File(path); | ||
| File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles()); | ||
| assert files.length > 0; | ||
| } | ||
|
|
||
| private void generate(String path) throws IOException { | ||
| new KotlinGraphQLCodegen(singletonList(path), outputBuildDir, mappingConfig, | ||
| TestUtils.getStaticGeneratedInfo()).generate(); | ||
| } | ||
|
|
||
| } |
55 changes: 55 additions & 0 deletions
55
...st/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/CreateEventMutationRequest.kt
This file contains hidden or 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,55 @@ | ||
| import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation | ||
| import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperationRequest | ||
| import java.util.Objects | ||
|
|
||
| /** | ||
| * Create a new event. | ||
| */ | ||
| open class CreateEventMutationRequest(private val alias: String?) : GraphQLOperationRequest { | ||
|
|
||
| companion object { | ||
| const val OPERATION_NAME: String = "createEvent" | ||
| val OPERATION_TYPE: GraphQLOperation = GraphQLOperation.MUTATION | ||
| } | ||
|
|
||
| private val input: MutableMap<String, Any?> = LinkedHashMap() | ||
| private val useObjectMapperForInputSerialization: MutableSet<String> = HashSet() | ||
|
|
||
| constructor(): this(null) | ||
|
|
||
| fun setCategoryId(categoryId: String) { | ||
| this.input["categoryId"] = categoryId | ||
| } | ||
|
|
||
| fun setCreatedBy(createdBy: String?) { | ||
| this.input["createdBy"] = createdBy | ||
| } | ||
|
|
||
| override fun getOperationType(): GraphQLOperation = OPERATION_TYPE | ||
|
|
||
| override fun getOperationName(): String = OPERATION_NAME | ||
|
|
||
| override fun getAlias(): String? = alias ?: OPERATION_NAME | ||
|
|
||
| override fun getInput(): MutableMap<String, Any?> = input | ||
|
|
||
| override fun getUseObjectMapperForInputSerialization(): MutableSet<String> = useObjectMapperForInputSerialization | ||
|
|
||
| override fun equals(other: Any?): Boolean { | ||
| if (this === other) { | ||
| return true | ||
| } | ||
| if (other == null || javaClass != other.javaClass) { | ||
| return false | ||
| } | ||
| val that = other as CreateEventMutationRequest | ||
| return Objects.equals(operationType, that.operationType) && | ||
| Objects.equals(operationName, that.operationName) && | ||
| Objects.equals(input, that.input) | ||
| } | ||
|
|
||
| override fun hashCode(): Int = Objects.hash(operationType, operationName, input) | ||
|
|
||
| override fun toString(): String = Objects.toString(input) | ||
|
|
||
| } |
13 changes: 13 additions & 0 deletions
13
...t/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/CreateEventMutationResolver.kt
This file contains hidden or 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,13 @@ | ||
|
|
||
| /** | ||
| * Create a new event. | ||
| */ | ||
| interface CreateEventMutationResolver { | ||
|
|
||
| /** | ||
| * Create a new event. | ||
| */ | ||
| @Throws(Exception::class) | ||
| fun createEvent(categoryId: String, createdBy: String?): Event | ||
|
|
||
| } |
19 changes: 19 additions & 0 deletions
19
...t/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/CreateEventMutationResponse.kt
This file contains hidden or 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,19 @@ | ||
| import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResult | ||
|
|
||
| /** | ||
| * Create a new event. | ||
| */ | ||
| open class CreateEventMutationResponse : GraphQLResult<MutableMap<String, Event>>() { | ||
|
|
||
| companion object { | ||
| const val OPERATION_NAME: String = "createEvent" | ||
| } | ||
|
|
||
| /** | ||
| * Create a new event. | ||
| */ | ||
| fun createEvent(): Event { | ||
| val data: MutableMap<String, Event> = super.getData() | ||
| return data.getValue(OPERATION_NAME) | ||
| } | ||
| } |
47 changes: 47 additions & 0 deletions
47
src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/Event.kt
This file contains hidden or 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,47 @@ | ||
| import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLRequestSerializer | ||
| import java.util.StringJoiner | ||
|
|
||
| /** | ||
| * An event that describes a thing that happens | ||
| */ | ||
| data class Event( | ||
| val id: String?, | ||
| val categoryId: String?, | ||
| val properties: List<EventProperty?>?, | ||
| val status: EventStatus?, | ||
| val createdBy: String?, | ||
| val createdDateTime: String?, | ||
| val active: Boolean?, | ||
| val rating: Int? | ||
| ) { | ||
|
|
||
| // In the future, it maybe change. | ||
| override fun toString(): String { | ||
| val joiner = StringJoiner(", ", "{ ", " }") | ||
| if (id != null) { | ||
| joiner.add("id: " + GraphQLRequestSerializer.getEntry(id)) | ||
| } | ||
| if (categoryId != null) { | ||
| joiner.add("categoryId: " + GraphQLRequestSerializer.getEntry(categoryId)) | ||
| } | ||
| if (properties != null) { | ||
| joiner.add("properties: " + GraphQLRequestSerializer.getEntry(properties)) | ||
| } | ||
| if (status != null) { | ||
| joiner.add("status: " + GraphQLRequestSerializer.getEntry(status)) | ||
| } | ||
| if (createdBy != null) { | ||
| joiner.add("createdBy: " + GraphQLRequestSerializer.getEntry(createdBy)) | ||
| } | ||
| if (createdDateTime != null) { | ||
| joiner.add("createdDateTime: " + GraphQLRequestSerializer.getEntry(createdDateTime)) | ||
| } | ||
| if (active != null) { | ||
| joiner.add("active: " + GraphQLRequestSerializer.getEntry(active)) | ||
| } | ||
| if (rating != null) { | ||
| joiner.add("rating: " + GraphQLRequestSerializer.getEntry(rating)) | ||
| } | ||
| return joiner.toString() | ||
| } | ||
| } |
51 changes: 51 additions & 0 deletions
51
src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventByIdQueryRequest.kt
This file contains hidden or 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,51 @@ | ||
| import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation | ||
| import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperationRequest | ||
| import java.util.Objects | ||
|
|
||
| /** | ||
| * Single event by ID. | ||
| */ | ||
| open class EventByIdQueryRequest(private val alias: String?) : GraphQLOperationRequest { | ||
|
|
||
| companion object { | ||
| const val OPERATION_NAME: String = "eventById" | ||
| val OPERATION_TYPE: GraphQLOperation = GraphQLOperation.QUERY | ||
| } | ||
|
|
||
| private val input: MutableMap<String, Any?> = LinkedHashMap() | ||
| private val useObjectMapperForInputSerialization: MutableSet<String> = HashSet() | ||
|
|
||
| constructor(): this(null) | ||
|
|
||
| fun setId(id: String) { | ||
| this.input["id"] = id | ||
| } | ||
|
|
||
| override fun getOperationType(): GraphQLOperation = OPERATION_TYPE | ||
|
|
||
| override fun getOperationName(): String = OPERATION_NAME | ||
|
|
||
| override fun getAlias(): String? = alias ?: OPERATION_NAME | ||
|
|
||
| override fun getInput(): MutableMap<String, Any?> = input | ||
|
|
||
| override fun getUseObjectMapperForInputSerialization(): MutableSet<String> = useObjectMapperForInputSerialization | ||
|
|
||
| override fun equals(other: Any?): Boolean { | ||
| if (this === other) { | ||
| return true | ||
| } | ||
| if (other == null || javaClass != other.javaClass) { | ||
| return false | ||
| } | ||
| val that = other as EventByIdQueryRequest | ||
| return Objects.equals(operationType, that.operationType) && | ||
| Objects.equals(operationName, that.operationName) && | ||
| Objects.equals(input, that.input) | ||
| } | ||
|
|
||
| override fun hashCode(): Int = Objects.hash(operationType, operationName, input) | ||
|
|
||
| override fun toString(): String = Objects.toString(input) | ||
|
|
||
| } |
13 changes: 13 additions & 0 deletions
13
src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventByIdQueryResolver.kt
This file contains hidden or 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,13 @@ | ||
|
|
||
| /** | ||
| * Single event by ID. | ||
| */ | ||
| interface EventByIdQueryResolver { | ||
|
|
||
| /** | ||
| * Single event by ID. | ||
| */ | ||
| @Throws(Exception::class) | ||
| fun eventById(id: String): Event | ||
|
|
||
| } |
19 changes: 19 additions & 0 deletions
19
src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventByIdQueryResponse.kt
This file contains hidden or 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,19 @@ | ||
| import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResult | ||
|
|
||
| /** | ||
| * Single event by ID. | ||
| */ | ||
| open class EventByIdQueryResponse : GraphQLResult<MutableMap<String, Event>>() { | ||
|
|
||
| companion object { | ||
| const val OPERATION_NAME: String = "eventById" | ||
| } | ||
|
|
||
| /** | ||
| * Single event by ID. | ||
| */ | ||
| fun eventById(): Event { | ||
| val data: MutableMap<String, Event> = super.getData() | ||
| return data.getValue(OPERATION_NAME) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jxnu-liguobin why are we adding this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jxnu-liguobin I would like not to add kotlin code and dependencies to the main project. instead, please add this as part of example kotlin plugin which we already have.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. We can update the sample synchronously when major changes occur.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The template changes in this PR have been verified, closed it