Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of default values in schema for complex types. #648

Merged
merged 1 commit into from
Jan 17, 2024

Conversation

srinivasankavitha
Copy link
Contributor

The generated code for a schema that sets default values for complex types does not compile. Example test case:

@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)
    }

The code generation was not handling input defaults with type ObjectValue.

This PR fixes this by handling ObjectValue case by instantiating the equivalent class using default constructor.

@srinivasankavitha srinivasankavitha merged commit 1bff1a0 into master Jan 17, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant