graphql-python / graphql-python/graphene-django

How to perform partial update using mutation?

Open
#935 4 comments 6 reactions 0 assignees View on GitHub
✨enhancement
Dominant language
Python
Stars
4.4k
Forks
760
PR merge metrics
No merged PRs in 30d

Description

I'm trying to perform partial update using graphene. I'm following [docs for serializers](https://docs.graphene-python.org/projects/django/en/latest/mutations/#create-update-operations), but I can't run the mutation, because of required fields. Here's an example.

**Serializer**
```python
class StudySerializer(serializers.ModelSerializer):
class Meta:
model = Study
fields = '__all__'
# required for accepting "id" in mutation's arguments
# see https://github.com/graphql-python/graphene-django/issues/906#issuecomment-602078174
extra_kwargs = {'id': {'read_only': False, 'required': False}}
```

**Mutation**
```python
class UpdateStudy(SerializerMutation):
class Meta:
serializer_class = StudySerializer
model_operations = ['update']
```

GraphQL is complaining about missing fields in mutation, but they should be optional

![Screenshot 2020-04-16 at 15 07 52](https://user-images.githubusercontent.com/3169629/79459823-2fdd4700-7ff4-11ea-8beb-7fc6ba2a417f.png)

Is there any workaround for this?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.