mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-14 02:02:20 +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():
|
if serializer.is_valid():
|
||||||
return cls.perform_mutate(serializer, info)
|
return cls.perform_mutate(serializer, info)
|
||||||
else:
|
else:
|
||||||
errors = [
|
# TODO: make sure that we have the correct value for
|
||||||
ErrorType(field=key, messages=value)
|
# non field errors
|
||||||
for key, value in serializer.errors.items()
|
|
||||||
]
|
|
||||||
|
|
||||||
return cls(errors=errors)
|
return cls(errors=cls.Errors(**serializer.errors))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def perform_mutate(cls, serializer, info):
|
def perform_mutate(cls, serializer, info):
|
||||||
|
|
|
@ -159,13 +159,14 @@ def test_mutate_and_get_payload_error():
|
||||||
|
|
||||||
# missing required fields
|
# missing required fields
|
||||||
result = MyMutation.mutate_and_get_payload(None, mock_info(), **{})
|
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():
|
def test_model_mutate_and_get_payload_error():
|
||||||
# missing required fields
|
# missing required fields
|
||||||
result = MyModelMutation.mutate_and_get_payload(None, mock_info(), **{})
|
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():
|
def test_invalid_serializer_operations():
|
||||||
|
|
Loading…
Reference in New Issue
Block a user