Nullable types for fields with default values in Kotlin
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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