diff --git a/graphql-dgs-codegen-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/CodeGenCli.kt b/graphql-dgs-codegen-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/CodeGenCli.kt index 36ed61bb..672637b3 100644 --- a/graphql-dgs-codegen-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/CodeGenCli.kt +++ b/graphql-dgs-codegen-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/CodeGenCli.kt @@ -46,7 +46,7 @@ class CodeGenCli : CliktCommand("Generate Java sources for SCHEMA file(s)") { ) private val language by option("--language", "-l", help = "Output language").choice("java", "kotlin", ignoreCase = true) .default("java") - private val generateClient by option("--generate-client", "-c", help = "Generate client api").flag(default = false) + private val generateClient by option("--generate-client", "-c", help = "Genereate client api").flag(default = false) private val generateDataTypes by option( "--generate-data-types", help = "Generate data types. Not needed when only generating an API" diff --git a/graphql-dgs-codegen-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/generators/java/DataTypeGenerator.kt b/graphql-dgs-codegen-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/generators/java/DataTypeGenerator.kt index 8ccf5d02..49dfbab5 100644 --- a/graphql-dgs-codegen-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/generators/java/DataTypeGenerator.kt +++ b/graphql-dgs-codegen-core/src/main/kotlin/com/netflix/graphql/dgs/codegen/generators/java/DataTypeGenerator.kt @@ -19,13 +19,11 @@ package com.netflix.graphql.dgs.codegen.generators.java import com.netflix.graphql.dgs.codegen.* -import com.netflix.graphql.dgs.codegen.generators.shared.CodeGeneratorUtils.capitalized import com.netflix.graphql.dgs.codegen.generators.shared.SiteTarget import com.netflix.graphql.dgs.codegen.generators.shared.applyDirectivesJava import com.squareup.javapoet.* import graphql.language.* import graphql.language.TypeName -import graphql.schema.idl.TypeUtil import org.slf4j.Logger import org.slf4j.LoggerFactory import java.io.Serializable @@ -83,15 +81,13 @@ class DataTypeGenerator(config: CodeGenConfig, document: Document) : BaseDataTyp if (config.generateDataTypes) { val fieldDefinitions = definition.fieldDefinitions .filterSkipped() - .map { fieldDefinition -> - val isNullable = !TypeUtil.isNonNull(fieldDefinition.type) + .map { Field( - fieldDefinition.name, - typeUtils.findReturnType(fieldDefinition.type, useInterfaceType, true), + it.name, + typeUtils.findReturnType(it.type, useInterfaceType, true), overrideGetter = overrideGetter, - description = fieldDefinition.description, - directives = fieldDefinition.directives, - isNullable = isNullable + description = it.description, + directives = it.directives ) } .plus( @@ -126,7 +122,6 @@ class InputTypeGenerator(config: CodeGenConfig, document: Document) : BaseDataTy val name = definition.name val fieldDefinitions = definition.inputValueDefinitions.map { - val isNullable = !TypeUtil.isNonNull(it.type) val defaultValue = it.defaultValue?.let { defVal -> when (defVal) { is BooleanValue -> CodeBlock.of("\$L", defVal.isValue) @@ -160,8 +155,7 @@ class InputTypeGenerator(config: CodeGenConfig, document: Document) : BaseDataTy type = typeUtils.findReturnType(it.type), initialValue = defaultValue, description = it.description, - directives = it.directives, - isNullable = isNullable + directives = it.directives ) }.plus(extensions.flatMap { it.inputValueDefinitions }.map { Field(it.name, typeUtils.findReturnType(it.type)) }) return generate(name, emptyList(), fieldDefinitions, definition.description, definition.directives) @@ -173,7 +167,7 @@ class InputTypeGenerator(config: CodeGenConfig, document: Document) : BaseDataTy } } -internal data class Field(val name: String, val type: com.squareup.javapoet.TypeName, val initialValue: CodeBlock? = null, val overrideGetter: Boolean = false, val interfaceType: com.squareup.javapoet.TypeName? = null, val description: Description? = null, val directives: List = listOf(), val isNullable: Boolean = true) +internal data class Field(val name: String, val type: com.squareup.javapoet.TypeName, val initialValue: CodeBlock? = null, val overrideGetter: Boolean = false, val interfaceType: com.squareup.javapoet.TypeName? = null, val description: Description? = null, val directives: List = listOf()) abstract class BaseDataTypeGenerator( internal val packageName: String, @@ -233,7 +227,7 @@ abstract class BaseDataTypeGenerator( addEquals(javaType) addHashcode(javaType) - addBuilder(fields, javaType) + addBuilder(javaType) val javaFile = JavaFile.builder(packageName, javaType.build()).build() @@ -347,22 +341,7 @@ abstract class BaseDataTypeGenerator( constructorBuilder .addParameter(parameterBuilder.build()) .addModifiers(Modifier.PUBLIC) - } - - fieldDefinitions.forEach { - val constructor = constructorBuilder - .addStatement( - "this.\$N = \$N", - ReservedKeywordSanitizer.sanitize(it.name), - ReservedKeywordSanitizer.sanitize(it.name) - ) - if (it.isNullable && it.initialValue == null) { - constructorBuilder - .addStatement( - "this.\$N = true", - generateBooleanFieldName(ReservedKeywordSanitizer.sanitize(it.name)) - ) - } + .addStatement("this.\$N = \$N", ReservedKeywordSanitizer.sanitize(it.name), ReservedKeywordSanitizer.sanitize(it.name)) } javaType.addMethod(constructorBuilder.build()) @@ -381,35 +360,6 @@ abstract class BaseDataTypeGenerator( private fun addField(fieldDefinition: Field, javaType: TypeSpec.Builder) { addFieldWithGetterAndSetter(fieldDefinition.type, fieldDefinition, javaType) - // Generate for all nullable fields without any defaults - if (fieldDefinition.isNullable && fieldDefinition.initialValue == null) { - addIsDefinedFieldWithGetters(fieldDefinition, javaType) - } - } - - private fun addIsDefinedFieldWithGetters(fieldDefinition: Field, javaType: TypeSpec.Builder) { - val fieldName = generateBooleanFieldName(ReservedKeywordSanitizer.sanitize(fieldDefinition.name)) - val field = FieldSpec - .builder(com.squareup.javapoet.TypeName.BOOLEAN, fieldName) - .addModifiers(Modifier.PRIVATE) - .initializer("false") - .build() - val getterName = "${fieldName}Defined" - - val getter = MethodSpec - .methodBuilder(getterName) - .addModifiers(Modifier.PUBLIC) - .returns(com.squareup.javapoet.TypeName.BOOLEAN) - .addStatement( - "return \$N", - fieldName - ).build() - javaType.addField(field) - javaType.addMethod(getter) - } - - private fun generateBooleanFieldName(name: String): String { - return "is${name.capitalized()}" } private fun addFieldWithGetterAndSetter(returnType: com.squareup.javapoet.TypeName?, fieldDefinition: Field, javaType: TypeSpec.Builder) { @@ -440,7 +390,6 @@ abstract class BaseDataTypeGenerator( val setterName = typeUtils.transformIfDefaultClassMethodExists("set${fieldDefinition.name[0].uppercase()}${fieldDefinition.name.substring(1)}", TypeUtils.Companion.setClass) val parameterBuilder = ParameterSpec.builder(returnType, ReservedKeywordSanitizer.sanitize(fieldDefinition.name)) - val setterMethodBuilder = MethodSpec.methodBuilder(setterName) .addModifiers(Modifier.PUBLIC) .addStatement( @@ -448,13 +397,6 @@ abstract class BaseDataTypeGenerator( ReservedKeywordSanitizer.sanitize(fieldDefinition.name), ReservedKeywordSanitizer.sanitize(fieldDefinition.name) ) - if (fieldDefinition.isNullable && fieldDefinition.initialValue == null) { - setterMethodBuilder - .addStatement( - "this.\$N = true", - generateBooleanFieldName(ReservedKeywordSanitizer.sanitize(fieldDefinition.name)) - ) - } if (fieldDefinition.directives.isNotEmpty()) { val (annotations, comments) = applyDirectivesJava(fieldDefinition.directives, config) @@ -489,13 +431,13 @@ abstract class BaseDataTypeGenerator( ) } - private fun addBuilder(fields: List, javaType: TypeSpec.Builder) { + private fun addBuilder(javaType: TypeSpec.Builder) { val className = ClassName.get(packageName, javaType.build().name) val buildMethod = MethodSpec.methodBuilder("build").returns(className).addStatement( """ - $className result = new $className(); - ${javaType.build().fieldSpecs.joinToString("\n") { "result.${it.name} = this.${it.name};".trimIndent() }} - return result + $className result = new $className(); + ${javaType.build().fieldSpecs.joinToString("\n") { "result.${it.name} = this.${it.name};" }} + return result """.trimIndent() ).addModifiers(Modifier.PUBLIC).build() @@ -518,23 +460,10 @@ abstract class BaseDataTypeGenerator( .addMethod(buildMethod) javaType.build().fieldSpecs.map { - val method = MethodSpec.methodBuilder(it.name) + MethodSpec.methodBuilder(it.name) .addJavadoc(it.javadoc) .returns(builderClassName) .addStatement("this.${it.name} = ${it.name}") - - val fieldName = it.name - val field = fields.find { it.name.contains(fieldName) } - - if (field?.isNullable == true && field.initialValue == null) { - method - .addStatement( - "this.\$N = true", - generateBooleanFieldName(it.name) - ) - } - - method .addStatement("return this") .addParameter(ParameterSpec.builder(it.type, it.name).build()) .addModifiers(Modifier.PUBLIC).build() diff --git a/graphql-dgs-codegen-core/src/test/kotlin/com/netflix/graphql/dgs/codegen/CodeGenTest.kt b/graphql-dgs-codegen-core/src/test/kotlin/com/netflix/graphql/dgs/codegen/CodeGenTest.kt index 6d19fcef..189b81c9 100644 --- a/graphql-dgs-codegen-core/src/test/kotlin/com/netflix/graphql/dgs/codegen/CodeGenTest.kt +++ b/graphql-dgs-codegen-core/src/test/kotlin/com/netflix/graphql/dgs/codegen/CodeGenTest.kt @@ -122,8 +122,8 @@ class CodeGenTest { assertThat(typeSpec.name).isEqualTo("Person") assertThat(dataTypes[0].packageName).isEqualTo(typesPackageName) - assertThat(typeSpec.fieldSpecs.size).isEqualTo(4) - assertThat(typeSpec.fieldSpecs).extracting("name").contains("firstname", "lastname", "isFirstname", "isLastname") + assertThat(typeSpec.fieldSpecs.size).isEqualTo(2) + assertThat(typeSpec.fieldSpecs).extracting("name").contains("firstname", "lastname") assertThat(typeSpec.methodSpecs).flatExtracting("parameters").extracting("name").contains("firstname", "lastname") dataTypes[0].writeTo(System.out) assertCompilesJava(dataTypes) @@ -147,8 +147,8 @@ class CodeGenTest { ).generate() val typeSpec = dataTypes[0].typeSpec assertThat(typeSpec.fieldSpecs[0].type.toString()).isEqualTo("java.lang.Integer") - assertThat(typeSpec.fieldSpecs[2].type.toString()).isEqualTo("java.lang.Boolean") - assertThat(typeSpec.fieldSpecs[4].type.toString()).isEqualTo("java.lang.Double") + assertThat(typeSpec.fieldSpecs[1].type.toString()).isEqualTo("java.lang.Boolean") + assertThat(typeSpec.fieldSpecs[2].type.toString()).isEqualTo("java.lang.Double") } @Test @@ -236,8 +236,8 @@ class CodeGenTest { ).generate() val typeSpec = dataTypes[0].typeSpec assertThat(typeSpec.fieldSpecs[0].type.toString()).isEqualTo("java.util.List") - assertThat(typeSpec.fieldSpecs[2].type.toString()).isEqualTo("java.util.List") - assertThat(typeSpec.fieldSpecs[4].type.toString()).isEqualTo("java.util.List") + assertThat(typeSpec.fieldSpecs[1].type.toString()).isEqualTo("java.util.List") + assertThat(typeSpec.fieldSpecs[2].type.toString()).isEqualTo("java.util.List") } @Test @@ -427,8 +427,8 @@ class CodeGenTest { assertThat(dataTypes.size).isEqualTo(1) assertThat(dataTypes[0].typeSpec.name).isEqualTo("Person") - assertThat(dataTypes[0].typeSpec.fieldSpecs.size).isEqualTo(4) - assertThat(dataTypes[0].typeSpec.fieldSpecs).extracting("name").contains("name", "email", "isName", "isEmail") + assertThat(dataTypes[0].typeSpec.fieldSpecs.size).isEqualTo(2) + assertThat(dataTypes[0].typeSpec.fieldSpecs).extracting("name").contains("name", "email") val type = assertThat(dataTypes[0].typeSpec.fieldSpecs).filteredOn("name", "email").extracting("type") type.extracting("rawType.canonicalName").contains("java.util.List") type.flatExtracting("typeArguments").extracting("canonicalName").contains("java.lang.String") @@ -497,8 +497,8 @@ class CodeGenTest { val employee = dataTypes.single().typeSpec // Check data class assertThat(employee.name).isEqualTo("Employee") - assertThat(employee.fieldSpecs.size).isEqualTo(5) - assertThat(employee.fieldSpecs).extracting("name").contains("firstname", "lastname", "company", "isLastname", "isCompany") + assertThat(employee.fieldSpecs.size).isEqualTo(3) + assertThat(employee.fieldSpecs).extracting("name").contains("firstname", "lastname", "company") val annotation = employee.annotations.single() assertThat(annotation).isEqualTo(disableJsonTypeInfoAnnotation()) @@ -564,8 +564,8 @@ class CodeGenTest { val employee = dataTypes.single().typeSpec // Check data class assertThat(employee.name).isEqualTo("AdminFeatureToggle") - assertThat(employee.fieldSpecs.size).isEqualTo(3) - assertThat(employee.fieldSpecs).extracting("name").contains("enabled", "boxedEnabled", "isBoxedEnabled") + assertThat(employee.fieldSpecs.size).isEqualTo(2) + assertThat(employee.fieldSpecs).extracting("name").contains("enabled", "boxedEnabled") val annotation = employee.annotations.single() assertThat(annotation).isEqualTo(disableJsonTypeInfoAnnotation()) @@ -765,8 +765,8 @@ class CodeGenTest { val employee = dataTypes.single().typeSpec // Check data class assertThat(employee.name).isEqualTo("Employee") - assertThat(employee.fieldSpecs.size).isEqualTo(6) - assertThat(employee.fieldSpecs).extracting("name").contains("firstname", "lastname", "company", "isFirstname", "isLastname", "isCompany") + assertThat(employee.fieldSpecs.size).isEqualTo(3) + assertThat(employee.fieldSpecs).extracting("name").contains("firstname", "lastname", "company") val annotation = employee.annotations.single() assertThat(annotation).isEqualTo(disableJsonTypeInfoAnnotation()) @@ -827,8 +827,8 @@ class CodeGenTest { // Check data class assertThat(dataTypes.size).isEqualTo(1) assertThat(dataTypes[0].typeSpec.name).isEqualTo("Person") - assertThat(dataTypes[0].typeSpec.fieldSpecs.size).isEqualTo(6) - assertThat(dataTypes[0].typeSpec.fieldSpecs).extracting("name").contains("firstname", "lastname", "friends", "isFirstname", "isLastname", "isFriends") + assertThat(dataTypes[0].typeSpec.fieldSpecs.size).isEqualTo(3) + assertThat(dataTypes[0].typeSpec.fieldSpecs).extracting("name").contains("firstname", "lastname", "friends") // Check type of friends field val parameterizedType = ParameterizedTypeName.get(ClassName.get(List::class.java), ClassName.get(typesPackageName, "Person")) @@ -1213,11 +1213,11 @@ class CodeGenTest { assertThat(dataTypes.size).isEqualTo(1) assertThat(dataTypes[0].typeSpec.name).isEqualTo("Person") assertThat(dataTypes[0].packageName).isEqualTo(typesPackageName) - assertThat(dataTypes[0].typeSpec.fieldSpecs).hasSize(5) + assertThat(dataTypes[0].typeSpec.fieldSpecs).hasSize(3) assertThat(dataTypes[0].typeSpec.fieldSpecs).extracting("name") - .contains("firstname", "data", "dataNotNullable", "isFirstname", "isData") + .contains("firstname", "data", "dataNotNullable") + assertThat(dataTypes[0].typeSpec.fieldSpecs[1].type.toString()).isEqualTo(expected) assertThat(dataTypes[0].typeSpec.fieldSpecs[2].type.toString()).isEqualTo(expected) - assertThat(dataTypes[0].typeSpec.fieldSpecs[4].type.toString()).isEqualTo(expected) assertCompilesJava(dataTypes) } } @@ -1582,8 +1582,8 @@ class CodeGenTest { assertThat(dataTypes[0].typeSpec.name).isEqualTo("MovieFilter") assertThat(dataTypes[0].packageName).isEqualTo(typesPackageName) - assertThat(dataTypes[0].typeSpec.fieldSpecs.size).isEqualTo(2) - assertThat(dataTypes[0].typeSpec.fieldSpecs).extracting("name").contains("genre", "isGenre") + assertThat(dataTypes[0].typeSpec.fieldSpecs.size).isEqualTo(1) + assertThat(dataTypes[0].typeSpec.fieldSpecs).extracting("name").contains("genre") assertCompilesJava(dataTypes) } @@ -1786,8 +1786,8 @@ class CodeGenTest { assertThat(dataTypes[0].typeSpec.name).isEqualTo("MovieFilter") assertThat(dataTypes[0].packageName).isEqualTo(typesPackageName) - assertThat(dataTypes[0].typeSpec.fieldSpecs.size).isEqualTo(4) - assertThat(dataTypes[0].typeSpec.fieldSpecs).extracting("name").contains("genre", "releaseYear", "isGenre", "isReleaseYear") + assertThat(dataTypes[0].typeSpec.fieldSpecs.size).isEqualTo(2) + assertThat(dataTypes[0].typeSpec.fieldSpecs).extracting("name").contains("genre", "releaseYear") assertCompilesJava(dataTypes) } @@ -2346,7 +2346,7 @@ class CodeGenTest { ) ).generate() assertThat(dataTypes[0].typeSpec.name).isEqualTo("Person") - assertThat(dataTypes[0].typeSpec.fieldSpecs).extracting("name").containsExactly("name", "isName") + assertThat(dataTypes[0].typeSpec.fieldSpecs).extracting("name").containsExactly("name") } @Test @@ -2425,10 +2425,10 @@ class CodeGenTest { val talent = dataTypes.single().typeSpec // Check data class assertThat(talent.name).isEqualTo("Talent") - assertThat(talent.fieldSpecs.size).isEqualTo(7) + assertThat(talent.fieldSpecs.size).isEqualTo(4) assertThat(talent.fieldSpecs) .extracting("name") - .containsExactlyInAnyOrder("firstname", "lastname", "company", "imdbProfile", "isLastname", "isCompany", "isImdbProfile") + .contains("firstname", "lastname", "company", "imdbProfile") val annotation = talent.annotations.single() assertThat(annotation).isEqualTo(disableJsonTypeInfoAnnotation()) @@ -2504,27 +2504,18 @@ class CodeGenTest { | | private String lastname; | - | private boolean isLastname = false; - | | private String company; | - | private boolean isCompany = false; - | | private String imdbProfile; | - | private boolean isImdbProfile = false; - | | public Talent() { | } | | public Talent(String firstname, String lastname, String company, String imdbProfile) { | this.firstname = firstname; | this.lastname = lastname; - | this.isLastname = true; | this.company = company; - | this.isCompany = true; | this.imdbProfile = imdbProfile; - | this.isImdbProfile = true; | } | | public String getFirstname() { @@ -2541,11 +2532,6 @@ class CodeGenTest { | | public void setLastname(String lastname) { | this.lastname = lastname; - | this.isLastname = true; - | } - | - | public boolean isLastnameDefined() { - | return isLastname; | } | | public String getCompany() { @@ -2554,11 +2540,6 @@ class CodeGenTest { | | public void setCompany(String company) { | this.company = company; - | this.isCompany = true; - | } - | - | public boolean isCompanyDefined() { - | return isCompany; | } | | public String getImdbProfile() { @@ -2567,11 +2548,6 @@ class CodeGenTest { | | public void setImdbProfile(String imdbProfile) { | this.imdbProfile = imdbProfile; - | this.isImdbProfile = true; - | } - | - | public boolean isImdbProfileDefined() { - | return isImdbProfile; | } | | @Override @@ -2586,16 +2562,13 @@ class CodeGenTest { | Talent that = (Talent) o; | return java.util.Objects.equals(firstname, that.firstname) && | java.util.Objects.equals(lastname, that.lastname) && - | isLastname == that.isLastname && | java.util.Objects.equals(company, that.company) && - | isCompany == that.isCompany && - | java.util.Objects.equals(imdbProfile, that.imdbProfile) && - | isImdbProfile == that.isImdbProfile; + | java.util.Objects.equals(imdbProfile, that.imdbProfile); | } | | @Override | public int hashCode() { - | return java.util.Objects.hash(firstname, lastname, isLastname, company, isCompany, imdbProfile, isImdbProfile); + | return java.util.Objects.hash(firstname, lastname, company, imdbProfile); | } | | public static com.netflix.graphql.dgs.codegen.tests.generated.types.Talent.Builder newBuilder() { @@ -2607,26 +2580,17 @@ class CodeGenTest { | | private String lastname; | - | private boolean isLastname = false; - | | private String company; | - | private boolean isCompany = false; - | | private String imdbProfile; | - | private boolean isImdbProfile = false; - | | public Talent build() { - | com.netflix.graphql.dgs.codegen.tests.generated.types.Talent result = new com.netflix.graphql.dgs.codegen.tests.generated.types.Talent(); - | result.firstname = this.firstname; + | com.netflix.graphql.dgs.codegen.tests.generated.types.Talent result = new com.netflix.graphql.dgs.codegen.tests.generated.types.Talent(); + | result.firstname = this.firstname; | result.lastname = this.lastname; - | result.isLastname = this.isLastname; | result.company = this.company; - | result.isCompany = this.isCompany; | result.imdbProfile = this.imdbProfile; - | result.isImdbProfile = this.isImdbProfile; - | return result; + | return result; | } | | public com.netflix.graphql.dgs.codegen.tests.generated.types.Talent.Builder firstname( @@ -2638,39 +2602,18 @@ class CodeGenTest { | public com.netflix.graphql.dgs.codegen.tests.generated.types.Talent.Builder lastname( | String lastname) { | this.lastname = lastname; - | this.isLastname = true; - | return this; - | } - | - | public com.netflix.graphql.dgs.codegen.tests.generated.types.Talent.Builder isLastname( - | boolean isLastname) { - | this.isLastname = isLastname; | return this; | } | | public com.netflix.graphql.dgs.codegen.tests.generated.types.Talent.Builder company( | String company) { | this.company = company; - | this.isCompany = true; - | return this; - | } - | - | public com.netflix.graphql.dgs.codegen.tests.generated.types.Talent.Builder isCompany( - | boolean isCompany) { - | this.isCompany = isCompany; | return this; | } | | public com.netflix.graphql.dgs.codegen.tests.generated.types.Talent.Builder imdbProfile( | String imdbProfile) { | this.imdbProfile = imdbProfile; - | this.isImdbProfile = true; - | return this; - | } - | - | public com.netflix.graphql.dgs.codegen.tests.generated.types.Talent.Builder isImdbProfile( - | boolean isImdbProfile) { - | this.isImdbProfile = isImdbProfile; | return this; | } | } @@ -2682,117 +2625,6 @@ class CodeGenTest { assertCompilesJava(dataTypes + interfaces) } - @Test - fun generateDataClassWithBooleanFieldIsSet() { - val schema = """ - type Query { - show(id: ID!): Show - } - - type Mutation { - updateShow(input: UpdateShowInput!): Show - } - - type Show { - id: ID! - title: String - releaseYear: Int - } - - input UpdateShowInput { - id: ID! - title: String - releaseYear: Int - } - """.trimIndent() - - val codeGenResult = CodeGen( - CodeGenConfig( - schemas = setOf(schema), - packageName = basePackageName - ) - ).generate() - - val dataTypes = codeGenResult.javaDataTypes - assertThat(dataTypes.size).isEqualTo(2) - - // Data Types - val typeSpec = dataTypes[0].typeSpec - assertThat(typeSpec.name).isEqualTo("Show") - assertThat(dataTypes[0].packageName).isEqualTo(typesPackageName) - - assertThat(typeSpec.fieldSpecs).extracting("name").contains("id", "title", "releaseYear", "isTitle", "isReleaseYear") - assertThat(typeSpec.methodSpecs).extracting("name").contains( - "getId", - "setId", - "getTitle", - "setTitle", - "getReleaseYear", - "setReleaseYear", - "", - "", - "toString", - "equals", - "hashCode", - "newBuilder", - "isTitleDefined", - "isReleaseYearDefined" - ) - - var fieldSetter = typeSpec.methodSpecs.find { it.name == "setId" } - assertThat(fieldSetter?.code.toString().trim()).isEqualTo( - """ - | this.id = id; - """.trimMargin().trimIndent() - ) - - fieldSetter = typeSpec.methodSpecs.find { it.name == "setTitle" } - assertThat(fieldSetter?.code.toString().trim()).isEqualTo( - """ - | this.title = title; - | this.isTitle = true; - """.trimMargin().trimIndent() - ) - - fieldSetter = typeSpec.methodSpecs.find { it.name == "setReleaseYear" } - assertThat(fieldSetter?.code.toString().trim()).isEqualTo( - """ - | this.releaseYear = releaseYear; - | this.isReleaseYear = true; - """.trimMargin().trimIndent() - ) - - var isDefinedMethod = typeSpec.methodSpecs.find { it.name == "isTitleDefined" } - assertThat(isDefinedMethod?.code.toString().trim()).isEqualTo("return isTitle;") - - isDefinedMethod = typeSpec.methodSpecs.find { it.name == "isReleaseYearDefined" } - assertThat(isDefinedMethod?.code.toString().trim()).isEqualTo("return isReleaseYear;") - - // Builder class - assertThat(typeSpec.typeSpecs[0].kind).isEqualTo(TypeSpec.Kind.CLASS) - assertThat(typeSpec.typeSpecs[0].name).isEqualTo("Builder") - - val builderSpec = typeSpec.typeSpecs.find { it.name == "Builder" } - - assertThat(builderSpec?.fieldSpecs).extracting("name").containsExactlyInAnyOrder("id", "title", "releaseYear", "isTitle", "isReleaseYear") - - val buildMethod = builderSpec?.methodSpecs?.find { it.name == "build" } - assertThat(buildMethod?.code.toString().trim()) - .isEqualTo( - """ -com.netflix.graphql.dgs.codegen.tests.generated.types.Show result = new com.netflix.graphql.dgs.codegen.tests.generated.types.Show(); - result.id = this.id; - result.title = this.title; - result.isTitle = this.isTitle; - result.releaseYear = this.releaseYear; - result.isReleaseYear = this.isReleaseYear; - return result; - """.trimMargin().trimIndent() - ) - - assertCompilesJava(dataTypes) - } - @Test fun generateInterfacesWithoutSetters() { val schema = """ @@ -3344,20 +3176,20 @@ com.netflix.graphql.dgs.codegen.tests.generated.types.Show result = new com.netf val movie = dataTypes[0] assertThat(movie.typeSpec.name).isEqualTo("Movie") assertThat(movie.typeSpec.superinterfaces).extracting("simpleName").containsExactly("IMovie") - assertThat(movie.typeSpec.fieldSpecs).extracting("name").containsExactlyInAnyOrder("id", "title", "genre", "language", "tags", "rating", "isId", "isTitle", "isGenre", "isLanguage", "isTags", "isRating") + assertThat(movie.typeSpec.fieldSpecs).extracting("name").containsExactly("id", "title", "genre", "language", "tags", "rating") assertThat(movie.typeSpec.fieldSpecs[0].type).extracting("simpleName").isEqualTo("String") - assertThat(movie.typeSpec.fieldSpecs[2].type).extracting("simpleName").isEqualTo("String") - assertThat(movie.typeSpec.fieldSpecs[4].type).extracting("simpleName").isEqualTo("IGenre") - assertThat(movie.typeSpec.fieldSpecs[6].type).extracting("simpleName").isEqualTo("Language") - parameterizedTypeName = movie.typeSpec.fieldSpecs[8].type as ParameterizedTypeName + assertThat(movie.typeSpec.fieldSpecs[1].type).extracting("simpleName").isEqualTo("String") + assertThat(movie.typeSpec.fieldSpecs[2].type).extracting("simpleName").isEqualTo("IGenre") + assertThat(movie.typeSpec.fieldSpecs[3].type).extracting("simpleName").isEqualTo("Language") + parameterizedTypeName = movie.typeSpec.fieldSpecs[4].type as ParameterizedTypeName assertThat(parameterizedTypeName.rawType).extracting("simpleName").isEqualTo("List") assertThat(parameterizedTypeName.typeArguments[0]).extracting("simpleName").isEqualTo("String") - assertThat(movie.typeSpec.fieldSpecs[10].type).extracting("simpleName").isEqualTo("IRating") + assertThat(movie.typeSpec.fieldSpecs[5].type).extracting("simpleName").isEqualTo("IRating") val moviePage = dataTypes[1] assertThat(moviePage.typeSpec.name).isEqualTo("MoviePage") assertThat(moviePage.typeSpec.superinterfaces).extracting("simpleName").containsExactly("IMoviePage") - assertThat(moviePage.typeSpec.fieldSpecs).extracting("name").containsExactly("items", "isItems") + assertThat(moviePage.typeSpec.fieldSpecs).extracting("name").containsExactly("items") parameterizedTypeName = moviePage.typeSpec.fieldSpecs[0].type as ParameterizedTypeName assertThat(parameterizedTypeName.rawType).extracting("simpleName").isEqualTo("List") val movieTypeName = parameterizedTypeName.typeArguments[0] as WildcardTypeName @@ -3366,24 +3198,24 @@ com.netflix.graphql.dgs.codegen.tests.generated.types.Show result = new com.netf val genre = dataTypes[2] assertThat(genre.typeSpec.name).isEqualTo("Genre") assertThat(genre.typeSpec.superinterfaces).extracting("simpleName").containsExactly("IGenre") - assertThat(genre.typeSpec.fieldSpecs).extracting("name").containsExactly("name", "isName") + assertThat(genre.typeSpec.fieldSpecs).extracting("name").containsExactly("name") val rating = dataTypes[3] assertThat(rating.typeSpec.name).isEqualTo("Rating") assertThat(rating.typeSpec.superinterfaces).extracting("simpleName").containsExactly("IRating") - assertThat(rating.typeSpec.fieldSpecs).extracting("name").containsExactly("name", "isName") + assertThat(rating.typeSpec.fieldSpecs).extracting("name").containsExactly("name") val movieFilter = dataTypes[4] assertThat(movieFilter.typeSpec.name).isEqualTo("MovieFilter") assertThat(movieFilter.typeSpec.superinterfaces.size).isEqualTo(0) - assertThat(movieFilter.typeSpec.fieldSpecs).extracting("name").containsExactlyInAnyOrder("title", "genre", "language", "tags", "rating", "isTitle", "isGenre", "isLanguage", "isTags", "isRating") + assertThat(movieFilter.typeSpec.fieldSpecs).extracting("name").containsExactly("title", "genre", "language", "tags", "rating") assertThat(movieFilter.typeSpec.fieldSpecs[0].type).extracting("simpleName").isEqualTo("String") - assertThat(movieFilter.typeSpec.fieldSpecs[2].type).extracting("simpleName").isEqualTo("Genre") - assertThat(movieFilter.typeSpec.fieldSpecs[4].type).extracting("simpleName").isEqualTo("Language") - parameterizedTypeName = movieFilter.typeSpec.fieldSpecs[6].type as ParameterizedTypeName + assertThat(movieFilter.typeSpec.fieldSpecs[1].type).extracting("simpleName").isEqualTo("Genre") + assertThat(movieFilter.typeSpec.fieldSpecs[2].type).extracting("simpleName").isEqualTo("Language") + parameterizedTypeName = movieFilter.typeSpec.fieldSpecs[3].type as ParameterizedTypeName assertThat(parameterizedTypeName.rawType).extracting("simpleName").isEqualTo("List") assertThat(parameterizedTypeName.typeArguments[0]).extracting("simpleName").isEqualTo("String") - assertThat(movieFilter.typeSpec.fieldSpecs[8].type).extracting("simpleName").isEqualTo("Rating") + assertThat(movieFilter.typeSpec.fieldSpecs[4].type).extracting("simpleName").isEqualTo("Rating") assertCompilesJava(dataTypes + interfaces + result.javaEnumTypes) } @@ -3568,7 +3400,7 @@ com.netflix.graphql.dgs.codegen.tests.generated.types.Show result = new com.netf val searchResultPage = dataTypes[2] assertThat(searchResultPage.typeSpec.name).isEqualTo("SearchResultPage") assertThat(searchResultPage.typeSpec.superinterfaces).extracting("simpleName").containsExactly("ISearchResultPage") - assertThat(searchResultPage.typeSpec.fieldSpecs).extracting("name").containsExactly("items", "isItems") + assertThat(searchResultPage.typeSpec.fieldSpecs).extracting("name").containsExactly("items") parameterizedTypeName = searchResultPage.typeSpec.fieldSpecs[0].type as ParameterizedTypeName assertThat(parameterizedTypeName.rawType).extracting("simpleName").isEqualTo("List") @@ -3852,7 +3684,7 @@ It takes a title and such. assertThat(((person.annotations[0] as AnnotationSpec).type as ClassName).simpleName()).isEqualTo("Deprecated") assertThat(((person.annotations[0] as AnnotationSpec).type as ClassName).canonicalName()).isEqualTo("java.lang.Deprecated") val fields = person.fieldSpecs - assertThat(fields).hasSize(2) + assertThat(fields).hasSize(1) assertThat(fields[0].javadoc.toString()).isEqualTo("@deprecated This field is no longer available. Replaced by firstName") assertThat(fields[0].annotations).hasSize(1) assertThat(((fields[0].annotations[0] as AnnotationSpec).type as ClassName).simpleName()).isEqualTo("Deprecated") @@ -3887,7 +3719,7 @@ It takes a title and such. assertThat((person.annotations[0] as AnnotationSpec).members["maxLimit"]).isEqualTo(listOf(CodeBlock.of("\$L", 10))) assertThat((person.annotations[0] as AnnotationSpec).members["types"]).isEqualTo(listOf(CodeBlock.of("{\$L}", "\"husband\", \"wife\""))) val fields = person.fieldSpecs - assertThat(fields).hasSize(2) + assertThat(fields).hasSize(1) assertThat(fields[0].annotations).hasSize(1) assertThat(((fields[0].annotations[0] as AnnotationSpec).type as ClassName).simpleName()).isEqualTo("ValidName") assertThat(((fields[0].annotations[0] as AnnotationSpec).type as ClassName).canonicalName()).isEqualTo("com.test.validator.ValidName") @@ -3921,7 +3753,7 @@ It takes a title and such. assertThat((person.annotations[0] as AnnotationSpec).members["maxLimit"]).isEqualTo(listOf(CodeBlock.of("\$L", 10))) assertThat((person.annotations[0] as AnnotationSpec).members["types"]).isEqualTo(listOf(CodeBlock.of("{\$L}", "\"husband\", \"wife\""))) val fields = person.fieldSpecs - assertThat(fields).hasSize(2) + assertThat(fields).hasSize(1) assertThat(fields[0].annotations).hasSize(1) assertThat(((fields[0].annotations[0] as AnnotationSpec).type as ClassName).simpleName()).isEqualTo("ValidName") assertThat(((fields[0].annotations[0] as AnnotationSpec).type as ClassName).canonicalName()).isEqualTo("com.test.validator.ValidName") @@ -3955,7 +3787,7 @@ It takes a title and such. assertThat((person.annotations[0] as AnnotationSpec).members["maxLimit"]).isEqualTo(listOf(CodeBlock.of("\$L", 10))) assertThat((person.annotations[0] as AnnotationSpec).members["types"]).isEqualTo(listOf(CodeBlock.of("{\$L}", "\"husband\", \"wife\""))) val fields = person.fieldSpecs - assertThat(fields).hasSize(2) + assertThat(fields).hasSize(1) assertThat(fields[0].annotations).hasSize(1) assertThat(((fields[0].annotations[0] as AnnotationSpec).type as ClassName).simpleName()).isEqualTo("ValidName") assertThat(((fields[0].annotations[0] as AnnotationSpec).type as ClassName).canonicalName()).isEqualTo("com.test.validator.ValidName") @@ -4008,7 +3840,7 @@ It takes a title and such. assertThat((person.annotations[0] as AnnotationSpec).members["maxLimit"]).isEqualTo(listOf(CodeBlock.of("\$L", 10))) assertThat((person.annotations[0] as AnnotationSpec).members["types"]).isEqualTo(listOf(CodeBlock.of("{\$L}", "\"husband\", \"wife\""))) val fields = person.fieldSpecs - assertThat(fields).hasSize(2) + assertThat(fields).hasSize(1) assertThat(fields[0].annotations).hasSize(1) assertThat(((fields[0].annotations[0] as AnnotationSpec).type as ClassName).simpleName()).isEqualTo("ValidName") assertThat(((fields[0].annotations[0] as AnnotationSpec).type as ClassName).canonicalName()).isEqualTo("com.test.anotherValidator.ValidName") @@ -4042,7 +3874,7 @@ It takes a title and such. assertThat((person.annotations[0] as AnnotationSpec).members["maxLimit"]).isEqualTo(listOf(CodeBlock.of("\$L", 10))) assertThat((person.annotations[0] as AnnotationSpec).members["types"]).isEqualTo(listOf(CodeBlock.of("{\$L}", "\"husband\", \"wife\""))) val fields = person.fieldSpecs - assertThat(fields).hasSize(2) + assertThat(fields).hasSize(1) assertThat(fields[0].annotations).hasSize(1) assertThat(((fields[0].annotations[0] as AnnotationSpec).type as ClassName).simpleName()).isEqualTo("ValidName") assertThat(((fields[0].annotations[0] as AnnotationSpec).type as ClassName).canonicalName()).isEqualTo("com.test.anotherValidator.ValidName") @@ -4075,7 +3907,7 @@ It takes a title and such. assertThat((person.annotations[0] as AnnotationSpec).members).hasSize(1) assertThat((person.annotations[0] as AnnotationSpec).members["groups"]).isEqualTo(listOf(CodeBlock.of("\$L", "com.test.validator.groups.BasicValidation.class"))) val fields = person.fieldSpecs - assertThat(fields).hasSize(2) + assertThat(fields).hasSize(1) assertThat(fields[0].annotations).hasSize(1) assertThat(((fields[0].annotations[0] as AnnotationSpec).type as ClassName).simpleName()).isEqualTo("ValidName") assertThat(((fields[0].annotations[0] as AnnotationSpec).type as ClassName).canonicalName()).isEqualTo("com.test.anotherValidator.ValidName") @@ -4107,7 +3939,7 @@ It takes a title and such. assertThat((person.annotations[0] as AnnotationSpec).members).hasSize(1) assertThat((person.annotations[0] as AnnotationSpec).members["groups"]).isEqualTo(listOf(CodeBlock.of("\$S", "BasicValidation.class"))) // treat as string when no mapping is provided val fields = person.fieldSpecs - assertThat(fields).hasSize(2) + assertThat(fields).hasSize(1) assertThat(fields[0].annotations).hasSize(1) assertThat(((fields[0].annotations[0] as AnnotationSpec).type as ClassName).simpleName()).isEqualTo("ValidName") assertThat(((fields[0].annotations[0] as AnnotationSpec).type as ClassName).canonicalName()).isEqualTo("com.test.anotherValidator.ValidName") @@ -4145,7 +3977,7 @@ It takes a title and such. assertThat((person.annotations[0] as AnnotationSpec).members).hasSize(1) assertThat((person.annotations[0] as AnnotationSpec).members["groups"]).isEqualTo(listOf(CodeBlock.of("{\$L}", "com.test.validator.groups.BasicValidation.class, com.test.validator.groups.AdvanceValidation.class"))) val fields = person.fieldSpecs - assertThat(fields).hasSize(2) + assertThat(fields).hasSize(1) assertThat(fields[0].annotations).hasSize(1) assertThat(((fields[0].annotations[0] as AnnotationSpec).type as ClassName).simpleName()).isEqualTo("ValidName") assertThat(((fields[0].annotations[0] as AnnotationSpec).type as ClassName).canonicalName()).isEqualTo("com.test.anotherValidator.ValidName") @@ -4188,15 +4020,15 @@ It takes a title and such. assertThat((person.annotations[0] as AnnotationSpec).members).hasSize(1) assertThat((person.annotations[0] as AnnotationSpec).members["groups"]).isEqualTo(listOf(CodeBlock.of("{\$L}", "com.test.validator.groups.BasicValidation.class, com.test.validator.groups.AdvanceValidation.class"))) val fields = person.fieldSpecs - assertThat(fields).hasSize(4) + assertThat(fields).hasSize(2) assertThat(fields[0].annotations).hasSize(1) assertThat(((fields[0].annotations[0] as AnnotationSpec).type as ClassName).simpleName()).isEqualTo("ValidName") assertThat(((fields[0].annotations[0] as AnnotationSpec).type as ClassName).canonicalName()).isEqualTo("com.test.anotherValidator.ValidName") - assertThat(fields[2].annotations).hasSize(1) - assertThat(((fields[2].annotations[0] as AnnotationSpec).type as ClassName).simpleName()).isEqualTo("ValidDateOfBirth") - assertThat(((fields[2].annotations[0] as AnnotationSpec).type as ClassName).canonicalName()).isEqualTo("com.test.validator.dob.ValidDateOfBirth") - assertThat((fields[2].annotations[0] as AnnotationSpec).members["levels"]).isEqualTo(listOf(CodeBlock.of("{\$L}", "com.test.validator.dob.levels.PreliminaryValidation.class, com.test.validator.dob.levels.SecondaryValidation.class"))) + assertThat(fields[1].annotations).hasSize(1) + assertThat(((fields[1].annotations[0] as AnnotationSpec).type as ClassName).simpleName()).isEqualTo("ValidDateOfBirth") + assertThat(((fields[1].annotations[0] as AnnotationSpec).type as ClassName).canonicalName()).isEqualTo("com.test.validator.dob.ValidDateOfBirth") + assertThat((fields[1].annotations[0] as AnnotationSpec).members["levels"]).isEqualTo(listOf(CodeBlock.of("{\$L}", "com.test.validator.dob.levels.PreliminaryValidation.class, com.test.validator.dob.levels.SecondaryValidation.class"))) } @Test @@ -4226,7 +4058,7 @@ It takes a title and such. assertThat((person.annotations[0] as AnnotationSpec).members).hasSize(1) assertThat((person.annotations[0] as AnnotationSpec).members["sexType"]).isEqualTo(listOf(CodeBlock.of("\$L", "com.enums.MALE"))) val fields = person.fieldSpecs - assertThat(fields).hasSize(2) + assertThat(fields).hasSize(1) assertThat(fields[0].annotations).hasSize(1) assertThat(((fields[0].annotations[0] as AnnotationSpec).type as ClassName).simpleName()).isEqualTo("ValidName") assertThat(((fields[0].annotations[0] as AnnotationSpec).type as ClassName).canonicalName()).isEqualTo("com.test.anotherValidator.ValidName") @@ -4259,7 +4091,7 @@ It takes a title and such. assertThat((person.annotations[0] as AnnotationSpec).members).hasSize(1) assertThat((person.annotations[0] as AnnotationSpec).members["types"]).isEqualTo(listOf(CodeBlock.of("{\$L}", "com.enums.HUSBAND, com.enums.WIFE"))) val fields = person.fieldSpecs - assertThat(fields).hasSize(2) + assertThat(fields).hasSize(1) assertThat(fields[0].annotations).hasSize(1) assertThat(((fields[0].annotations[0] as AnnotationSpec).type as ClassName).simpleName()).isEqualTo("ValidName") assertThat(((fields[0].annotations[0] as AnnotationSpec).type as ClassName).canonicalName()).isEqualTo("com.test.anotherValidator.ValidName") @@ -4292,7 +4124,7 @@ It takes a title and such. assertThat((person.annotations[0] as AnnotationSpec).members).hasSize(1) assertThat((person.annotations[0] as AnnotationSpec).members["types"]).isEqualTo(listOf(CodeBlock.of("{\$L}", "com.enums.HUSBAND, com.enums.WIFE"))) val fields = person.fieldSpecs - assertThat(fields).hasSize(2) + assertThat(fields).hasSize(1) assertThat(fields[0].annotations).hasSize(1) assertThat(((fields[0].annotations[0] as AnnotationSpec).type as ClassName).simpleName()).isEqualTo("ValidName") assertThat(((fields[0].annotations[0] as AnnotationSpec).type as ClassName).canonicalName()).isEqualTo("com.test.anotherValidator.ValidName") @@ -4325,7 +4157,7 @@ It takes a title and such. assertThat((person.annotations[0] as AnnotationSpec).members).hasSize(1) assertThat((person.annotations[0] as AnnotationSpec).members["types"]).isEqualTo(listOf(CodeBlock.of("{\$L}", "com.enums.HUSBAND, com.enums.WIFE"))) val fields = person.fieldSpecs - assertThat(fields).hasSize(2) + assertThat(fields).hasSize(1) assertThat(fields[0].annotations).hasSize(2) assertThat(((fields[0].annotations[0] as AnnotationSpec).type as ClassName).simpleName()).isEqualTo("ValidName") assertThat(((fields[0].annotations[0] as AnnotationSpec).type as ClassName).canonicalName()).isEqualTo("com.test.anotherValidator.ValidName") @@ -4423,7 +4255,7 @@ It takes a title and such. assertThat(((person.annotations[0] as AnnotationSpec).type as ClassName).simpleName()).isEqualTo("Deprecated") assertThat(((person.annotations[0] as AnnotationSpec).type as ClassName).canonicalName()).isEqualTo("java.lang.Deprecated") val fields = person.fieldSpecs - assertThat(fields).hasSize(2) + assertThat(fields).hasSize(1) assertThat(fields[0].annotations).hasSize(0) } @@ -4451,7 +4283,7 @@ It takes a title and such. assertThat(person.name).isEqualTo("Person") assertThat(person.annotations).hasSize(2) val fields = person.fieldSpecs - assertThat(fields).hasSize(2) + assertThat(fields).hasSize(1) assertThat(fields[0].annotations).hasSize(1) val methods = person.methodSpecs assertThat((methods[0] as MethodSpec).name).isEqualTo("getName") @@ -4483,7 +4315,7 @@ It takes a title and such. assertThat(person.name).isEqualTo("Person") assertThat(person.annotations).hasSize(2) val fields = person.fieldSpecs - assertThat(fields).hasSize(2) + assertThat(fields).hasSize(1) assertThat(fields[0].annotations).hasSize(2) assertThat(((fields[0].annotations[0] as AnnotationSpec).type as ClassName).simpleName()).isEqualTo("ValidName") assertThat(((fields[0].annotations[0] as AnnotationSpec).type as ClassName).canonicalName()).isEqualTo("com.test.anotherValidator.ValidName") @@ -4518,7 +4350,7 @@ It takes a title and such. assertThat(person.name).isEqualTo("Person") assertThat(person.annotations).hasSize(2) val fields = person.fieldSpecs - assertThat(fields).hasSize(2) + assertThat(fields).hasSize(1) assertThat(fields[0].annotations).hasSize(1) val methods = person.methodSpecs assertThat((methods[0] as MethodSpec).name).isEqualTo("getName") @@ -4552,7 +4384,7 @@ It takes a title and such. assertThat(person.name).isEqualTo("Person") assertThat(person.annotations).hasSize(2) val fields = person.fieldSpecs - assertThat(fields).hasSize(2) + assertThat(fields).hasSize(1) assertThat(fields[0].annotations).hasSize(1) val methods = person.methodSpecs assertThat((methods[0] as MethodSpec).name).isEqualTo("getName") @@ -4588,7 +4420,7 @@ It takes a title and such. assertThat(person.name).isEqualTo("Person") assertThat(person.annotations).hasSize(2) val fields = person.fieldSpecs - assertThat(fields).hasSize(2) + assertThat(fields).hasSize(1) assertThat(fields[0].annotations).hasSize(1) val methods = person.methodSpecs assertThat((methods[0] as MethodSpec).name).isEqualTo("getName") @@ -4597,7 +4429,7 @@ It takes a title and such. assertThat(methods[1].annotations).hasSize(0) assertThat((methods[3] as MethodSpec).name).isEqualTo("") assertThat(methods[3].annotations).hasSize(0) - val parameters = (methods[4] as MethodSpec).parameters + val parameters = (methods[3] as MethodSpec).parameters assertThat(parameters).hasSize(1) assertThat(((parameters[0].annotations[0] as AnnotationSpec).type as ClassName).simpleName()).isEqualTo("ValidName") } @@ -4646,8 +4478,8 @@ It takes a title and such. ).generate() assertThat(dataTypes.size).isEqualTo(1) - assertThat(dataTypes[0].typeSpec.fieldSpecs[2].type.toString()).contains(basePackageName) - assertThat(dataTypes[0].typeSpec.fieldSpecs[4].type.toString()).isEqualTo("java.time.LocalDate") + assertThat(dataTypes[0].typeSpec.fieldSpecs[1].type.toString()).contains(basePackageName) + assertThat(dataTypes[0].typeSpec.fieldSpecs[2].type.toString()).isEqualTo("java.time.LocalDate") } @Test @@ -4669,7 +4501,7 @@ It takes a title and such. ).generate() assertThat(dataTypes.size).isEqualTo(1) - assertThat(dataTypes[0].typeSpec.fieldSpecs[4].type.toString()).isEqualTo("org.springframework.web.multipart.MultipartFile") + assertThat(dataTypes[0].typeSpec.fieldSpecs[2].type.toString()).isEqualTo("org.springframework.web.multipart.MultipartFile") } @Test diff --git a/graphql-dgs-codegen-core/src/test/kotlin/com/netflix/graphql/dgs/codegen/EntitiesClientApiGenTest.kt b/graphql-dgs-codegen-core/src/test/kotlin/com/netflix/graphql/dgs/codegen/EntitiesClientApiGenTest.kt index 541b128d..2ccb0bb8 100644 --- a/graphql-dgs-codegen-core/src/test/kotlin/com/netflix/graphql/dgs/codegen/EntitiesClientApiGenTest.kt +++ b/graphql-dgs-codegen-core/src/test/kotlin/com/netflix/graphql/dgs/codegen/EntitiesClientApiGenTest.kt @@ -61,7 +61,7 @@ class EntitiesClientApiGenTest { val representation = codeGenResult.javaDataTypes.single { "Representation" in it.typeSpec.name } assertThat(representation.typeSpec.name).isEqualTo("MovieRepresentation") assertThat(representation.typeSpec.fieldSpecs).extracting("name") - .containsExactlyInAnyOrder("__typename", "movieId", "isMovieId") + .containsExactlyInAnyOrder("__typename", "movieId") codeGenResult.assertCompile() } @@ -97,7 +97,7 @@ class EntitiesClientApiGenTest { val representation = codeGenResult.javaDataTypes.single { "Representation" in it.typeSpec.name } assertThat(representation.typeSpec.name).isEqualTo("MovieRepresentation") assertThat(representation.typeSpec.fieldSpecs).extracting("name") - .containsExactlyInAnyOrder("__typename", "movieId", "isMovieId") + .containsExactlyInAnyOrder("__typename", "movieId") codeGenResult.assertCompile() } @@ -140,10 +140,10 @@ class EntitiesClientApiGenTest { assertThat(representations).hasSize(2) assertThat(representations[0].typeSpec.name).isEqualTo("MovieRepresentation") assertThat(representations[0].typeSpec.fieldSpecs).extracting("name") - .containsExactlyInAnyOrder("__typename", "actor", "isActor") + .containsExactlyInAnyOrder("__typename", "actor") assertThat(representations[1].typeSpec.name).isEqualTo("IActorRepresentation") assertThat(representations[1].typeSpec.fieldSpecs).extracting("name") - .containsExactlyInAnyOrder("__typename", "name", "isName") + .containsExactlyInAnyOrder("__typename", "name") codeGenResult.assertCompile() } @@ -180,7 +180,7 @@ class EntitiesClientApiGenTest { assertThat(representations).hasSize(2) assertThat(representations[0].typeSpec.name).isEqualTo("MovieRepresentation") assertThat(representations[0].typeSpec.fieldSpecs).extracting("name") - .containsExactlyInAnyOrder("__typename", "movieId", "actors", "isMovieId", "isActors") + .containsExactlyInAnyOrder("__typename", "movieId", "actors") assertThat(representations[0].typeSpec.fieldSpecs[1]).extracting("type") .toString() .contains("java.util.List") @@ -226,13 +226,13 @@ class EntitiesClientApiGenTest { assertThat(representations).hasSize(3) assertThat(representations[0].typeSpec.name).isEqualTo("MovieRepresentation") assertThat(representations[0].typeSpec.fieldSpecs).extracting("name") - .containsExactlyInAnyOrder("__typename", "movieId", "actor", "isMovieId", "isActor") + .containsExactlyInAnyOrder("__typename", "movieId", "actor") assertThat(representations[1].typeSpec.name).isEqualTo("PersonRepresentation") assertThat(representations[1].typeSpec.fieldSpecs).extracting("name") - .containsExactlyInAnyOrder("__typename", "name", "isName") + .containsExactlyInAnyOrder("__typename", "name") assertThat(representations[2].typeSpec.name).isEqualTo("MovieCastRepresentation") assertThat(representations[2].typeSpec.fieldSpecs).extracting("name") - .containsExactlyInAnyOrder("__typename", "movie", "actor", "isMovie", "isActor") + .containsExactlyInAnyOrder("__typename", "movie", "actor") codeGenResult.assertCompile() } @@ -270,10 +270,10 @@ class EntitiesClientApiGenTest { assertThat(representations).hasSize(2) assertThat(representations[0].typeSpec.name).isEqualTo("MovieRepresentation") assertThat(representations[0].typeSpec.fieldSpecs).extracting("name") - .containsExactlyInAnyOrder("__typename", "movieId", "isMovieId") + .containsExactlyInAnyOrder("__typename", "movieId") assertThat(representations[1].typeSpec.name).isEqualTo("MovieActorRepresentation") assertThat(representations[1].typeSpec.fieldSpecs).extracting("name") - .containsExactlyInAnyOrder("__typename", "name", "isName") + .containsExactlyInAnyOrder("__typename", "name") codeGenResult.assertCompile() } @@ -308,10 +308,10 @@ class EntitiesClientApiGenTest { assertThat(representations).hasSize(2) assertThat(representations[0].typeSpec.name).isEqualTo("MovieRepresentation") assertThat(representations[0].typeSpec.fieldSpecs).extracting("name") - .containsExactlyInAnyOrder("__typename", "movieId", "actor", "isMovieId", "isActor") + .containsExactlyInAnyOrder("__typename", "movieId", "actor") assertThat(representations[1].typeSpec.name).isEqualTo("PersonRepresentation") assertThat(representations[1].typeSpec.fieldSpecs).extracting("name") - .containsExactlyInAnyOrder("__typename", "name", "age", "isName", "isAge") + .containsExactlyInAnyOrder("__typename", "name", "age") codeGenResult.assertCompile() } @@ -348,7 +348,7 @@ class EntitiesClientApiGenTest { assertThat(representations).hasSize(2) assertThat(representations[0].typeSpec.name).isEqualTo("MovieRepresentation") assertThat(representations[0].typeSpec.fieldSpecs).extracting("name") - .containsExactlyInAnyOrder("__typename", "id", "genre", "isId", "isGenre") + .containsExactlyInAnyOrder("__typename", "id", "genre") assertThat(representations[1].typeSpec.name).isEqualTo("MovieGenreRepresentation") codeGenResult.assertCompile() @@ -403,7 +403,7 @@ class EntitiesClientApiGenTest { ) assertThat(representations.first { it.typeSpec.name == "MovieRepresentation" }.typeSpec.fieldSpecs) - .extracting("name").containsExactlyInAnyOrder("__typename", "id", "actor", "genre", "location", "isId", "isGenre", "isActor", "isLocation") + .extracting("name").containsExactlyInAnyOrder("__typename", "id", "actor", "genre", "location") val movieRepresentationType = representations.find { it.typeSpec.name == "MovieRepresentation" } ?: fail("MovieRepresentation type not found") @@ -413,18 +413,14 @@ class EntitiesClientApiGenTest { "genre" to "com.netflix.graphql.dgs.codegen.tests.generated.client.MovieGenreRepresentation", "actor" to "com.netflix.graphql.dgs.codegen.tests.generated.client.PersonRepresentation", "location" to "com.netflix.graphql.dgs.codegen.tests.generated.client.LocationRepresentation", - "__typename" to "java.lang.String", - "isId" to "boolean", - "isGenre" to "boolean", - "isActor" to "boolean", - "isLocation" to "boolean" + "__typename" to "java.lang.String" ) assertThat(representations.first { it.typeSpec.name == "PersonRepresentation" }.typeSpec.fieldSpecs) - .extracting("name").containsExactlyInAnyOrder("__typename", "id", "isId") + .extracting("name").containsExactlyInAnyOrder("__typename", "id") assertThat(representations.first { it.typeSpec.name == "LocationRepresentation" }.typeSpec.fieldSpecs) - .extracting("name").containsExactlyInAnyOrder("__typename", "id", "isId") + .extracting("name").containsExactlyInAnyOrder("__typename", "id") codeGenResult.assertCompile() } diff --git a/graphql-dgs-codegen-core/src/test/kotlin/com/netflix/graphql/dgs/codegen/KotlinCodeGenTest.kt b/graphql-dgs-codegen-core/src/test/kotlin/com/netflix/graphql/dgs/codegen/KotlinCodeGenTest.kt index a397b564..acb4f29c 100644 --- a/graphql-dgs-codegen-core/src/test/kotlin/com/netflix/graphql/dgs/codegen/KotlinCodeGenTest.kt +++ b/graphql-dgs-codegen-core/src/test/kotlin/com/netflix/graphql/dgs/codegen/KotlinCodeGenTest.kt @@ -3725,17 +3725,16 @@ It takes a title and such. } """.trimIndent() - val codeGenResult = CodeGen( + val (dataTypes) = CodeGen( CodeGenConfig( schemas = setOf(schema), packageName = basePackageName ) ).generate() - val dataTypes = codeGenResult.javaDataTypes assertThat(dataTypes.size).isEqualTo(1) - assertThat(dataTypes[0].typeSpec.fieldSpecs[2].type.toString()).contains(basePackageName) - assertThat(dataTypes[0].typeSpec.fieldSpecs[4].type.toString()).isEqualTo("java.time.LocalDate") + assertThat(dataTypes[0].typeSpec.fieldSpecs[1].type.toString()).contains(basePackageName) + assertThat(dataTypes[0].typeSpec.fieldSpecs[2].type.toString()).isEqualTo("java.time.LocalDate") } @Test diff --git a/graphql-dgs-codegen-core/src/test/kotlin/com/netflix/graphql/dgs/codegen/clientapi/ClientApiGenQueryTest.kt b/graphql-dgs-codegen-core/src/test/kotlin/com/netflix/graphql/dgs/codegen/clientapi/ClientApiGenQueryTest.kt index 638862f0..115a1651 100644 --- a/graphql-dgs-codegen-core/src/test/kotlin/com/netflix/graphql/dgs/codegen/clientapi/ClientApiGenQueryTest.kt +++ b/graphql-dgs-codegen-core/src/test/kotlin/com/netflix/graphql/dgs/codegen/clientapi/ClientApiGenQueryTest.kt @@ -488,10 +488,10 @@ class ClientApiGenQueryTest { assertThat(codeGenResult.javaInterfaces[0].typeSpec.name).isEqualTo("HasDefaultField") assertThat(codeGenResult.javaDataTypes.size).isEqualTo(1) - assertThat(codeGenResult.javaDataTypes[0].typeSpec.fieldSpecs.size).isEqualTo(8) + assertThat(codeGenResult.javaDataTypes[0].typeSpec.fieldSpecs.size).isEqualTo(4) assertThat(codeGenResult.javaDataTypes[0].typeSpec.fieldSpecs[0].name).isEqualTo("name") - assertThat(codeGenResult.javaDataTypes[0].typeSpec.fieldSpecs[2].name).isEqualTo("_default") - assertThat(codeGenResult.javaDataTypes[0].typeSpec.fieldSpecs[4].name).isEqualTo("_public") + assertThat(codeGenResult.javaDataTypes[0].typeSpec.fieldSpecs[1].name).isEqualTo("_default") + assertThat(codeGenResult.javaDataTypes[0].typeSpec.fieldSpecs[2].name).isEqualTo("_public") assertCompilesJava( codeGenResult.clientProjections + codeGenResult.javaQueryTypes + codeGenResult.javaEnumTypes + codeGenResult.javaDataTypes + codeGenResult.javaInterfaces @@ -963,14 +963,14 @@ class ClientApiGenQueryTest { val typeSpec = codeGenResult.javaDataTypes[0].typeSpec assertThat(typeSpec.name).isEqualTo("Bar") assertThat(typeSpec.fieldSpecs[0].name).isEqualTo("object") - assertThat(typeSpec.fieldSpecs.size).isEqualTo(4) - assertThat(typeSpec.fieldSpecs[2].name).isEqualTo("_class") + assertThat(typeSpec.fieldSpecs.size).isEqualTo(2) + assertThat(typeSpec.fieldSpecs[1].name).isEqualTo("_class") assertThat(typeSpec.methodSpecs.size).isGreaterThan(0) assertThat(typeSpec.methodSpecs[0].name).isEqualTo("getObject") assertThat(typeSpec.methodSpecs[1].name).isEqualTo("setObject") - assertThat(typeSpec.methodSpecs[3].name).isEqualTo("getClassField") - assertThat(typeSpec.methodSpecs[4].name).isEqualTo("setClassField") + assertThat(typeSpec.methodSpecs[2].name).isEqualTo("getClassField") + assertThat(typeSpec.methodSpecs[3].name).isEqualTo("setClassField") assertCompilesJava(codeGenResult.javaDataTypes + codeGenResult.javaInterfaces) }