context: Updating multiple nodes at once with their own separate patches.
I can generate a mutation with multiple mutation statements one for each node, but my IDE frowns upon dynamic queries/mutations in this regards.
I can’t do this with the generated updateType mutation as it stands because it only takes one filter and patches all nodes that match the filter with the same patch.
I thought I could do this using a deep mutation, but deep mutations do not allow you to patch child nodes.
type Contact {
id: ID!
name: String!
settings: [Setting] @hasInverse(field: forContact)
}
type Setting {
id: ID!
type: SettingType!
forContact: Contact!
value: String!
}
type SettingType {
id: ID!
name: String! @search(by: [hash,term,fulltext])
type: String!
hasValues: [Setting] @hasInverse(field: type)
}
Data to update:
{
"contact": {
"id": "0xa", // existing Contact
"settings": [
{
"id": "0x42",
"value": "foo", // updated value
"type": {
"id:" "0xc" // existing SettingType
}
},
{
"id": "0x43",
"value": "bar", // update value
"type": {
"id": "0xb" // existing SettingType
}
},
{
"value": "baz", // new value
"type": {
"id": "0xd" // existing SettingType
}
}
]
}
}
So I can’t do updateContact
because no patch on children. I can’t do updateSettingType
because no patch on children. I can’t do updateSetting
because one of the settings is a new setting and because it can only update one node at a time.
“Hack” Solution:
Is there any other way to push this data in a single request besides breaking it down and doing something dynamic like:
fragment SettingFrag on Setting {
id
value
}
mutation myUpdate {
setting1: updateSetting(input: {
filter: { id: ["0x42"] }
set: { value: "foo" }
}) {
setting {
...SettingFrag
}
}
setting2: updateSetting(input: {
filter: { id: ["0x43"] }
set: { value: "bar" }
}) {
setting {
...SettingFrag
}
}
# update Contact to do a deep mutation adding new settings
updateContact(input: {
filter: { id: ["0xa"] }
set: {
settings: [{
type: { id: "0xd" }
value: "baz"
}]
}
}) {
contact {
id
settings {
...SettingFrag
}
}
}
}
Mimum Solution:
If updateType mutations accepted an array of UpdateTypeInput such as:
updateType(input: [UpdateTypeInput!]!) UpdatePayload
then I could at least make my mutation above a static mutation with variables even though I have to separate patched settings vs. new settings.
With the recent changes converting objects to arrays when necessary to conform to spec, this would be a backwards compatible change still
Best Solution:
What would be even better and a perfect solution would be to allow to patch children in an update mutation.