Skip to content

Commit 6e77c35

Browse files
committed
Apply camel case converter to field names in DRF errors
1 parent 775d2e3 commit 6e77c35

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

graphene_django/rest_framework/mutation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from graphene.types.mutation import MutationOptions
88
from graphene.relay.mutation import ClientIDMutation
99
from graphene.types.objecttype import yank_fields_from_attrs
10+
from graphene.utils.str_converters import to_camel_case
1011

1112
from .serializer_converter import convert_serializer_field
1213
from ..types import ErrorType
@@ -128,7 +129,7 @@ def mutate_and_get_payload(cls, root, info, **input):
128129
return cls.perform_mutate(serializer, info)
129130
else:
130131
errors = [
131-
ErrorType(field=key, messages=value)
132+
ErrorType(field=to_camel_case(key), messages=value)
132133
for key, value in serializer.errors.items()
133134
]
134135

graphene_django/rest_framework/tests/test_mutation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ def test_model_mutate_and_get_payload_error():
211211
# missing required fields
212212
result = MyModelMutation.mutate_and_get_payload(None, mock_info(), **{})
213213
assert len(result.errors) > 0
214+
assert result.errors[0].field == 'coolName'
214215

215216

216217
def test_invalid_serializer_operations():

0 commit comments

Comments
 (0)