Mutation Default values

Hi Team,
I have an issue with default values coming from JSON input. when I am passing Id=1234 and content=maths the other fields author and isNetCalculated by default coming null to java object. this is updating null to author and isNetCalculated for Id=1234. where as user saying he does not want to update author and isNetCalculated and wants to only update content=maths for Id=1234. In this case by using java null check I can avoid updating author and isNetCalculated. but in some cases user saying when he passes author= null he wants to update the author column with null value. how to handle this scenario? I am using spring boot graphql api. How to find what columns actually user passing in the input json?


input MessageInput {
Id: String!
content: String
author: String
isNetCalculated: Boolean


type Mutation {
createMessage(input: MessageInput): Message

Sample JSON Request:
createMessage(input: {
Id: “1234”,
content: “maths”})

Maybe there is a better approach but you can try making another mutation.
The 2nd mutation could take similar input but in the resolver it specifically sets properties to null.

Could also try not setting default values and check the JSON for the optional keys. If the key exists, update the values. If the key does not exist, do nothing

Hi :wave:

What client are you using? If you’re using Apollo Kotlin with java codegen, optional input values take Optionals so you should be able to do something like this:

// Send "author": null
input = MessageInput.builder()

// Do not send "author"
input = MessageInput.builder()
   // .author(null) 

Hope this helps!