mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-13 17:52:19 +03:00
Return correct errors
This commit is contained in:
parent
98a9c7161d
commit
942bb6c7e0
|
@ -140,12 +140,10 @@ class SerializerMutation(ClientIDMutation):
|
|||
if serializer.is_valid():
|
||||
return cls.perform_mutate(serializer, info)
|
||||
else:
|
||||
errors = [
|
||||
ErrorType(field=key, messages=value)
|
||||
for key, value in serializer.errors.items()
|
||||
]
|
||||
# TODO: make sure that we have the correct value for
|
||||
# non field errors
|
||||
|
||||
return cls(errors=errors)
|
||||
return cls(errors=cls.Errors(**serializer.errors))
|
||||
|
||||
@classmethod
|
||||
def perform_mutate(cls, serializer, info):
|
||||
|
|
|
@ -159,13 +159,14 @@ def test_mutate_and_get_payload_error():
|
|||
|
||||
# missing required fields
|
||||
result = MyMutation.mutate_and_get_payload(None, mock_info(), **{})
|
||||
assert len(result.errors) > 0
|
||||
assert result.errors.text[0] == "This field is required."
|
||||
assert result.errors.model[0] == "This field is required."
|
||||
|
||||
|
||||
def test_model_mutate_and_get_payload_error():
|
||||
# missing required fields
|
||||
result = MyModelMutation.mutate_and_get_payload(None, mock_info(), **{})
|
||||
assert len(result.errors) > 0
|
||||
assert result.errors.cool_name[0] == "This field is required."
|
||||
|
||||
|
||||
def test_invalid_serializer_operations():
|
||||
|
|
Loading…
Reference in New Issue
Block a user