Hello everybody. Wanted to ask about optional fiel...
# orm-help
j
Hello everybody. Wanted to ask about optional fields that are defined in input type of my app schema. Let’s say I’ve got this input type:
Copy code
input UserUpdateInput {
  firstName: String
  lastName: String
  shippingAddress: AddressInput
  phone: String
}
And this mutation:
Copy code
updateUser(where: UserWhereUniqueInput!, data: UserUpdateInput!): User!
If I run this mutation and provide only
firstName
and
phone
for example. I can see that in my resolver I have args object with 2 properties that I have provided (only
firstName
and
phone
). The question is that I’ve seen implementations that use
*setNull
fields, like:
Copy code
input UserUpdateInput {
  firstName: String
  lastName: String
  shippingAddress: AddressInput
  shippingAddress_setNull: Boolean
  phone: String
  phone_setNull: Boolean
}
I’m told that the reason is that by default the fields that are optional and not provided are set to
null
but I don’t see that. And it’s used to distinguish if a user really wants to set the field as
null
or just hasn’t provided a value. But in my case I don’t see not provided values to be set
null
. Can you please help to understand what is the proper way to implement that? Thank you. P.S. API with Apollo Server.