Hello!
I am trying to create a React form component to update documents via GraphQL. I would like the form to be able to both set and unset fields in the same operation. When I try to make a request such as the following:
mutation updateOneInvitation($query: InvitationQueryInput, $set: InvitationUpdateInput!) { updateOneInvitation(query: $query, set: $set) { ...invitation_all } } fragment invitation_all on Invitation { _id defaults { firstName lastName timezone } organization issued accepted email }
…where my $set variable is the following:
{
"defaults": {
"firstName_unset": true,
"lastName_unset": true,
"timezone": "America/Chicago"
}
}
I get the following error:
Error: Updating the path 'defaults' would create a conflict at 'defaults'
Some cursory Googling led me to this StackOverflow post:
It would appear that setting and unsetting properties on an embedded document via the GraphQL is internally creating a MongoDB query which uses $set and $unset on the same embedded document, leading to this unexpected error.
How can I get around this, and both set and unset properties on an embedded document in the same request? I could do this in two operations but hide that fact from my users, which seems like a workable workaround for now, but I’d much prefer do this in one GraphQL request for the added reliability, simplicity, and responsiveness.