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 5c3fb0f9..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 @@ -146,6 +146,7 @@ class InputTypeGenerator(config: CodeGenConfig, document: Document) : BaseDataTy } }.joinToString() ) + is ObjectValue -> CodeBlock.of("new \$L()", typeUtils.findReturnType(it.type)) else -> CodeBlock.of("\$L", defVal) } } 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 65967fcf..f469ee49 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 @@ -1593,6 +1593,32 @@ class CodeGenTest { assertCompilesJava(enumTypes + dataTypes) } + @Test + fun generateInputWithDefaultValueForComplexType() { + val schema = """ + enum Color { + red + } + + input ColorFilter { + color: Color = red + } + + input Car { + color: Color = red + make: String + } + + input MyCar { + car: Car = {color: red} + } + """.trimIndent() + + val (dataTypes, _, enumTypes) = CodeGen(CodeGenConfig(schemas = setOf(schema), packageName = basePackageName)).generate() + + assertCompilesJava(enumTypes + dataTypes) + } + @Test fun generateInputWithDefaultValueForArray() { val schema = """