In the many-to-one and many-to-many extras, there is currently a way to specify "exact", which essentially purges all past entries and creates new ones following the given inputs, such that all related entries end up equal to the given "exact" set. This is somewhat useful, but I would have expected the following to work as well:
class UpdateDogMutation(DjangoUpdateMutation):
class Meta:
model = Dog
many_to_many_extras = {
"enemies": {
"exact": {"type": "auto"},
}
}
mutation {
updateDog(id: "RG9nTm9kZTox", input: {
name: "Buster 2",
enemies: [
# Create a new cat:
{
owner: "VXNlck5vZGU6MQ==",
name: "John's new cat",
},
# Reference/update an existing cat:
{
id: "abc123==", # id of an existing cat which will be updated and included in the dog's enemies
owner: "VXNlck5vZGU6MQ==",
name: "John's existing cat with updated name",
},
]
}){
dog{
...DogInfo
}
}
}
This would allow the final related enemies set to be equal to the two cats above (removing any prior enemy cats that are not present in that list), where one of the cats gets newly created, and the other was an existing object, which is updated to have a new name. Right now in graphene-django-cud, however, the "auto" type for "exact" does not provide a way to specify an id for the elements in enemies, so you are forced to delete all past entires and create new ones, without being able to reference/update existing ones in one fell swoop. (I know there's an alternative which is to have separate add, remove, and update fields for the enemies relation so that you don't always have to "purge" to make updates, but 3 fields instead of 1 is quite a bit more cumbersome to deal with on the client.)
For instance, the popular django-rest-framework drf-writable-nested library has support for updating such that you can either update existing objects in the set when you provide their id or you can create new ones if the id is omitted (see example here).
Is it possible to support something like this, or is it already possible and I've misunderstood how to specify it? Thank you! As always, really appreciate how thorough and convenient this library is!
In the many-to-one and many-to-many extras, there is currently a way to specify
"exact"
, which essentially purges all past entries and creates new ones following the given inputs, such that all related entries end up equal to the given "exact" set. This is somewhat useful, but I would have expected the following to work as well:This would allow the final related
enemies
set to be equal to the two cats above (removing any prior enemy cats that are not present in that list), where one of the cats gets newly created, and the other was an existing object, which is updated to have a newname
. Right now ingraphene-django-cud
, however, the"auto"
type for"exact"
does not provide a way to specify anid
for the elements inenemies
, so you are forced to delete all past entires and create new ones, without being able to reference/update existing ones in one fell swoop. (I know there's an alternative which is to have separateadd
,remove
, andupdate
fields for theenemies
relation so that you don't always have to "purge" to make updates, but 3 fields instead of 1 is quite a bit more cumbersome to deal with on the client.)For instance, the popular django-rest-framework
drf-writable-nested
library has support for updating such that you can either update existing objects in the set when you provide theirid
or you can create new ones if theid
is omitted (see example here).Is it possible to support something like this, or is it already possible and I've misunderstood how to specify it? Thank you! As always, really appreciate how thorough and convenient this library is!