mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-22 01:27:01 +03:00
added support for partial updates in serializers (#731)
* added support for partial updates in serializers * Add test to verify partial updates Co-authored-by: Jonathan Kim <jkimbo@gmail.com>
This commit is contained in:
parent
45df7445f4
commit
7940a7b954
|
@ -102,8 +102,10 @@ class SerializerMutation(ClientIDMutation):
|
|||
instance = get_object_or_404(
|
||||
model_class, **{lookup_field: input[lookup_field]}
|
||||
)
|
||||
partial = True
|
||||
elif "create" in cls._meta.model_operations:
|
||||
instance = None
|
||||
partial = False
|
||||
else:
|
||||
raise Exception(
|
||||
'Invalid update operation. Input parameter "{}" required.'.format(
|
||||
|
@ -115,6 +117,7 @@ class SerializerMutation(ClientIDMutation):
|
|||
"instance": instance,
|
||||
"data": input,
|
||||
"context": {"request": info.context},
|
||||
"partial": partial,
|
||||
}
|
||||
|
||||
return {"data": input, "context": {"request": info.context}}
|
||||
|
|
|
@ -183,6 +183,16 @@ def test_model_update_mutate_and_get_payload_success():
|
|||
assert result.cool_name == "New Narf"
|
||||
|
||||
|
||||
@mark.django_db
|
||||
def test_model_partial_update_mutate_and_get_payload_success():
|
||||
instance = MyFakeModel.objects.create(cool_name="Narf")
|
||||
result = MyModelMutation.mutate_and_get_payload(
|
||||
None, mock_info(), **{"id": instance.id}
|
||||
)
|
||||
assert result.errors is None
|
||||
assert result.cool_name == "Narf"
|
||||
|
||||
|
||||
@mark.django_db
|
||||
def test_model_invalid_update_mutate_and_get_payload_success():
|
||||
class InvalidModelMutation(SerializerMutation):
|
||||
|
|
Loading…
Reference in New Issue
Block a user