Use nullable fields instead of Optional wrapper for input type fields

Hi,

I’m using Apollo client in a Kotlin Multiplatform project. I already found out we can turn off generating Optional wrapper for operation variables via Gradle.

Is it possible to turn off the Optional wrapper generation for input type fields as well?

// this
data class TestInput(val field: Optional<Int?>)

// becomes this
data class TestInput(val field: Int?)
1 Like

Hi :wave:

Is it possible to turn off the Optional wrapper generation for input type fields as well?

That’s not possible because very often you need both. The typical case is this:

mutation updateUser($userInput: UserInput!) {
  updateUser(userInput: $userInput) {
    success
  }
}

if you pass {"phone": null} it will delete the phone number. If you pass {"name": "foo"}, it will update name but keep the phone number so in the context of input fields, null != absent.

If you really want to, you could look into Compiler Hooks to edit the generated Kotlin manually but I’d recommend against that.