File tree Expand file tree Collapse file tree 5 files changed +46
-11
lines changed Expand file tree Collapse file tree 5 files changed +46
-11
lines changed Original file line number Diff line number Diff line change @@ -101,3 +101,42 @@ Default: ``100``
101101 GRAPHENE = {
102102 ' RELAY_CONNECTION_MAX_LIMIT' : 100 ,
103103 }
104+
105+
106+ ``CAMELCASE_ERRORS ``
107+ ------------------------------------
108+
109+ When set to ``True `` field names in the ``errors `` object will be camel case.
110+ By default they will be snake case.
111+
112+ Default: ``False ``
113+
114+ .. code :: python
115+
116+ GRAPHENE = {
117+ ' CAMELCASE_ERRORS' : False ,
118+ }
119+
120+ # result = schema.execute(...)
121+ print (result.errors)
122+ # [
123+ # {
124+ # 'field': 'test_field',
125+ # 'messages': ['This field is required.'],
126+ # }
127+ # ]
128+
129+ .. code :: python
130+
131+ GRAPHENE = {
132+ ' CAMELCASE_ERRORS' : True ,
133+ }
134+
135+ # result = schema.execute(...)
136+ print (result.errors)
137+ # [
138+ # {
139+ # 'field': 'testField',
140+ # 'messages': ['This field is required.'],
141+ # }
142+ # ]
Original file line number Diff line number Diff line change @@ -53,10 +53,10 @@ class Meta:
5353
5454 result = PetMutation .mutate_and_get_payload (None , None )
5555 assert {f .field for f in result .errors } == {"name" , "age" , "test_field" }
56- graphene_settings .DJANGO_GRAPHENE_CAMELCASE_ERRORS = True
56+ graphene_settings .CAMELCASE_ERRORS = True
5757 result = PetMutation .mutate_and_get_payload (None , None )
5858 assert {f .field for f in result .errors } == {"name" , "age" , "testField" }
59- graphene_settings .DJANGO_GRAPHENE_CAMELCASE_ERRORS = False
59+ graphene_settings .CAMELCASE_ERRORS = False
6060
6161
6262class ModelFormMutationTests (TestCase ):
Original file line number Diff line number Diff line change @@ -215,10 +215,10 @@ def test_model_mutate_and_get_payload_error():
215215
216216
217217def test_mutation_error_camelcased ():
218- graphene_settings .DJANGO_GRAPHENE_CAMELCASE_ERRORS = True
218+ graphene_settings .CAMELCASE_ERRORS = True
219219 result = MyModelMutation .mutate_and_get_payload (None , mock_info (), ** {})
220220 assert result .errors [0 ].field == "coolName"
221- graphene_settings .DJANGO_GRAPHENE_CAMELCASE_ERRORS = False
221+ graphene_settings .CAMELCASE_ERRORS = False
222222
223223
224224def test_invalid_serializer_operations ():
Original file line number Diff line number Diff line change 3535 "RELAY_CONNECTION_ENFORCE_FIRST_OR_LAST" : False ,
3636 # Max items returned in ConnectionFields / FilterConnectionFields
3737 "RELAY_CONNECTION_MAX_LIMIT" : 100 ,
38- "DJANGO_GRAPHENE_CAMELCASE_ERRORS " : False ,
38+ "CAMELCASE_ERRORS " : False ,
3939}
4040
4141if settings .DEBUG :
Original file line number Diff line number Diff line change @@ -191,9 +191,5 @@ class ErrorType(ObjectType):
191191
192192 @classmethod
193193 def from_errors (cls , errors ):
194- data = (
195- camelize (errors )
196- if graphene_settings .DJANGO_GRAPHENE_CAMELCASE_ERRORS
197- else errors
198- )
199- return [ErrorType (field = key , messages = value ) for key , value in data .items ()]
194+ data = camelize (errors ) if graphene_settings .CAMELCASE_ERRORS else errors
195+ return [cls (field = key , messages = value ) for key , value in data .items ()]
You can’t perform that action at this time.
0 commit comments