diff --git a/graphene_django/forms/mutation.py b/graphene_django/forms/mutation.py index ecf492c..fd43cbd 100644 --- a/graphene_django/forms/mutation.py +++ b/graphene_django/forms/mutation.py @@ -11,6 +11,7 @@ from graphene.types.mutation import MutationOptions # InputObjectType, # ) from graphene.types.utils import yank_fields_from_attrs +from graphene.utils.str_converters import to_camel_case from graphene_django.registry import get_global_registry from .converter import convert_form_field_with_choices @@ -46,7 +47,7 @@ class BaseDjangoFormMutation(ClientIDMutation): return cls.perform_mutate(form, info) else: errors = [ - ErrorType(field=key, messages=value) + ErrorType(field=to_camel_case(key), messages=value) for key, value in form.errors.items() ] diff --git a/graphene_django/forms/tests/test_mutation.py b/graphene_django/forms/tests/test_mutation.py index 1f39afe..329a7c1 100644 --- a/graphene_django/forms/tests/test_mutation.py +++ b/graphene_django/forms/tests/test_mutation.py @@ -14,6 +14,7 @@ class PetForm(forms.ModelForm): class Meta: model = Pet fields = '__all__' + test_camel = forms.IntegerField(required=False) def test_needs_form_class(): @@ -127,18 +128,20 @@ class ModelFormMutationTests(TestCase): class Meta: form_class = PetForm - result = PetMutation.mutate_and_get_payload(None, None) + result = PetMutation.mutate_and_get_payload(None, None, test_camel='text') # A pet was not created self.assertEqual(Pet.objects.count(), 0) fields_w_error = [e.field for e in result.errors] - self.assertEqual(len(result.errors), 2) + self.assertEqual(len(result.errors), 3) + self.assertIn("testCamel", fields_w_error) + self.assertEqual(result.errors[0].messages, ["Enter a whole number."]) self.assertIn("name", fields_w_error) - self.assertEqual(result.errors[0].messages, ["This field is required."]) - self.assertIn("age", fields_w_error) self.assertEqual(result.errors[1].messages, ["This field is required."]) + self.assertIn("age", fields_w_error) + self.assertEqual(result.errors[2].messages, ["This field is required."]) class FormMutationTests(TestCase):