diff --git a/build.gradle b/build.gradle index 7b6595024..bb51e50c4 100644 --- a/build.gradle +++ b/build.gradle @@ -7,6 +7,7 @@ plugins { id "signing" id "maven-publish" id "org.sonarqube" version "3.2.0" + id 'org.jetbrains.kotlin.jvm' version '1.8.20-Beta' } def graphqlCodegenVersion = '5.5.1-SNAPSHOT' // This variable used in the automatic release process @@ -29,6 +30,10 @@ dependencies { testImplementation "org.junit.jupiter:junit-jupiter-params:5.7.1" testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.7.1" testImplementation "org.hamcrest:java-hamcrest:2.0.0.0" + testImplementation "org.scala-lang:scala-library:2.13.10" + testImplementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" + testImplementation "com.fasterxml.jackson.module:jackson-module-scala_2.13:2.13.3" + } test.useJUnitPlatform() @@ -156,3 +161,13 @@ if (project.hasProperty("signing.keyId")) { sign publishing.publications.mavenJava } } +compileKotlin { + kotlinOptions { + jvmTarget = "1.8" + } +} +compileTestKotlin { + kotlinOptions { + jvmTarget = "1.8" + } +} diff --git a/src/main/resources/templates/kotlin-lang/parametrized_input.ftl b/src/main/resources/templates/kotlin-lang/parametrized_input.ftl index b4811b36a..6057672bd 100755 --- a/src/main/resources/templates/kotlin-lang/parametrized_input.ftl +++ b/src/main/resources/templates/kotlin-lang/parametrized_input.ftl @@ -39,13 +39,16 @@ data class ${className}( ) : GraphQLParametrizedInput { override fun deepCopy(): ${className} { - val parametrizedInput = ${className}() <#if fields?has_content> + return ${className}( <#list fields as field> - parametrizedInput.${field.name}(this.${field.name}) + this.${field.name}<#if field_has_next>, + ) + <#else> + return ${className}() - return parametrizedInput + } override fun toString(): String { diff --git a/src/main/resources/templates/scala-lang/parametrized_input.ftl b/src/main/resources/templates/scala-lang/parametrized_input.ftl index 8ed75b545..c6fd907a0 100644 --- a/src/main/resources/templates/scala-lang/parametrized_input.ftl +++ b/src/main/resources/templates/scala-lang/parametrized_input.ftl @@ -54,14 +54,16 @@ case class ${className}( ) extends GraphQLParametrizedInput { - override def deepCopy(): ${className} { - val parametrizedInput = ${className}() + override def deepCopy(): ${className} = { <#if fields?has_content> + ${className}( <#list fields as field> - parametrizedInput.${field.name}(this.${field.name}) + this.${field.name}<#if field_has_next>, + ) + <#else> + ${className}() - parametrizedInput } override def toString(): String = {<#--There is no Option[Seq[T]], Format is not supported in the generated code, so it is very difficult to write template for this format.--> diff --git a/src/main/resources/templates/scala-lang/response_projection.ftl b/src/main/resources/templates/scala-lang/response_projection.ftl index 96fbb165e..42e4c3a14 100644 --- a/src/main/resources/templates/scala-lang/response_projection.ftl +++ b/src/main/resources/templates/scala-lang/response_projection.ftl @@ -33,7 +33,7 @@ class ${className}() extends GraphQLResponseProjection() { def this(projection: ${className}) = { this() if (projection != null) { - for (field <- projection.fields.values) { + for (field <- projection.fields.values.asScala) { add$(field) } } @@ -44,7 +44,7 @@ class ${className}() extends GraphQLResponseProjection() { if (projections != null) { for (projection <- projections) { if (projection != null) { - for (field <- projection.fields.values) { + for (field <- projection.fields.values.asScala) { add$(field) } } @@ -108,7 +108,7 @@ class ${className}() extends GraphQLResponseProjection() { - override def deepCopy$(): ${className} = ${className}(this) + override def deepCopy$(): ${className} = new ${className}(this) <#if equalsAndHashCode> override def equals(obj: Any): Boolean = { diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/GraphQLCodegenGitHubTest.java b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/GraphQLCodegenGitHubTest.java index c3d92c1ab..9b70f69c8 100644 --- a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/GraphQLCodegenGitHubTest.java +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/GraphQLCodegenGitHubTest.java @@ -44,10 +44,10 @@ void init() { mappingConfig.setGenerateEqualsAndHashCode(true); } - @AfterEach - void cleanup() { - Utils.deleteDir(outputBuildDir); - } +// @AfterEach +// void cleanup() { +// Utils.deleteDir(outputBuildDir); +// } @Test void generate_MultipleInterfacesPerType() throws Exception { diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/GraphQLCodegenVerifyCompileTest.java b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/GraphQLCodegenVerifyCompileTest.java new file mode 100644 index 000000000..4e9d0cfd8 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/GraphQLCodegenVerifyCompileTest.java @@ -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(); + } + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/CreateEventMutationRequest.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/CreateEventMutationRequest.kt new file mode 100644 index 000000000..54e5165c1 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/CreateEventMutationRequest.kt @@ -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 = LinkedHashMap() + private val useObjectMapperForInputSerialization: MutableSet = 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 = input + + override fun getUseObjectMapperForInputSerialization(): MutableSet = 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) + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/CreateEventMutationResolver.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/CreateEventMutationResolver.kt new file mode 100644 index 000000000..eb5ee8a15 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/CreateEventMutationResolver.kt @@ -0,0 +1,13 @@ + +/** + * Create a new event. + */ +interface CreateEventMutationResolver { + + /** + * Create a new event. + */ + @Throws(Exception::class) + fun createEvent(categoryId: String, createdBy: String?): Event + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/CreateEventMutationResponse.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/CreateEventMutationResponse.kt new file mode 100644 index 000000000..e50f2de9c --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/CreateEventMutationResponse.kt @@ -0,0 +1,19 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResult + +/** + * Create a new event. + */ +open class CreateEventMutationResponse : GraphQLResult>() { + + companion object { + const val OPERATION_NAME: String = "createEvent" + } + + /** + * Create a new event. + */ + fun createEvent(): Event { + val data: MutableMap = super.getData() + return data.getValue(OPERATION_NAME) + } +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/Event.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/Event.kt new file mode 100644 index 000000000..0424156d7 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/Event.kt @@ -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?, + 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() + } +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventByIdQueryRequest.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventByIdQueryRequest.kt new file mode 100644 index 000000000..879fc5018 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventByIdQueryRequest.kt @@ -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 = LinkedHashMap() + private val useObjectMapperForInputSerialization: MutableSet = 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 = input + + override fun getUseObjectMapperForInputSerialization(): MutableSet = 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) + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventByIdQueryResolver.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventByIdQueryResolver.kt new file mode 100644 index 000000000..262f5c5d4 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventByIdQueryResolver.kt @@ -0,0 +1,13 @@ + +/** + * Single event by ID. + */ +interface EventByIdQueryResolver { + + /** + * Single event by ID. + */ + @Throws(Exception::class) + fun eventById(id: String): Event + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventByIdQueryResponse.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventByIdQueryResponse.kt new file mode 100644 index 000000000..994509012 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventByIdQueryResponse.kt @@ -0,0 +1,19 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResult + +/** + * Single event by ID. + */ +open class EventByIdQueryResponse : GraphQLResult>() { + + companion object { + const val OPERATION_NAME: String = "eventById" + } + + /** + * Single event by ID. + */ + fun eventById(): Event { + val data: MutableMap = super.getData() + return data.getValue(OPERATION_NAME) + } +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventProperty.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventProperty.kt new file mode 100644 index 000000000..bc4cfa00b --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventProperty.kt @@ -0,0 +1,33 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLRequestSerializer +import java.util.StringJoiner + +/** + * An event property have all possible types + */ +data class EventProperty( + val floatVal: Double?, + val booleanVal: Boolean?, + val intVal: Int, + val intVals: List?, + val stringVal: String? +) { + + // In the future, it maybe change. + override fun toString(): String { + val joiner = StringJoiner(", ", "{ ", " }") + if (floatVal != null) { + joiner.add("floatVal: " + GraphQLRequestSerializer.getEntry(floatVal)) + } + if (booleanVal != null) { + joiner.add("booleanVal: " + GraphQLRequestSerializer.getEntry(booleanVal)) + } + joiner.add("intVal: " + GraphQLRequestSerializer.getEntry(intVal)) + if (intVals != null) { + joiner.add("intVals: " + GraphQLRequestSerializer.getEntry(intVals)) + } + if (stringVal != null) { + joiner.add("stringVal: " + GraphQLRequestSerializer.getEntry(stringVal)) + } + return joiner.toString() + } +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventPropertyChildParametrizedInput.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventPropertyChildParametrizedInput.kt new file mode 100644 index 000000000..ea2cdbebe --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventPropertyChildParametrizedInput.kt @@ -0,0 +1,30 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLParametrizedInput +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLRequestSerializer +import java.util.StringJoiner +/** + * Parametrized input for field child in type EventProperty + */ +data class EventPropertyChildParametrizedInput( + val first: Int?, + val last: Int? +) : GraphQLParametrizedInput { + + override fun deepCopy(): EventPropertyChildParametrizedInput { + return EventPropertyChildParametrizedInput( + this.first, + this.last + ) + + } + + override fun toString(): String { + val joiner = StringJoiner(", ", "( ", " )") + if (first != null) { + joiner.add("first: " + GraphQLRequestSerializer.getEntry(first)) + } + if (last != null) { + joiner.add("last: " + GraphQLRequestSerializer.getEntry(last)) + } + return joiner.toString() + } +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventPropertyParentParametrizedInput.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventPropertyParentParametrizedInput.kt new file mode 100644 index 000000000..8e5cc0d14 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventPropertyParentParametrizedInput.kt @@ -0,0 +1,30 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLParametrizedInput +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLRequestSerializer +import java.util.StringJoiner +/** + * Parametrized input for field parent in type EventProperty + */ +data class EventPropertyParentParametrizedInput( + val withStatus: EventStatus?, + val createdAfter: String? +) : GraphQLParametrizedInput { + + override fun deepCopy(): EventPropertyParentParametrizedInput { + return EventPropertyParentParametrizedInput( + this.withStatus, + this.createdAfter + ) + + } + + override fun toString(): String { + val joiner = StringJoiner(", ", "( ", " )") + if (withStatus != null) { + joiner.add("withStatus: " + GraphQLRequestSerializer.getEntry(withStatus)) + } + if (createdAfter != null) { + joiner.add("createdAfter: " + GraphQLRequestSerializer.getEntry(createdAfter)) + } + return joiner.toString() + } +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventPropertyResolver.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventPropertyResolver.kt new file mode 100644 index 000000000..65a3ebc62 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventPropertyResolver.kt @@ -0,0 +1,19 @@ + +/** + * Resolver for EventProperty + */ +interface EventPropertyResolver { + + /** + * Properties + */ + @Throws(Exception::class) + fun child(eventProperty: EventProperty, first: Int?, last: Int?): List? + + /** + * Parent event of the property + */ + @Throws(Exception::class) + fun parent(eventProperty: EventProperty, withStatus: EventStatus?, createdAfter: String?): Event? + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventPropertyResponseProjection.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventPropertyResponseProjection.kt new file mode 100644 index 000000000..efd554ed9 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventPropertyResponseProjection.kt @@ -0,0 +1,123 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResponseField +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResponseProjection +import java.util.Objects + +/** + * Response projection for EventProperty + */ +open class EventPropertyResponseProjection : GraphQLResponseProjection { + + constructor(): super() + + constructor(projection: EventPropertyResponseProjection): super(projection) + + constructor(projections: List): super(projections) + + private val projectionDepthOnFields: MutableMap by lazy { mutableMapOf() } + + fun `all$`(): EventPropertyResponseProjection = `all$`(3) + + fun `all$`(maxDepth: Int): EventPropertyResponseProjection { + this.floatVal() + this.booleanVal() + this.intVal() + this.intVals() + this.stringVal() + if (projectionDepthOnFields.getOrDefault("EventPropertyResponseProjection.EventPropertyResponseProjection.child", 0) <= maxDepth) { + projectionDepthOnFields["EventPropertyResponseProjection.EventPropertyResponseProjection.child"] = projectionDepthOnFields.getOrDefault("EventPropertyResponseProjection.EventPropertyResponseProjection.child", 0) + 1 + this.child(EventPropertyResponseProjection().`all$`(maxDepth - projectionDepthOnFields.getOrDefault("EventPropertyResponseProjection.EventPropertyResponseProjection.child", 0))) + } + if (projectionDepthOnFields.getOrDefault("EventPropertyResponseProjection.EventResponseProjection.parent", 0) <= maxDepth) { + projectionDepthOnFields["EventPropertyResponseProjection.EventResponseProjection.parent"] = projectionDepthOnFields.getOrDefault("EventPropertyResponseProjection.EventResponseProjection.parent", 0) + 1 + this.parent(EventResponseProjection().`all$`(maxDepth - projectionDepthOnFields.getOrDefault("EventPropertyResponseProjection.EventResponseProjection.parent", 0))) + } + this.typename() + return this + } + + fun floatVal(): EventPropertyResponseProjection = floatVal(null) + + fun floatVal(alias: String?): EventPropertyResponseProjection { + `add$`(GraphQLResponseField("floatVal").alias(alias)) + return this + } + + fun booleanVal(): EventPropertyResponseProjection = booleanVal(null) + + fun booleanVal(alias: String?): EventPropertyResponseProjection { + `add$`(GraphQLResponseField("booleanVal").alias(alias)) + return this + } + + fun intVal(): EventPropertyResponseProjection = intVal(null) + + fun intVal(alias: String?): EventPropertyResponseProjection { + `add$`(GraphQLResponseField("intVal").alias(alias)) + return this + } + + fun intVals(): EventPropertyResponseProjection = intVals(null) + + fun intVals(alias: String?): EventPropertyResponseProjection { + `add$`(GraphQLResponseField("intVals").alias(alias)) + return this + } + + fun stringVal(): EventPropertyResponseProjection = stringVal(null) + + fun stringVal(alias: String?): EventPropertyResponseProjection { + `add$`(GraphQLResponseField("stringVal").alias(alias)) + return this + } + + fun child(subProjection: EventPropertyResponseProjection): EventPropertyResponseProjection = child(null, subProjection) + + fun child(alias: String?, subProjection: EventPropertyResponseProjection): EventPropertyResponseProjection { + `add$`(GraphQLResponseField("child").alias(alias).projection(subProjection)) + return this + } + + fun child(input: EventPropertyChildParametrizedInput, subProjection: EventPropertyResponseProjection): EventPropertyResponseProjection = child(null, input, subProjection) + + fun child(alias: String?, input: EventPropertyChildParametrizedInput, subProjection: EventPropertyResponseProjection): EventPropertyResponseProjection { + `add$`(GraphQLResponseField("child").alias(alias).parameters(input).projection(subProjection)) + return this + } + + fun parent(subProjection: EventResponseProjection): EventPropertyResponseProjection = parent(null, subProjection) + + fun parent(alias: String?, subProjection: EventResponseProjection): EventPropertyResponseProjection { + `add$`(GraphQLResponseField("parent").alias(alias).projection(subProjection)) + return this + } + + fun parent(input: EventPropertyParentParametrizedInput, subProjection: EventResponseProjection): EventPropertyResponseProjection = parent(null, input, subProjection) + + fun parent(alias: String?, input: EventPropertyParentParametrizedInput, subProjection: EventResponseProjection): EventPropertyResponseProjection { + `add$`(GraphQLResponseField("parent").alias(alias).parameters(input).projection(subProjection)) + return this + } + + fun typename(): EventPropertyResponseProjection = typename(null) + + fun typename(alias: String?): EventPropertyResponseProjection { + `add$`(GraphQLResponseField("__typename").alias(alias)) + return this + } + + override fun `deepCopy$`(): EventPropertyResponseProjection = EventPropertyResponseProjection(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + if (other == null || javaClass != other.javaClass) { + return false + } + val that = other as EventPropertyResponseProjection + return Objects.equals(fields, that.fields) + } + + override fun hashCode(): Int = Objects.hash(fields) + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventResponseProjection.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventResponseProjection.kt new file mode 100644 index 000000000..1de1926e7 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventResponseProjection.kt @@ -0,0 +1,114 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResponseField +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResponseProjection +import java.util.Objects + +/** + * Response projection for Event + */ +open class EventResponseProjection : GraphQLResponseProjection { + + constructor(): super() + + constructor(projection: EventResponseProjection): super(projection) + + constructor(projections: List): super(projections) + + private val projectionDepthOnFields: MutableMap by lazy { mutableMapOf() } + + fun `all$`(): EventResponseProjection = `all$`(3) + + fun `all$`(maxDepth: Int): EventResponseProjection { + this.id() + this.categoryId() + if (projectionDepthOnFields.getOrDefault("EventResponseProjection.EventPropertyResponseProjection.properties", 0) <= maxDepth) { + projectionDepthOnFields["EventResponseProjection.EventPropertyResponseProjection.properties"] = projectionDepthOnFields.getOrDefault("EventResponseProjection.EventPropertyResponseProjection.properties", 0) + 1 + this.properties(EventPropertyResponseProjection().`all$`(maxDepth - projectionDepthOnFields.getOrDefault("EventResponseProjection.EventPropertyResponseProjection.properties", 0))) + } + this.status() + this.createdBy() + this.createdDateTime() + this.active() + this.rating() + this.typename() + return this + } + + fun id(): EventResponseProjection = id(null) + + fun id(alias: String?): EventResponseProjection { + `add$`(GraphQLResponseField("id").alias(alias)) + return this + } + + fun categoryId(): EventResponseProjection = categoryId(null) + + fun categoryId(alias: String?): EventResponseProjection { + `add$`(GraphQLResponseField("categoryId").alias(alias)) + return this + } + + fun properties(subProjection: EventPropertyResponseProjection): EventResponseProjection = properties(null, subProjection) + + fun properties(alias: String?, subProjection: EventPropertyResponseProjection): EventResponseProjection { + `add$`(GraphQLResponseField("properties").alias(alias).projection(subProjection)) + return this + } + + fun status(): EventResponseProjection = status(null) + + fun status(alias: String?): EventResponseProjection { + `add$`(GraphQLResponseField("status").alias(alias)) + return this + } + + fun createdBy(): EventResponseProjection = createdBy(null) + + fun createdBy(alias: String?): EventResponseProjection { + `add$`(GraphQLResponseField("createdBy").alias(alias)) + return this + } + + fun createdDateTime(): EventResponseProjection = createdDateTime(null) + + fun createdDateTime(alias: String?): EventResponseProjection { + `add$`(GraphQLResponseField("createdDateTime").alias(alias)) + return this + } + + fun active(): EventResponseProjection = active(null) + + fun active(alias: String?): EventResponseProjection { + `add$`(GraphQLResponseField("active").alias(alias)) + return this + } + + fun rating(): EventResponseProjection = rating(null) + + fun rating(alias: String?): EventResponseProjection { + `add$`(GraphQLResponseField("rating").alias(alias)) + return this + } + + fun typename(): EventResponseProjection = typename(null) + + fun typename(alias: String?): EventResponseProjection { + `add$`(GraphQLResponseField("__typename").alias(alias)) + return this + } + + override fun `deepCopy$`(): EventResponseProjection = EventResponseProjection(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + if (other == null || javaClass != other.javaClass) { + return false + } + val that = other as EventResponseProjection + return Objects.equals(fields, that.fields) + } + + override fun hashCode(): Int = Objects.hash(fields) + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventStatus.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventStatus.kt new file mode 100644 index 000000000..683a16b51 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventStatus.kt @@ -0,0 +1,16 @@ +/** + * Possible statuses of the event + */ +enum class EventStatus(val graphqlName: String) { + + /** + * OPEN status + * Means just created + */ + OPEN("OPEN"), + IN_PROGRESS("IN_PROGRESS"), + /** + * Logging completed + */ + LOGGED("LOGGED") +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventsByCategoryAndStatusQueryRequest.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventsByCategoryAndStatusQueryRequest.kt new file mode 100644 index 000000000..552ea5226 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventsByCategoryAndStatusQueryRequest.kt @@ -0,0 +1,55 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperationRequest +import java.util.Objects + +/** + * List of events of a specified category. + */ +open class EventsByCategoryAndStatusQueryRequest(private val alias: String?) : GraphQLOperationRequest { + + companion object { + const val OPERATION_NAME: String = "eventsByCategoryAndStatus" + val OPERATION_TYPE: GraphQLOperation = GraphQLOperation.QUERY + } + + private val input: MutableMap = LinkedHashMap() + private val useObjectMapperForInputSerialization: MutableSet = HashSet() + + constructor(): this(null) + + fun setCategoryId(categoryId: String) { + this.input["categoryId"] = categoryId + } + + fun setStatus(status: EventStatus?) { + this.input["status"] = status + } + + override fun getOperationType(): GraphQLOperation = OPERATION_TYPE + + override fun getOperationName(): String = OPERATION_NAME + + override fun getAlias(): String? = alias ?: OPERATION_NAME + + override fun getInput(): MutableMap = input + + override fun getUseObjectMapperForInputSerialization(): MutableSet = useObjectMapperForInputSerialization + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + if (other == null || javaClass != other.javaClass) { + return false + } + val that = other as EventsByCategoryAndStatusQueryRequest + 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) + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventsByCategoryAndStatusQueryResolver.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventsByCategoryAndStatusQueryResolver.kt new file mode 100644 index 000000000..f3697309c --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventsByCategoryAndStatusQueryResolver.kt @@ -0,0 +1,13 @@ + +/** + * List of events of a specified category. + */ +interface EventsByCategoryAndStatusQueryResolver { + + /** + * List of events of a specified category. + */ + @Throws(Exception::class) + fun eventsByCategoryAndStatus(categoryId: String, status: EventStatus?): List + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventsByCategoryAndStatusQueryResponse.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventsByCategoryAndStatusQueryResponse.kt new file mode 100644 index 000000000..a15d83d14 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventsByCategoryAndStatusQueryResponse.kt @@ -0,0 +1,19 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResult + +/** + * List of events of a specified category. + */ +open class EventsByCategoryAndStatusQueryResponse : GraphQLResult>>() { + + companion object { + const val OPERATION_NAME: String = "eventsByCategoryAndStatus" + } + + /** + * List of events of a specified category. + */ + fun eventsByCategoryAndStatus(): List { + val data: MutableMap> = super.getData() + return data.getValue(OPERATION_NAME) + } +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventsByIdsQueryRequest.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventsByIdsQueryRequest.kt new file mode 100644 index 000000000..a5e57b618 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventsByIdsQueryRequest.kt @@ -0,0 +1,51 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperationRequest +import java.util.Objects + +/** + * Events by IDs. + */ +open class EventsByIdsQueryRequest(private val alias: String?) : GraphQLOperationRequest { + + companion object { + const val OPERATION_NAME: String = "eventsByIds" + val OPERATION_TYPE: GraphQLOperation = GraphQLOperation.QUERY + } + + private val input: MutableMap = LinkedHashMap() + private val useObjectMapperForInputSerialization: MutableSet = HashSet() + + constructor(): this(null) + + fun setIds(ids: List) { + this.input["ids"] = ids + } + + override fun getOperationType(): GraphQLOperation = OPERATION_TYPE + + override fun getOperationName(): String = OPERATION_NAME + + override fun getAlias(): String? = alias ?: OPERATION_NAME + + override fun getInput(): MutableMap = input + + override fun getUseObjectMapperForInputSerialization(): MutableSet = useObjectMapperForInputSerialization + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + if (other == null || javaClass != other.javaClass) { + return false + } + val that = other as EventsByIdsQueryRequest + 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) + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventsByIdsQueryResolver.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventsByIdsQueryResolver.kt new file mode 100644 index 000000000..844999432 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventsByIdsQueryResolver.kt @@ -0,0 +1,13 @@ + +/** + * Events by IDs. + */ +interface EventsByIdsQueryResolver { + + /** + * Events by IDs. + */ + @Throws(Exception::class) + fun eventsByIds(ids: List): List + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventsByIdsQueryResponse.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventsByIdsQueryResponse.kt new file mode 100644 index 000000000..ffbfd5df4 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventsByIdsQueryResponse.kt @@ -0,0 +1,19 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResult + +/** + * Events by IDs. + */ +open class EventsByIdsQueryResponse : GraphQLResult>>() { + + companion object { + const val OPERATION_NAME: String = "eventsByIds" + } + + /** + * Events by IDs. + */ + fun eventsByIds(): List { + val data: MutableMap> = super.getData() + return data.getValue(OPERATION_NAME) + } +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventsCreatedSubscriptionRequest.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventsCreatedSubscriptionRequest.kt new file mode 100644 index 000000000..c90907091 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventsCreatedSubscriptionRequest.kt @@ -0,0 +1,47 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperationRequest +import java.util.Objects + +/** + * Subscribe to events + */ +open class EventsCreatedSubscriptionRequest(private val alias: String?) : GraphQLOperationRequest { + + companion object { + const val OPERATION_NAME: String = "eventsCreated" + val OPERATION_TYPE: GraphQLOperation = GraphQLOperation.SUBSCRIPTION + } + + private val input: MutableMap = LinkedHashMap() + private val useObjectMapperForInputSerialization: MutableSet = HashSet() + + constructor(): this(null) + + override fun getOperationType(): GraphQLOperation = OPERATION_TYPE + + override fun getOperationName(): String = OPERATION_NAME + + override fun getAlias(): String? = alias ?: OPERATION_NAME + + override fun getInput(): MutableMap = input + + override fun getUseObjectMapperForInputSerialization(): MutableSet = useObjectMapperForInputSerialization + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + if (other == null || javaClass != other.javaClass) { + return false + } + val that = other as EventsCreatedSubscriptionRequest + 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) + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventsCreatedSubscriptionResolver.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventsCreatedSubscriptionResolver.kt new file mode 100644 index 000000000..9541e82a8 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventsCreatedSubscriptionResolver.kt @@ -0,0 +1,13 @@ + +/** + * Subscribe to events + */ +interface EventsCreatedSubscriptionResolver { + + /** + * Subscribe to events + */ + @Throws(Exception::class) + fun eventsCreated(): List + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventsCreatedSubscriptionResponse.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventsCreatedSubscriptionResponse.kt new file mode 100644 index 000000000..28ab8d424 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/EventsCreatedSubscriptionResponse.kt @@ -0,0 +1,19 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResult + +/** + * Subscribe to events + */ +open class EventsCreatedSubscriptionResponse : GraphQLResult>>() { + + companion object { + const val OPERATION_NAME: String = "eventsCreated" + } + + /** + * Subscribe to events + */ + fun eventsCreated(): List { + val data: MutableMap> = super.getData() + return data.getValue(OPERATION_NAME) + } +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/MutationResolver.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/MutationResolver.kt new file mode 100644 index 000000000..c71b0dd9a --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/MutationResolver.kt @@ -0,0 +1,10 @@ + +interface MutationResolver { + + /** + * Create a new event. + */ + @Throws(Exception::class) + fun createEvent(categoryId: String, createdBy: String?): Event + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/QueryResolver.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/QueryResolver.kt new file mode 100644 index 000000000..f66243e1a --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/QueryResolver.kt @@ -0,0 +1,28 @@ + +interface QueryResolver { + + /** + * Version of the application. + */ + @Throws(Exception::class) + fun version(): String + + /** + * List of events of a specified category. + */ + @Throws(Exception::class) + fun eventsByCategoryAndStatus(categoryId: String, status: EventStatus?): List + + /** + * Single event by ID. + */ + @Throws(Exception::class) + fun eventById(id: String): Event + + /** + * Events by IDs. + */ + @Throws(Exception::class) + fun eventsByIds(ids: List): List + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/SubscriptionResolver.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/SubscriptionResolver.kt new file mode 100644 index 000000000..49da8eb1c --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/SubscriptionResolver.kt @@ -0,0 +1,10 @@ + +interface SubscriptionResolver { + + /** + * Subscribe to events + */ + @Throws(Exception::class) + fun eventsCreated(): List + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/User.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/User.kt new file mode 100644 index 000000000..48cee0150 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/User.kt @@ -0,0 +1,23 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLRequestSerializer +import java.util.StringJoiner + +/** + * type with directive using enum value + */ +data class User( + val name: String?, + val friends: List? +) { + + // In the future, it maybe change. + override fun toString(): String { + val joiner = StringJoiner(", ", "{ ", " }") + if (name != null) { + joiner.add("name: " + GraphQLRequestSerializer.getEntry(name)) + } + if (friends != null) { + joiner.add("friends: " + GraphQLRequestSerializer.getEntry(friends)) + } + return joiner.toString() + } +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/UserResponseProjection.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/UserResponseProjection.kt new file mode 100644 index 000000000..d0e6fd752 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/UserResponseProjection.kt @@ -0,0 +1,66 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResponseField +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResponseProjection +import java.util.Objects + +/** + * Response projection for User + */ +open class UserResponseProjection : GraphQLResponseProjection { + + constructor(): super() + + constructor(projection: UserResponseProjection): super(projection) + + constructor(projections: List): super(projections) + + private val projectionDepthOnFields: MutableMap by lazy { mutableMapOf() } + + fun `all$`(): UserResponseProjection = `all$`(3) + + fun `all$`(maxDepth: Int): UserResponseProjection { + this.name() + if (projectionDepthOnFields.getOrDefault("UserResponseProjection.UserResponseProjection.friends", 0) <= maxDepth) { + projectionDepthOnFields["UserResponseProjection.UserResponseProjection.friends"] = projectionDepthOnFields.getOrDefault("UserResponseProjection.UserResponseProjection.friends", 0) + 1 + this.friends(UserResponseProjection().`all$`(maxDepth - projectionDepthOnFields.getOrDefault("UserResponseProjection.UserResponseProjection.friends", 0))) + } + this.typename() + return this + } + + fun name(): UserResponseProjection = name(null) + + fun name(alias: String?): UserResponseProjection { + `add$`(GraphQLResponseField("name").alias(alias)) + return this + } + + fun friends(subProjection: UserResponseProjection): UserResponseProjection = friends(null, subProjection) + + fun friends(alias: String?, subProjection: UserResponseProjection): UserResponseProjection { + `add$`(GraphQLResponseField("friends").alias(alias).projection(subProjection)) + return this + } + + fun typename(): UserResponseProjection = typename(null) + + fun typename(alias: String?): UserResponseProjection { + `add$`(GraphQLResponseField("__typename").alias(alias)) + return this + } + + override fun `deepCopy$`(): UserResponseProjection = UserResponseProjection(this) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + if (other == null || javaClass != other.javaClass) { + return false + } + val that = other as UserResponseProjection + return Objects.equals(fields, that.fields) + } + + override fun hashCode(): Int = Objects.hash(fields) + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/VersionQueryRequest.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/VersionQueryRequest.kt new file mode 100644 index 000000000..7fcc87e6d --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/VersionQueryRequest.kt @@ -0,0 +1,47 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperationRequest +import java.util.Objects + +/** + * Version of the application. + */ +open class VersionQueryRequest(private val alias: String?) : GraphQLOperationRequest { + + companion object { + const val OPERATION_NAME: String = "version" + val OPERATION_TYPE: GraphQLOperation = GraphQLOperation.QUERY + } + + private val input: MutableMap = LinkedHashMap() + private val useObjectMapperForInputSerialization: MutableSet = HashSet() + + constructor(): this(null) + + override fun getOperationType(): GraphQLOperation = OPERATION_TYPE + + override fun getOperationName(): String = OPERATION_NAME + + override fun getAlias(): String? = alias ?: OPERATION_NAME + + override fun getInput(): MutableMap = input + + override fun getUseObjectMapperForInputSerialization(): MutableSet = useObjectMapperForInputSerialization + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + if (other == null || javaClass != other.javaClass) { + return false + } + val that = other as VersionQueryRequest + 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) + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/VersionQueryResolver.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/VersionQueryResolver.kt new file mode 100644 index 000000000..d8305ca86 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/VersionQueryResolver.kt @@ -0,0 +1,13 @@ + +/** + * Version of the application. + */ +interface VersionQueryResolver { + + /** + * Version of the application. + */ + @Throws(Exception::class) + fun version(): String + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/VersionQueryResponse.kt b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/VersionQueryResponse.kt new file mode 100644 index 000000000..097591015 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/kotlin/compile-pass/VersionQueryResponse.kt @@ -0,0 +1,19 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResult + +/** + * Version of the application. + */ +open class VersionQueryResponse : GraphQLResult>() { + + companion object { + const val OPERATION_NAME: String = "version" + } + + /** + * Version of the application. + */ + fun version(): String { + val data: MutableMap = super.getData() + return data.getValue(OPERATION_NAME) + } +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/GraphQLCodegenVerifyCompileTest.java b/src/test/java/com/kobylynskyi/graphql/codegen/scala/GraphQLCodegenVerifyCompileTest.java new file mode 100644 index 000000000..408a8736e --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/GraphQLCodegenVerifyCompileTest.java @@ -0,0 +1,51 @@ +package com.kobylynskyi.graphql.codegen.scala; + +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/scala/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.SCALA); + mappingConfig.setGenerateToString(true); + mappingConfig.setGenerateApis(true); + mappingConfig.setGenerateClient(true); + mappingConfig.setAddGeneratedAnnotation(false); + mappingConfig.setGenerateEqualsAndHashCode(true); + mappingConfig.setModelValidationAnnotation(""); + } + + @Test + void generate_CheckFiles_Scala_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 ScalaGraphQLCodegen(singletonList(path), outputBuildDir, mappingConfig, + TestUtils.getStaticGeneratedInfo()).generate(); + } + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/CreateEventMutationRequest.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/CreateEventMutationRequest.scala new file mode 100644 index 000000000..3b289dde1 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/CreateEventMutationRequest.scala @@ -0,0 +1,62 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperationRequest +import java.util.{ LinkedHashMap => JLinkedHashMap } +import java.util.{ Map => JMap, Set => JSet } +import java.util.Objects +import scala.collection.mutable +import scala.collection.JavaConverters._ + +/** + * Create a new event. + */ +class CreateEventMutationRequest(alias: String) extends GraphQLOperationRequest { + + private final lazy val input = new JLinkedHashMap[String, java.lang.Object]() + private final lazy val useObjectMapperForInputSerialization: mutable.Set[String] = mutable.Set() + + def setCategoryId(categoryId: String): Unit = { + this.input.put("categoryId", categoryId) + } + + def setCreatedBy(createdBy: String): Unit = { + this.input.put("createdBy", createdBy) + } + + override def getOperationType(): GraphQLOperation = CreateEventMutationRequest.OPERATION_TYPE + + override def getOperationName(): String = CreateEventMutationRequest.OPERATION_NAME + + override def getAlias(): String = if (alias != null) alias else CreateEventMutationRequest.OPERATION_NAME + + override def getInput(): JMap[String, java.lang.Object] = input + + override def getUseObjectMapperForInputSerialization(): JSet[String] = useObjectMapperForInputSerialization.asJava + + override def equals(obj: Any): Boolean = { + if (this == obj) { + return true + } + if (obj == null || getClass != obj.getClass) { + return false + } + val that = obj.asInstanceOf[CreateEventMutationRequest] + Objects.equals(getOperationType(), that.getOperationType()) && + Objects.equals(getOperationName(), that.getOperationName()) && + Objects.equals(input, that.input) + } + + override def hashCode(): Int = Objects.hash(getOperationType(), getOperationName(), input) + + override def toString(): String = Objects.toString(input) +} + +object CreateEventMutationRequest { + + final val OPERATION_NAME: String = "createEvent" + final val OPERATION_TYPE: GraphQLOperation = GraphQLOperation.MUTATION + + def apply(alias: String) = new CreateEventMutationRequest(alias) + + def apply() = new CreateEventMutationRequest(null) + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/CreateEventMutationResolver.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/CreateEventMutationResolver.scala new file mode 100644 index 000000000..8f1114f21 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/CreateEventMutationResolver.scala @@ -0,0 +1,13 @@ + +/** + * Create a new event. + */ +trait CreateEventMutationResolver { + + /** + * Create a new event. + */ + @throws[Exception] + def createEvent(categoryId: String, createdBy: String): Event + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/CreateEventMutationResponse.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/CreateEventMutationResponse.scala new file mode 100644 index 000000000..8ac99bc00 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/CreateEventMutationResponse.scala @@ -0,0 +1,23 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResult +import java.util.{ Map => JMap } + +/** + * Create a new event. + */ +class CreateEventMutationResponse extends GraphQLResult[JMap[String, Event]] { + + /** + * Create a new event. + */ + def createEvent(): Event = { + val data: JMap[String, Event] = getData + if (data != null) data.get(CreateEventMutationResponse.OPERATION_NAME) else null + } + +} + +object CreateEventMutationResponse { + + private final val OPERATION_NAME: String = "createEvent" + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/Event.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/Event.scala new file mode 100644 index 000000000..22be6db4f --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/Event.scala @@ -0,0 +1,33 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLRequestSerializer +import scala.collection.JavaConverters._ +import EventStatus._ + +/** + * An event that describes a thing that happens + */ +case class Event( + id: String, + categoryId: String, + properties: scala.Seq[EventProperty], + @com.fasterxml.jackson.module.scala.JsonScalaEnumeration(classOf[EventStatusTypeRefer]) + status: EventStatus, + createdBy: String, + createdDateTime: String, + active: scala.Option[Boolean], + rating: scala.Option[Int] +) { + + override def toString(): String = { + scala.Seq( + if (id != null) "id: " + GraphQLRequestSerializer.getEntry(id) else "", + if (categoryId != null) "categoryId: " + GraphQLRequestSerializer.getEntry(categoryId) else "", + if (properties != null) "properties: " + GraphQLRequestSerializer.getEntry(properties.asJava) else "", + if (status != null) "status: " + GraphQLRequestSerializer.getEntry(status) else "", + if (createdBy != null) "createdBy: " + GraphQLRequestSerializer.getEntry(createdBy) else "", + if (createdDateTime != null) "createdDateTime: " + GraphQLRequestSerializer.getEntry(createdDateTime) else "", + if (active.isDefined) "active: " + GraphQLRequestSerializer.getEntry(active.get) else "", + if (rating.isDefined) "rating: " + GraphQLRequestSerializer.getEntry(rating.get) else "" + ).filter(_ != "").mkString("{", ",", "}") + } +} + diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventByIdQueryRequest.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventByIdQueryRequest.scala new file mode 100644 index 000000000..32722d5b4 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventByIdQueryRequest.scala @@ -0,0 +1,58 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperationRequest +import java.util.{ LinkedHashMap => JLinkedHashMap } +import java.util.{ Map => JMap, Set => JSet } +import java.util.Objects +import scala.collection.mutable +import scala.collection.JavaConverters._ + +/** + * Single event by ID. + */ +class EventByIdQueryRequest(alias: String) extends GraphQLOperationRequest { + + private final lazy val input = new JLinkedHashMap[String, java.lang.Object]() + private final lazy val useObjectMapperForInputSerialization: mutable.Set[String] = mutable.Set() + + def setId(id: String): Unit = { + this.input.put("id", id) + } + + override def getOperationType(): GraphQLOperation = EventByIdQueryRequest.OPERATION_TYPE + + override def getOperationName(): String = EventByIdQueryRequest.OPERATION_NAME + + override def getAlias(): String = if (alias != null) alias else EventByIdQueryRequest.OPERATION_NAME + + override def getInput(): JMap[String, java.lang.Object] = input + + override def getUseObjectMapperForInputSerialization(): JSet[String] = useObjectMapperForInputSerialization.asJava + + override def equals(obj: Any): Boolean = { + if (this == obj) { + return true + } + if (obj == null || getClass != obj.getClass) { + return false + } + val that = obj.asInstanceOf[EventByIdQueryRequest] + Objects.equals(getOperationType(), that.getOperationType()) && + Objects.equals(getOperationName(), that.getOperationName()) && + Objects.equals(input, that.input) + } + + override def hashCode(): Int = Objects.hash(getOperationType(), getOperationName(), input) + + override def toString(): String = Objects.toString(input) +} + +object EventByIdQueryRequest { + + final val OPERATION_NAME: String = "eventById" + final val OPERATION_TYPE: GraphQLOperation = GraphQLOperation.QUERY + + def apply(alias: String) = new EventByIdQueryRequest(alias) + + def apply() = new EventByIdQueryRequest(null) + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventByIdQueryResolver.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventByIdQueryResolver.scala new file mode 100644 index 000000000..fb0f6d38b --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventByIdQueryResolver.scala @@ -0,0 +1,13 @@ + +/** + * Single event by ID. + */ +trait EventByIdQueryResolver { + + /** + * Single event by ID. + */ + @throws[Exception] + def eventById(id: String): Event + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventByIdQueryResponse.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventByIdQueryResponse.scala new file mode 100644 index 000000000..73c47204c --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventByIdQueryResponse.scala @@ -0,0 +1,23 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResult +import java.util.{ Map => JMap } + +/** + * Single event by ID. + */ +class EventByIdQueryResponse extends GraphQLResult[JMap[String, Event]] { + + /** + * Single event by ID. + */ + def eventById(): Event = { + val data: JMap[String, Event] = getData + if (data != null) data.get(EventByIdQueryResponse.OPERATION_NAME) else null + } + +} + +object EventByIdQueryResponse { + + private final val OPERATION_NAME: String = "eventById" + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventProperty.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventProperty.scala new file mode 100644 index 000000000..72e5ef8eb --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventProperty.scala @@ -0,0 +1,25 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLRequestSerializer +import scala.collection.JavaConverters._ + +/** + * An event property have all possible types + */ +case class EventProperty( + floatVal: scala.Option[Double], + booleanVal: scala.Option[Boolean], + intVal: Int, + intVals: scala.Seq[Int], + stringVal: String +) { + + override def toString(): String = { + scala.Seq( + if (floatVal.isDefined) "floatVal: " + GraphQLRequestSerializer.getEntry(floatVal.get) else "", + if (booleanVal.isDefined) "booleanVal: " + GraphQLRequestSerializer.getEntry(booleanVal.get) else "", + "intVal: " + GraphQLRequestSerializer.getEntry(intVal), + if (intVals != null) "intVals: " + GraphQLRequestSerializer.getEntry(intVals.asJava) else "", + if (stringVal != null) "stringVal: " + GraphQLRequestSerializer.getEntry(stringVal) else "" + ).filter(_ != "").mkString("{", ",", "}") + } +} + diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventPropertyChildParametrizedInput.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventPropertyChildParametrizedInput.scala new file mode 100644 index 000000000..93b333ffa --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventPropertyChildParametrizedInput.scala @@ -0,0 +1,27 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLParametrizedInput +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLRequestSerializer +import scala.collection.JavaConverters._ + +/** + * Parametrized input for field child in type EventProperty + */ +case class EventPropertyChildParametrizedInput( + first: scala.Option[Int], + last: scala.Option[Int] +) extends GraphQLParametrizedInput { + + override def deepCopy(): EventPropertyChildParametrizedInput = { + EventPropertyChildParametrizedInput( + this.first, + this.last + ) + } + + override def toString(): String = { + scala.Seq( + if (first.isDefined) "first: " + GraphQLRequestSerializer.getEntry(first.get) else "", + if (last.isDefined) "last: " + GraphQLRequestSerializer.getEntry(last.get) else "" + ).filter(_ != "").mkString("(", ",", ")") + } + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventPropertyParentParametrizedInput.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventPropertyParentParametrizedInput.scala new file mode 100644 index 000000000..4d89cd98a --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventPropertyParentParametrizedInput.scala @@ -0,0 +1,28 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLParametrizedInput +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLRequestSerializer +import scala.collection.JavaConverters._ +import EventStatus._ + +/** + * Parametrized input for field parent in type EventProperty + */ +case class EventPropertyParentParametrizedInput( + withStatus: EventStatus, + createdAfter: String +) extends GraphQLParametrizedInput { + + override def deepCopy(): EventPropertyParentParametrizedInput = { + EventPropertyParentParametrizedInput( + this.withStatus, + this.createdAfter + ) + } + + override def toString(): String = { + scala.Seq( + if (withStatus != null) "withStatus: " + GraphQLRequestSerializer.getEntry(withStatus) else "", + if (createdAfter != null) "createdAfter: " + GraphQLRequestSerializer.getEntry(createdAfter) else "" + ).filter(_ != "").mkString("(", ",", ")") + } + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventPropertyResolver.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventPropertyResolver.scala new file mode 100644 index 000000000..a14eb5396 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventPropertyResolver.scala @@ -0,0 +1,20 @@ +import EventStatus._ + +/** + * Resolver for EventProperty + */ +trait EventPropertyResolver { + + /** + * Properties + */ + @throws[Exception] + def child(eventProperty: EventProperty, first: scala.Option[Int], last: scala.Option[Int]): scala.Seq[EventProperty] + + /** + * Parent event of the property + */ + @throws[Exception] + def parent(eventProperty: EventProperty, withStatus: EventStatus, createdAfter: String): Event + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventPropertyResponseProjection.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventPropertyResponseProjection.scala new file mode 100644 index 000000000..98507d5d5 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventPropertyResponseProjection.scala @@ -0,0 +1,161 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResponseField +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResponseProjection +import java.util.Objects +import scala.collection.mutable.HashMap +import scala.collection.JavaConverters._ + +/** + * Response projection for EventProperty + */ +class EventPropertyResponseProjection() extends GraphQLResponseProjection() { + + def this(projection: EventPropertyResponseProjection) = { + this() + if (projection != null) { + for (field <- projection.fields.values.asScala) { + add$(field) + } + } + } + + def this(projections: scala.Seq[EventPropertyResponseProjection]) = { + this() + if (projections != null) { + for (projection <- projections) { + if (projection != null) { + for (field <- projection.fields.values.asScala) { + add$(field) + } + } + } + } + } + + private final lazy val projectionDepthOnFields = new HashMap[String, Int] + + def all$(): EventPropertyResponseProjection = all$(3) + + def all$(maxDepth: Int): EventPropertyResponseProjection = { + this.floatVal() + this.booleanVal() + this.intVal() + this.intVals() + this.stringVal() + if (projectionDepthOnFields.getOrElse("EventPropertyResponseProjection.EventPropertyResponseProjection.child", 0) <= maxDepth) { + projectionDepthOnFields.put("EventPropertyResponseProjection.EventPropertyResponseProjection.child", projectionDepthOnFields.getOrElse("EventPropertyResponseProjection.EventPropertyResponseProjection.child", 0) + 1) + this.child(new EventPropertyResponseProjection().all$(maxDepth - projectionDepthOnFields.getOrElse("EventPropertyResponseProjection.EventPropertyResponseProjection.child", 0))) + } + if (projectionDepthOnFields.getOrElse("EventPropertyResponseProjection.EventResponseProjection.parent", 0) <= maxDepth) { + projectionDepthOnFields.put("EventPropertyResponseProjection.EventResponseProjection.parent", projectionDepthOnFields.getOrElse("EventPropertyResponseProjection.EventResponseProjection.parent", 0) + 1) + this.parent(new EventResponseProjection().all$(maxDepth - projectionDepthOnFields.getOrElse("EventPropertyResponseProjection.EventResponseProjection.parent", 0))) + } + this.typename() + this + } + + def floatVal(): EventPropertyResponseProjection = { + floatVal(null.asInstanceOf[String]) + } + + def floatVal(alias: String): EventPropertyResponseProjection = { + add$(new GraphQLResponseField("floatVal").alias(alias)) + this + } + + def booleanVal(): EventPropertyResponseProjection = { + booleanVal(null.asInstanceOf[String]) + } + + def booleanVal(alias: String): EventPropertyResponseProjection = { + add$(new GraphQLResponseField("booleanVal").alias(alias)) + this + } + + def intVal(): EventPropertyResponseProjection = { + intVal(null.asInstanceOf[String]) + } + + def intVal(alias: String): EventPropertyResponseProjection = { + add$(new GraphQLResponseField("intVal").alias(alias)) + this + } + + def intVals(): EventPropertyResponseProjection = { + intVals(null.asInstanceOf[String]) + } + + def intVals(alias: String): EventPropertyResponseProjection = { + add$(new GraphQLResponseField("intVals").alias(alias)) + this + } + + def stringVal(): EventPropertyResponseProjection = { + stringVal(null.asInstanceOf[String]) + } + + def stringVal(alias: String): EventPropertyResponseProjection = { + add$(new GraphQLResponseField("stringVal").alias(alias)) + this + } + + def child(subProjection: EventPropertyResponseProjection): EventPropertyResponseProjection = { + child(null.asInstanceOf[String], subProjection) + } + + def child(alias: String, subProjection: EventPropertyResponseProjection): EventPropertyResponseProjection = { + add$(new GraphQLResponseField("child").alias(alias).projection(subProjection)) + this + } + + def child(input: EventPropertyChildParametrizedInput,subProjection: EventPropertyResponseProjection): EventPropertyResponseProjection = { + child(null.asInstanceOf[String], input, subProjection) + } + + def child(alias: String, input: EventPropertyChildParametrizedInput , subProjection: EventPropertyResponseProjection): EventPropertyResponseProjection = { + add$(new GraphQLResponseField("child").alias(alias).parameters(input).projection(subProjection)) + this + } + + def parent(subProjection: EventResponseProjection): EventPropertyResponseProjection = { + parent(null.asInstanceOf[String], subProjection) + } + + def parent(alias: String, subProjection: EventResponseProjection): EventPropertyResponseProjection = { + add$(new GraphQLResponseField("parent").alias(alias).projection(subProjection)) + this + } + + def parent(input: EventPropertyParentParametrizedInput,subProjection: EventResponseProjection): EventPropertyResponseProjection = { + parent(null.asInstanceOf[String], input, subProjection) + } + + def parent(alias: String, input: EventPropertyParentParametrizedInput , subProjection: EventResponseProjection): EventPropertyResponseProjection = { + add$(new GraphQLResponseField("parent").alias(alias).parameters(input).projection(subProjection)) + this + } + + def typename(): EventPropertyResponseProjection = { + typename(null.asInstanceOf[String]) + } + + def typename(alias: String): EventPropertyResponseProjection = { + add$(new GraphQLResponseField("__typename").alias(alias)) + this + } + + override def deepCopy$(): EventPropertyResponseProjection = new EventPropertyResponseProjection(this) + + override def equals(obj: Any): Boolean = { + if (this == obj) { + return true + } + if (obj == null || getClass != obj.getClass) { + return false + } + val that = obj.asInstanceOf[EventPropertyResponseProjection] + Objects.equals(fields, that.fields) + } + + override def hashCode(): Int = Objects.hash(fields) + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventResponseProjection.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventResponseProjection.scala new file mode 100644 index 000000000..12f48b84b --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventResponseProjection.scala @@ -0,0 +1,150 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResponseField +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResponseProjection +import java.util.Objects +import scala.collection.mutable.HashMap +import scala.collection.JavaConverters._ + +/** + * Response projection for Event + */ +class EventResponseProjection() extends GraphQLResponseProjection() { + + def this(projection: EventResponseProjection) = { + this() + if (projection != null) { + for (field <- projection.fields.values.asScala) { + add$(field) + } + } + } + + def this(projections: scala.Seq[EventResponseProjection]) = { + this() + if (projections != null) { + for (projection <- projections) { + if (projection != null) { + for (field <- projection.fields.values.asScala) { + add$(field) + } + } + } + } + } + + private final lazy val projectionDepthOnFields = new HashMap[String, Int] + + def all$(): EventResponseProjection = all$(3) + + def all$(maxDepth: Int): EventResponseProjection = { + this.id() + this.categoryId() + if (projectionDepthOnFields.getOrElse("EventResponseProjection.EventPropertyResponseProjection.properties", 0) <= maxDepth) { + projectionDepthOnFields.put("EventResponseProjection.EventPropertyResponseProjection.properties", projectionDepthOnFields.getOrElse("EventResponseProjection.EventPropertyResponseProjection.properties", 0) + 1) + this.properties(new EventPropertyResponseProjection().all$(maxDepth - projectionDepthOnFields.getOrElse("EventResponseProjection.EventPropertyResponseProjection.properties", 0))) + } + this.status() + this.createdBy() + this.createdDateTime() + this.active() + this.rating() + this.typename() + this + } + + def id(): EventResponseProjection = { + id(null.asInstanceOf[String]) + } + + def id(alias: String): EventResponseProjection = { + add$(new GraphQLResponseField("id").alias(alias)) + this + } + + def categoryId(): EventResponseProjection = { + categoryId(null.asInstanceOf[String]) + } + + def categoryId(alias: String): EventResponseProjection = { + add$(new GraphQLResponseField("categoryId").alias(alias)) + this + } + + def properties(subProjection: EventPropertyResponseProjection): EventResponseProjection = { + properties(null.asInstanceOf[String], subProjection) + } + + def properties(alias: String, subProjection: EventPropertyResponseProjection): EventResponseProjection = { + add$(new GraphQLResponseField("properties").alias(alias).projection(subProjection)) + this + } + + def status(): EventResponseProjection = { + status(null.asInstanceOf[String]) + } + + def status(alias: String): EventResponseProjection = { + add$(new GraphQLResponseField("status").alias(alias)) + this + } + + def createdBy(): EventResponseProjection = { + createdBy(null.asInstanceOf[String]) + } + + def createdBy(alias: String): EventResponseProjection = { + add$(new GraphQLResponseField("createdBy").alias(alias)) + this + } + + def createdDateTime(): EventResponseProjection = { + createdDateTime(null.asInstanceOf[String]) + } + + def createdDateTime(alias: String): EventResponseProjection = { + add$(new GraphQLResponseField("createdDateTime").alias(alias)) + this + } + + def active(): EventResponseProjection = { + active(null.asInstanceOf[String]) + } + + def active(alias: String): EventResponseProjection = { + add$(new GraphQLResponseField("active").alias(alias)) + this + } + + def rating(): EventResponseProjection = { + rating(null.asInstanceOf[String]) + } + + def rating(alias: String): EventResponseProjection = { + add$(new GraphQLResponseField("rating").alias(alias)) + this + } + + def typename(): EventResponseProjection = { + typename(null.asInstanceOf[String]) + } + + def typename(alias: String): EventResponseProjection = { + add$(new GraphQLResponseField("__typename").alias(alias)) + this + } + + override def deepCopy$(): EventResponseProjection = new EventResponseProjection(this) + + override def equals(obj: Any): Boolean = { + if (this == obj) { + return true + } + if (obj == null || getClass != obj.getClass) { + return false + } + val that = obj.asInstanceOf[EventResponseProjection] + Objects.equals(fields, that.fields) + } + + override def hashCode(): Int = Objects.hash(fields) + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventStatus.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventStatus.scala new file mode 100644 index 000000000..a4c5ea93c --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventStatus.scala @@ -0,0 +1,23 @@ +import com.fasterxml.jackson.core.`type`.TypeReference + +/** + * Possible statuses of the event + */ +object EventStatus extends Enumeration { + + type EventStatus = Value + + /** + * OPEN status + * Means just created + */ + val OPEN: Value = Value("OPEN") + val IN_PROGRESS: Value = Value("IN_PROGRESS") + /** + * Logging completed + */ + val LOGGED: Value = Value("LOGGED") + +} + +class EventStatusTypeRefer extends TypeReference[EventStatus.type] diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventsByCategoryAndStatusQueryRequest.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventsByCategoryAndStatusQueryRequest.scala new file mode 100644 index 000000000..0c958d6a5 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventsByCategoryAndStatusQueryRequest.scala @@ -0,0 +1,63 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperationRequest +import java.util.{ LinkedHashMap => JLinkedHashMap } +import java.util.{ Map => JMap, Set => JSet } +import java.util.Objects +import scala.collection.mutable +import scala.collection.JavaConverters._ +import EventStatus._ + +/** + * List of events of a specified category. + */ +class EventsByCategoryAndStatusQueryRequest(alias: String) extends GraphQLOperationRequest { + + private final lazy val input = new JLinkedHashMap[String, java.lang.Object]() + private final lazy val useObjectMapperForInputSerialization: mutable.Set[String] = mutable.Set() + + def setCategoryId(categoryId: String): Unit = { + this.input.put("categoryId", categoryId) + } + + def setStatus(status: EventStatus): Unit = { + this.input.put("status", status) + } + + override def getOperationType(): GraphQLOperation = EventsByCategoryAndStatusQueryRequest.OPERATION_TYPE + + override def getOperationName(): String = EventsByCategoryAndStatusQueryRequest.OPERATION_NAME + + override def getAlias(): String = if (alias != null) alias else EventsByCategoryAndStatusQueryRequest.OPERATION_NAME + + override def getInput(): JMap[String, java.lang.Object] = input + + override def getUseObjectMapperForInputSerialization(): JSet[String] = useObjectMapperForInputSerialization.asJava + + override def equals(obj: Any): Boolean = { + if (this == obj) { + return true + } + if (obj == null || getClass != obj.getClass) { + return false + } + val that = obj.asInstanceOf[EventsByCategoryAndStatusQueryRequest] + Objects.equals(getOperationType(), that.getOperationType()) && + Objects.equals(getOperationName(), that.getOperationName()) && + Objects.equals(input, that.input) + } + + override def hashCode(): Int = Objects.hash(getOperationType(), getOperationName(), input) + + override def toString(): String = Objects.toString(input) +} + +object EventsByCategoryAndStatusQueryRequest { + + final val OPERATION_NAME: String = "eventsByCategoryAndStatus" + final val OPERATION_TYPE: GraphQLOperation = GraphQLOperation.QUERY + + def apply(alias: String) = new EventsByCategoryAndStatusQueryRequest(alias) + + def apply() = new EventsByCategoryAndStatusQueryRequest(null) + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventsByCategoryAndStatusQueryResolver.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventsByCategoryAndStatusQueryResolver.scala new file mode 100644 index 000000000..4f82afcae --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventsByCategoryAndStatusQueryResolver.scala @@ -0,0 +1,14 @@ +import EventStatus._ + +/** + * List of events of a specified category. + */ +trait EventsByCategoryAndStatusQueryResolver { + + /** + * List of events of a specified category. + */ + @throws[Exception] + def eventsByCategoryAndStatus(categoryId: String, status: EventStatus): scala.Seq[Event] + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventsByCategoryAndStatusQueryResponse.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventsByCategoryAndStatusQueryResponse.scala new file mode 100644 index 000000000..3c193a827 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventsByCategoryAndStatusQueryResponse.scala @@ -0,0 +1,23 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResult +import java.util.{ Map => JMap } + +/** + * List of events of a specified category. + */ +class EventsByCategoryAndStatusQueryResponse extends GraphQLResult[JMap[String, scala.Seq[Event]]] { + + /** + * List of events of a specified category. + */ + def eventsByCategoryAndStatus(): scala.Seq[Event] = { + val data: JMap[String, scala.Seq[Event]] = getData + if (data != null) data.get(EventsByCategoryAndStatusQueryResponse.OPERATION_NAME) else null + } + +} + +object EventsByCategoryAndStatusQueryResponse { + + private final val OPERATION_NAME: String = "eventsByCategoryAndStatus" + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventsByIdsQueryRequest.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventsByIdsQueryRequest.scala new file mode 100644 index 000000000..1a3ad2b40 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventsByIdsQueryRequest.scala @@ -0,0 +1,58 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperationRequest +import java.util.{ LinkedHashMap => JLinkedHashMap } +import java.util.{ Map => JMap, Set => JSet } +import java.util.Objects +import scala.collection.mutable +import scala.collection.JavaConverters._ + +/** + * Events by IDs. + */ +class EventsByIdsQueryRequest(alias: String) extends GraphQLOperationRequest { + + private final lazy val input = new JLinkedHashMap[String, java.lang.Object]() + private final lazy val useObjectMapperForInputSerialization: mutable.Set[String] = mutable.Set() + + def setIds(ids: scala.Seq[String]): Unit = { + this.input.put("ids", ids) + } + + override def getOperationType(): GraphQLOperation = EventsByIdsQueryRequest.OPERATION_TYPE + + override def getOperationName(): String = EventsByIdsQueryRequest.OPERATION_NAME + + override def getAlias(): String = if (alias != null) alias else EventsByIdsQueryRequest.OPERATION_NAME + + override def getInput(): JMap[String, java.lang.Object] = input + + override def getUseObjectMapperForInputSerialization(): JSet[String] = useObjectMapperForInputSerialization.asJava + + override def equals(obj: Any): Boolean = { + if (this == obj) { + return true + } + if (obj == null || getClass != obj.getClass) { + return false + } + val that = obj.asInstanceOf[EventsByIdsQueryRequest] + Objects.equals(getOperationType(), that.getOperationType()) && + Objects.equals(getOperationName(), that.getOperationName()) && + Objects.equals(input, that.input) + } + + override def hashCode(): Int = Objects.hash(getOperationType(), getOperationName(), input) + + override def toString(): String = Objects.toString(input) +} + +object EventsByIdsQueryRequest { + + final val OPERATION_NAME: String = "eventsByIds" + final val OPERATION_TYPE: GraphQLOperation = GraphQLOperation.QUERY + + def apply(alias: String) = new EventsByIdsQueryRequest(alias) + + def apply() = new EventsByIdsQueryRequest(null) + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventsByIdsQueryResolver.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventsByIdsQueryResolver.scala new file mode 100644 index 000000000..63af5df68 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventsByIdsQueryResolver.scala @@ -0,0 +1,13 @@ + +/** + * Events by IDs. + */ +trait EventsByIdsQueryResolver { + + /** + * Events by IDs. + */ + @throws[Exception] + def eventsByIds(ids: scala.Seq[String]): scala.Seq[Event] + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventsByIdsQueryResponse.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventsByIdsQueryResponse.scala new file mode 100644 index 000000000..a6aaea2e6 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventsByIdsQueryResponse.scala @@ -0,0 +1,23 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResult +import java.util.{ Map => JMap } + +/** + * Events by IDs. + */ +class EventsByIdsQueryResponse extends GraphQLResult[JMap[String, scala.Seq[Event]]] { + + /** + * Events by IDs. + */ + def eventsByIds(): scala.Seq[Event] = { + val data: JMap[String, scala.Seq[Event]] = getData + if (data != null) data.get(EventsByIdsQueryResponse.OPERATION_NAME) else null + } + +} + +object EventsByIdsQueryResponse { + + private final val OPERATION_NAME: String = "eventsByIds" + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventsCreatedSubscriptionRequest.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventsCreatedSubscriptionRequest.scala new file mode 100644 index 000000000..81018c25c --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventsCreatedSubscriptionRequest.scala @@ -0,0 +1,54 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperationRequest +import java.util.{ LinkedHashMap => JLinkedHashMap } +import java.util.{ Map => JMap, Set => JSet } +import java.util.Objects +import scala.collection.mutable +import scala.collection.JavaConverters._ + +/** + * Subscribe to events + */ +class EventsCreatedSubscriptionRequest(alias: String) extends GraphQLOperationRequest { + + private final lazy val input = new JLinkedHashMap[String, java.lang.Object]() + private final lazy val useObjectMapperForInputSerialization: mutable.Set[String] = mutable.Set() + + override def getOperationType(): GraphQLOperation = EventsCreatedSubscriptionRequest.OPERATION_TYPE + + override def getOperationName(): String = EventsCreatedSubscriptionRequest.OPERATION_NAME + + override def getAlias(): String = if (alias != null) alias else EventsCreatedSubscriptionRequest.OPERATION_NAME + + override def getInput(): JMap[String, java.lang.Object] = input + + override def getUseObjectMapperForInputSerialization(): JSet[String] = useObjectMapperForInputSerialization.asJava + + override def equals(obj: Any): Boolean = { + if (this == obj) { + return true + } + if (obj == null || getClass != obj.getClass) { + return false + } + val that = obj.asInstanceOf[EventsCreatedSubscriptionRequest] + Objects.equals(getOperationType(), that.getOperationType()) && + Objects.equals(getOperationName(), that.getOperationName()) && + Objects.equals(input, that.input) + } + + override def hashCode(): Int = Objects.hash(getOperationType(), getOperationName(), input) + + override def toString(): String = Objects.toString(input) +} + +object EventsCreatedSubscriptionRequest { + + final val OPERATION_NAME: String = "eventsCreated" + final val OPERATION_TYPE: GraphQLOperation = GraphQLOperation.SUBSCRIPTION + + def apply(alias: String) = new EventsCreatedSubscriptionRequest(alias) + + def apply() = new EventsCreatedSubscriptionRequest(null) + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventsCreatedSubscriptionResolver.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventsCreatedSubscriptionResolver.scala new file mode 100644 index 000000000..3e64852f1 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventsCreatedSubscriptionResolver.scala @@ -0,0 +1,13 @@ + +/** + * Subscribe to events + */ +trait EventsCreatedSubscriptionResolver { + + /** + * Subscribe to events + */ + @throws[Exception] + def eventsCreated(): scala.Seq[Event] + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventsCreatedSubscriptionResponse.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventsCreatedSubscriptionResponse.scala new file mode 100644 index 000000000..1606a8b3b --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/EventsCreatedSubscriptionResponse.scala @@ -0,0 +1,23 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResult +import java.util.{ Map => JMap } + +/** + * Subscribe to events + */ +class EventsCreatedSubscriptionResponse extends GraphQLResult[JMap[String, scala.Seq[Event]]] { + + /** + * Subscribe to events + */ + def eventsCreated(): scala.Seq[Event] = { + val data: JMap[String, scala.Seq[Event]] = getData + if (data != null) data.get(EventsCreatedSubscriptionResponse.OPERATION_NAME) else null + } + +} + +object EventsCreatedSubscriptionResponse { + + private final val OPERATION_NAME: String = "eventsCreated" + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/MutationResolver.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/MutationResolver.scala new file mode 100644 index 000000000..25f84a975 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/MutationResolver.scala @@ -0,0 +1,10 @@ + +trait MutationResolver { + + /** + * Create a new event. + */ + @throws[Exception] + def createEvent(categoryId: String, createdBy: String): Event + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/QueryResolver.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/QueryResolver.scala new file mode 100644 index 000000000..734bb0a88 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/QueryResolver.scala @@ -0,0 +1,29 @@ +import EventStatus._ + +trait QueryResolver { + + /** + * Version of the application. + */ + @throws[Exception] + def version(): String + + /** + * List of events of a specified category. + */ + @throws[Exception] + def eventsByCategoryAndStatus(categoryId: String, status: EventStatus): scala.Seq[Event] + + /** + * Single event by ID. + */ + @throws[Exception] + def eventById(id: String): Event + + /** + * Events by IDs. + */ + @throws[Exception] + def eventsByIds(ids: scala.Seq[String]): scala.Seq[Event] + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/SubscriptionResolver.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/SubscriptionResolver.scala new file mode 100644 index 000000000..bb9416772 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/SubscriptionResolver.scala @@ -0,0 +1,10 @@ + +trait SubscriptionResolver { + + /** + * Subscribe to events + */ + @throws[Exception] + def eventsCreated(): scala.Seq[Event] + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/User.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/User.scala new file mode 100644 index 000000000..6692a7306 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/User.scala @@ -0,0 +1,19 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLRequestSerializer +import scala.collection.JavaConverters._ + +/** + * type with directive using enum value + */ +case class User( + name: String, + friends: scala.Seq[User] +) { + + override def toString(): String = { + scala.Seq( + if (name != null) "name: " + GraphQLRequestSerializer.getEntry(name) else "", + if (friends != null) "friends: " + GraphQLRequestSerializer.getEntry(friends.asJava) else "" + ).filter(_ != "").mkString("{", ",", "}") + } +} + diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/UserResponseProjection.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/UserResponseProjection.scala new file mode 100644 index 000000000..808f1261b --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/UserResponseProjection.scala @@ -0,0 +1,90 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResponseField +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResponseProjection +import java.util.Objects +import scala.collection.mutable.HashMap +import scala.collection.JavaConverters._ + +/** + * Response projection for User + */ +class UserResponseProjection() extends GraphQLResponseProjection() { + + def this(projection: UserResponseProjection) = { + this() + if (projection != null) { + for (field <- projection.fields.values.asScala) { + add$(field) + } + } + } + + def this(projections: scala.Seq[UserResponseProjection]) = { + this() + if (projections != null) { + for (projection <- projections) { + if (projection != null) { + for (field <- projection.fields.values.asScala) { + add$(field) + } + } + } + } + } + + private final lazy val projectionDepthOnFields = new HashMap[String, Int] + + def all$(): UserResponseProjection = all$(3) + + def all$(maxDepth: Int): UserResponseProjection = { + this.name() + if (projectionDepthOnFields.getOrElse("UserResponseProjection.UserResponseProjection.friends", 0) <= maxDepth) { + projectionDepthOnFields.put("UserResponseProjection.UserResponseProjection.friends", projectionDepthOnFields.getOrElse("UserResponseProjection.UserResponseProjection.friends", 0) + 1) + this.friends(new UserResponseProjection().all$(maxDepth - projectionDepthOnFields.getOrElse("UserResponseProjection.UserResponseProjection.friends", 0))) + } + this.typename() + this + } + + def name(): UserResponseProjection = { + name(null.asInstanceOf[String]) + } + + def name(alias: String): UserResponseProjection = { + add$(new GraphQLResponseField("name").alias(alias)) + this + } + + def friends(subProjection: UserResponseProjection): UserResponseProjection = { + friends(null.asInstanceOf[String], subProjection) + } + + def friends(alias: String, subProjection: UserResponseProjection): UserResponseProjection = { + add$(new GraphQLResponseField("friends").alias(alias).projection(subProjection)) + this + } + + def typename(): UserResponseProjection = { + typename(null.asInstanceOf[String]) + } + + def typename(alias: String): UserResponseProjection = { + add$(new GraphQLResponseField("__typename").alias(alias)) + this + } + + override def deepCopy$(): UserResponseProjection = new UserResponseProjection(this) + + override def equals(obj: Any): Boolean = { + if (this == obj) { + return true + } + if (obj == null || getClass != obj.getClass) { + return false + } + val that = obj.asInstanceOf[UserResponseProjection] + Objects.equals(fields, that.fields) + } + + override def hashCode(): Int = Objects.hash(fields) + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/VersionQueryRequest.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/VersionQueryRequest.scala new file mode 100644 index 000000000..76123ec8f --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/VersionQueryRequest.scala @@ -0,0 +1,54 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperationRequest +import java.util.{ LinkedHashMap => JLinkedHashMap } +import java.util.{ Map => JMap, Set => JSet } +import java.util.Objects +import scala.collection.mutable +import scala.collection.JavaConverters._ + +/** + * Version of the application. + */ +class VersionQueryRequest(alias: String) extends GraphQLOperationRequest { + + private final lazy val input = new JLinkedHashMap[String, java.lang.Object]() + private final lazy val useObjectMapperForInputSerialization: mutable.Set[String] = mutable.Set() + + override def getOperationType(): GraphQLOperation = VersionQueryRequest.OPERATION_TYPE + + override def getOperationName(): String = VersionQueryRequest.OPERATION_NAME + + override def getAlias(): String = if (alias != null) alias else VersionQueryRequest.OPERATION_NAME + + override def getInput(): JMap[String, java.lang.Object] = input + + override def getUseObjectMapperForInputSerialization(): JSet[String] = useObjectMapperForInputSerialization.asJava + + override def equals(obj: Any): Boolean = { + if (this == obj) { + return true + } + if (obj == null || getClass != obj.getClass) { + return false + } + val that = obj.asInstanceOf[VersionQueryRequest] + Objects.equals(getOperationType(), that.getOperationType()) && + Objects.equals(getOperationName(), that.getOperationName()) && + Objects.equals(input, that.input) + } + + override def hashCode(): Int = Objects.hash(getOperationType(), getOperationName(), input) + + override def toString(): String = Objects.toString(input) +} + +object VersionQueryRequest { + + final val OPERATION_NAME: String = "version" + final val OPERATION_TYPE: GraphQLOperation = GraphQLOperation.QUERY + + def apply(alias: String) = new VersionQueryRequest(alias) + + def apply() = new VersionQueryRequest(null) + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/VersionQueryResolver.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/VersionQueryResolver.scala new file mode 100644 index 000000000..f91a50f6e --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/VersionQueryResolver.scala @@ -0,0 +1,13 @@ + +/** + * Version of the application. + */ +trait VersionQueryResolver { + + /** + * Version of the application. + */ + @throws[Exception] + def version(): String + +} diff --git a/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/VersionQueryResponse.scala b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/VersionQueryResponse.scala new file mode 100644 index 000000000..837b44089 --- /dev/null +++ b/src/test/java/com/kobylynskyi/graphql/codegen/scala/compile-pass/VersionQueryResponse.scala @@ -0,0 +1,23 @@ +import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLResult +import java.util.{ Map => JMap } + +/** + * Version of the application. + */ +class VersionQueryResponse extends GraphQLResult[JMap[String, String]] { + + /** + * Version of the application. + */ + def version(): String = { + val data: JMap[String, String] = getData + if (data != null) data.get(VersionQueryResponse.OPERATION_NAME) else null + } + +} + +object VersionQueryResponse { + + private final val OPERATION_NAME: String = "version" + +} diff --git a/src/test/resources/expected-classes/kt/restricted-words/QueryFunParametrizedInput.kt.txt b/src/test/resources/expected-classes/kt/restricted-words/QueryFunParametrizedInput.kt.txt index 71c74d0ad..44fa206e5 100644 --- a/src/test/resources/expected-classes/kt/restricted-words/QueryFunParametrizedInput.kt.txt +++ b/src/test/resources/expected-classes/kt/restricted-words/QueryFunParametrizedInput.kt.txt @@ -15,9 +15,10 @@ data class QueryFunParametrizedInput( ) : GraphQLParametrizedInput { override fun deepCopy(): QueryFunParametrizedInput { - val parametrizedInput = QueryFunParametrizedInput() - parametrizedInput.final(this.final) - return parametrizedInput + return QueryFunParametrizedInput( + this.final + ) + } override fun toString(): String { diff --git a/src/test/resources/expected-classes/kt/restricted-words/QueryPrivateParametrizedInput.kt.txt b/src/test/resources/expected-classes/kt/restricted-words/QueryPrivateParametrizedInput.kt.txt index 902fbcbc2..70abf58d6 100644 --- a/src/test/resources/expected-classes/kt/restricted-words/QueryPrivateParametrizedInput.kt.txt +++ b/src/test/resources/expected-classes/kt/restricted-words/QueryPrivateParametrizedInput.kt.txt @@ -18,12 +18,13 @@ data class QueryPrivateParametrizedInput( ) : GraphQLParametrizedInput { override fun deepCopy(): QueryPrivateParametrizedInput { - val parametrizedInput = QueryPrivateParametrizedInput() - parametrizedInput.int(this.int) - parametrizedInput.new(this.new) - parametrizedInput.enum(this.enum) - parametrizedInput.createdAfter(this.createdAfter) - return parametrizedInput + return QueryPrivateParametrizedInput( + this.int, + this.new, + this.enum, + this.createdAfter + ) + } override fun toString(): String { diff --git a/src/test/resources/expected-classes/scala/SearchResultItemConnectionResponseProjection.scala.txt b/src/test/resources/expected-classes/scala/SearchResultItemConnectionResponseProjection.scala.txt index d988b3b75..4cfc5a3c9 100644 --- a/src/test/resources/expected-classes/scala/SearchResultItemConnectionResponseProjection.scala.txt +++ b/src/test/resources/expected-classes/scala/SearchResultItemConnectionResponseProjection.scala.txt @@ -18,7 +18,7 @@ class SearchResultItemConnectionResponseProjection() extends GraphQLResponseProj def this(projection: SearchResultItemConnectionResponseProjection) = { this() if (projection != null) { - for (field <- projection.fields.values) { + for (field <- projection.fields.values.asScala) { add$(field) } } @@ -29,7 +29,7 @@ class SearchResultItemConnectionResponseProjection() extends GraphQLResponseProj if (projections != null) { for (projection <- projections) { if (projection != null) { - for (field <- projection.fields.values) { + for (field <- projection.fields.values.asScala) { add$(field) } } @@ -144,7 +144,7 @@ class SearchResultItemConnectionResponseProjection() extends GraphQLResponseProj this } - override def deepCopy$(): SearchResultItemConnectionResponseProjection = SearchResultItemConnectionResponseProjection(this) + override def deepCopy$(): SearchResultItemConnectionResponseProjection = new SearchResultItemConnectionResponseProjection(this) override def equals(obj: Any): Boolean = { if (this == obj) { diff --git a/src/test/resources/expected-classes/scala/SearchResultItemResponseProjection.scala.txt b/src/test/resources/expected-classes/scala/SearchResultItemResponseProjection.scala.txt index 48a91226e..2bf268c22 100644 --- a/src/test/resources/expected-classes/scala/SearchResultItemResponseProjection.scala.txt +++ b/src/test/resources/expected-classes/scala/SearchResultItemResponseProjection.scala.txt @@ -18,7 +18,7 @@ class SearchResultItemResponseProjection() extends GraphQLResponseProjection() { def this(projection: SearchResultItemResponseProjection) = { this() if (projection != null) { - for (field <- projection.fields.values) { + for (field <- projection.fields.values.asScala) { add$(field) } } @@ -29,7 +29,7 @@ class SearchResultItemResponseProjection() extends GraphQLResponseProjection() { if (projections != null) { for (projection <- projections) { if (projection != null) { - for (field <- projection.fields.values) { + for (field <- projection.fields.values.asScala) { add$(field) } } @@ -118,7 +118,7 @@ class SearchResultItemResponseProjection() extends GraphQLResponseProjection() { this } - override def deepCopy$(): SearchResultItemResponseProjection = SearchResultItemResponseProjection(this) + override def deepCopy$(): SearchResultItemResponseProjection = new SearchResultItemResponseProjection(this) override def equals(obj: Any): Boolean = { if (this == obj) { diff --git a/src/test/resources/expected-classes/scala/empty/EventResponseProjection.scala.txt b/src/test/resources/expected-classes/scala/empty/EventResponseProjection.scala.txt index 6c0af7677..37a91a039 100644 --- a/src/test/resources/expected-classes/scala/empty/EventResponseProjection.scala.txt +++ b/src/test/resources/expected-classes/scala/empty/EventResponseProjection.scala.txt @@ -15,7 +15,7 @@ class EventResponseProjection() extends GraphQLResponseProjection() { def this(projection: EventResponseProjection) = { this() if (projection != null) { - for (field <- projection.fields.values) { + for (field <- projection.fields.values.asScala) { add$(field) } } @@ -26,7 +26,7 @@ class EventResponseProjection() extends GraphQLResponseProjection() { if (projections != null) { for (projection <- projections) { if (projection != null) { - for (field <- projection.fields.values) { + for (field <- projection.fields.values.asScala) { add$(field) } } @@ -52,7 +52,7 @@ class EventResponseProjection() extends GraphQLResponseProjection() { this } - override def deepCopy$(): EventResponseProjection = EventResponseProjection(this) + override def deepCopy$(): EventResponseProjection = new EventResponseProjection(this) } \ No newline at end of file diff --git a/src/test/resources/expected-classes/scala/extend/request/AssetResponseProjection.scala.txt b/src/test/resources/expected-classes/scala/extend/request/AssetResponseProjection.scala.txt index 717cc91d3..fbbefc84c 100644 --- a/src/test/resources/expected-classes/scala/extend/request/AssetResponseProjection.scala.txt +++ b/src/test/resources/expected-classes/scala/extend/request/AssetResponseProjection.scala.txt @@ -15,7 +15,7 @@ class AssetResponseProjection() extends GraphQLResponseProjection() { def this(projection: AssetResponseProjection) = { this() if (projection != null) { - for (field <- projection.fields.values) { + for (field <- projection.fields.values.asScala) { add$(field) } } @@ -26,7 +26,7 @@ class AssetResponseProjection() extends GraphQLResponseProjection() { if (projections != null) { for (projection <- projections) { if (projection != null) { - for (field <- projection.fields.values) { + for (field <- projection.fields.values.asScala) { add$(field) } } @@ -92,7 +92,7 @@ class AssetResponseProjection() extends GraphQLResponseProjection() { this } - override def deepCopy$(): AssetResponseProjection = AssetResponseProjection(this) + override def deepCopy$(): AssetResponseProjection = new AssetResponseProjection(this) } \ No newline at end of file diff --git a/src/test/resources/expected-classes/scala/extend/request/EventResponseProjection.scala.txt b/src/test/resources/expected-classes/scala/extend/request/EventResponseProjection.scala.txt index 27c9214ae..8a8020f3e 100644 --- a/src/test/resources/expected-classes/scala/extend/request/EventResponseProjection.scala.txt +++ b/src/test/resources/expected-classes/scala/extend/request/EventResponseProjection.scala.txt @@ -15,7 +15,7 @@ class EventResponseProjection() extends GraphQLResponseProjection() { def this(projection: EventResponseProjection) = { this() if (projection != null) { - for (field <- projection.fields.values) { + for (field <- projection.fields.values.asScala) { add$(field) } } @@ -26,7 +26,7 @@ class EventResponseProjection() extends GraphQLResponseProjection() { if (projections != null) { for (projection <- projections) { if (projection != null) { - for (field <- projection.fields.values) { + for (field <- projection.fields.values.asScala) { add$(field) } } @@ -105,7 +105,7 @@ class EventResponseProjection() extends GraphQLResponseProjection() { this } - override def deepCopy$(): EventResponseProjection = EventResponseProjection(this) + override def deepCopy$(): EventResponseProjection = new EventResponseProjection(this) } \ No newline at end of file diff --git a/src/test/resources/expected-classes/scala/tostring/QueryPrivateParametrizedInput.scala.txt b/src/test/resources/expected-classes/scala/tostring/QueryPrivateParametrizedInput.scala.txt index 5298ee29a..ebe9915cb 100644 --- a/src/test/resources/expected-classes/scala/tostring/QueryPrivateParametrizedInput.scala.txt +++ b/src/test/resources/expected-classes/scala/tostring/QueryPrivateParametrizedInput.scala.txt @@ -22,16 +22,16 @@ case class QueryPrivateParametrizedInput( createdAfter: java.time.ZonedDateTime ) extends GraphQLParametrizedInput { - override def deepCopy(): QueryPrivateParametrizedInput { - val parametrizedInput = QueryPrivateParametrizedInput() - parametrizedInput.int(this.int) - parametrizedInput.intOpt(this.intOpt) - parametrizedInput.seq1(this.seq1) - parametrizedInput.seq2(this.seq2) - parametrizedInput.`new`(this.`new`) - parametrizedInput.enum(this.enum) - parametrizedInput.createdAfter(this.createdAfter) - parametrizedInput + override def deepCopy(): QueryPrivateParametrizedInput = { + QueryPrivateParametrizedInput( + this.int, + this.intOpt, + this.seq1, + this.seq2, + this.`new`, + this.enum, + this.createdAfter + ) } override def toString(): String = {