Netflix / Netflix/dgs-codegen

Nullable types for fields with default values in Kotlin

Open
#34 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Kotlin
Stars
217
Forks
116
PR merge metrics
No merged PRs in 30d

Description

Currently a schema like

input ColorFilter {
    color: String = "red"
}

generates a Kotlin class like (shortened to the constructor)

public data class ColorFilter(
  @JsonProperty("color")
  public val color: String? = "red"
)

According to the spec

An input field is required if it has a non‐null type and does not have a default value. Otherwise, the input object field is optional.

To my understanding this would allow to generate

public data class ColorFilter(
  @JsonProperty("color")
  public val color: String = "red"
)

as the field will be always set in this case. This would using the generated class a tad easier as it avoids using ?. or !!.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how GraphQL input fields with default values become Kotlin constructor properties; the issue does not name a source file, test, or entry point. Compare the generated nullability with the GraphQL required-field rule, and consider the work done when defaulted fields generate as non-null while other optional fields retain their current behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, kotlin
Domain
backend-api-design, tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.