For an `input` type defined as ```input FooInput {...
# apollo-kotlin
s
For an
input
type defined as
Copy code
input FooInput {
  someId: ID
}
I get the generated code:
Copy code
public data class FooInput(
  public val someId: Optional<String?> = Optional.Absent,
)
Is there no configuration like we have for
generateOptionalOperationVariables.set(false)
that can turn this into a normal nullable too? Or is it that for
input
types specifically that we don’t want to do that as the absence of the value vs the explicit
null
on the value itself matters too much? In our use case I just want to either have the ID or not have it at all, there is no semantic difference between null and the absence of
someId
. Is there anything that could be done in the schema or in the codegen that I am missing to help me out here?
m
Nope, that's a pain but for GraphQL input fields, nullability implies optionality, you can't distinguish those
s
Ah makes total sense. Thanks for the links. I will just work with Optional here in that case, and just use
Optional.presentIfNotNull
for taking the nullable type and converting it to Optional. Thanks a lot 😊
m
If you ever want to work with compiler plugins, there's a fun project to make to allow Kotlin default argument to work similarly to Java builders
Copy code
// Notice how someId is **not** Optional
class FooInput(someId: String? = null) {
  val someId: Optional<String?>
}

FooInput() // someId is Optional.Absent
FooInput("bar") // someId is Optional.Present("bar")
FooInput(null) // someId is Option.Present(null)
s
Yeah, sounds like a really fun project. Also sounds quite “out of my league” in terms of what I know how to do if I wanna be realistic 😅 But yeah this would make it even more convenient to use in app code.