Skip to content

Handle NullValue in input field default value code generation#920

Open
lcamilo15 wants to merge 1 commit intoNetflix:masterfrom
lcamilo15:fix/null-default-value-codegen
Open

Handle NullValue in input field default value code generation#920
lcamilo15 wants to merge 1 commit intoNetflix:masterfrom
lcamilo15:fix/null-default-value-codegen

Conversation

@lcamilo15
Copy link

Summary

  • Fix NullValue{} being generated instead of null when a GraphQL input field has = null as its default value
  • Handle NullValue in both Java and Kotlin code generators, alongside the existing EnumValue, BooleanValue, IntValue, etc. cases
  • Same root cause as the EnumValue bug fixed in PR Fix input type code generation for enum fields with default values #33 — the else branch called .toString() on the AST node

Test plan

  • Added generateInputWithDefaultNullValue test for Java codegen (CodeGenTest.kt)
  • Added generateInputWithDefaultNullValue test for Kotlin codegen (KotlinCodeGenTest.kt)
  • Both tests verify the generated code compiles (assertCompilesJava / assertCompilesKotlin)
  • All existing default value tests continue to pass

Fixes #770

When a GraphQL input field has `= null` as its default value, the
code generator called toString() on the NullValue AST node, producing
the literal string `NullValue{}` instead of valid Java/Kotlin `null`.

This is the same root cause as the EnumValue bug fixed in PR Netflix#33.

Fixes Netflix#770
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.

NullValue{} in generated code

1 participant