Skip to content

Kotlin optional parameter changed in 4.0.0? #1126

Answered by dariuszkuc
jarlehansen asked this question in General
Discussion options

You must be logged in to vote

Hello 👋
Yes it was intentional. In older versions we always defaulted to null for optional arguments which while convenient was also ignoring any non-null defaults set in the code, i.e. given fun foo(bar: String? = "baz") it would always default to bar = null. While we cannot read those default values using reflections (so cannot expose them in the schema), we changed the default data fetcher logic to only set the argument value if it was specified in the request so it correctly honors the defaults now - in the example below bar will default to baz. As a side effect this requires all optional arguments to specify their defaults explicitly.

See #981

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jarlehansen
Comment options

Answer selected by jarlehansen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants