Django + Graphene + DjangoModelFormMutation : dissociating create and update
I am using a DjangoModelFormMutation from Graphene-python to expose a generic mutation for a model, like so :
from graphene import Field
from graphene_django.forms.mutation import DjangoModelFormMutation
from django.db import models
class Pet(models.Model):
name = models.CharField()
legs = models.PositiveIntegerField()
class PetForm(forms.ModelForm):
class Meta:
model = Pet
fields = ('name', 'legs')
# This will get returned when the mutation completes successfully
class PetType(DjangoObjectType):
class Meta:
model = Pet
class PetMutation(DjangoModelFormMutation):
pet = Field(PetType)
class Meta:
form_class = PetForm
Then in my schema file, I register the mutation like this :
create_pet = mutations.PetMutation.Field()
update_pet = mutations.PetMutation.Field()
This works, but there are two desired behaviors I can't achieve this way :
- Have two different mutations : one for create that can only create and not update, and one for update that can only update, and not create.
- Have the update mutation work partially as well , i.e only updating the client-provided fields.
How can I achieve the desired behavior ?