mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-13 09:42:32 +03:00
Apply camel case converter to field names in DRF errors
This commit is contained in:
parent
775d2e3523
commit
6e77c35381
|
@ -7,6 +7,7 @@ from graphene.types import Field, InputField
|
||||||
from graphene.types.mutation import MutationOptions
|
from graphene.types.mutation import MutationOptions
|
||||||
from graphene.relay.mutation import ClientIDMutation
|
from graphene.relay.mutation import ClientIDMutation
|
||||||
from graphene.types.objecttype import yank_fields_from_attrs
|
from graphene.types.objecttype import yank_fields_from_attrs
|
||||||
|
from graphene.utils.str_converters import to_camel_case
|
||||||
|
|
||||||
from .serializer_converter import convert_serializer_field
|
from .serializer_converter import convert_serializer_field
|
||||||
from ..types import ErrorType
|
from ..types import ErrorType
|
||||||
|
@ -128,7 +129,7 @@ class SerializerMutation(ClientIDMutation):
|
||||||
return cls.perform_mutate(serializer, info)
|
return cls.perform_mutate(serializer, info)
|
||||||
else:
|
else:
|
||||||
errors = [
|
errors = [
|
||||||
ErrorType(field=key, messages=value)
|
ErrorType(field=to_camel_case(key), messages=value)
|
||||||
for key, value in serializer.errors.items()
|
for key, value in serializer.errors.items()
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -211,6 +211,7 @@ 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 len(result.errors) > 0
|
||||||
|
assert result.errors[0].field == 'coolName'
|
||||||
|
|
||||||
|
|
||||||
def test_invalid_serializer_operations():
|
def test_invalid_serializer_operations():
|
||||||
|
|
Loading…
Reference in New Issue
Block a user