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``
101
101
GRAPHENE = {
102
102
' RELAY_CONNECTION_MAX_LIMIT' : 100 ,
103
103
}
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:
53
53
54
54
result = PetMutation .mutate_and_get_payload (None , None )
55
55
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
57
57
result = PetMutation .mutate_and_get_payload (None , None )
58
58
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
60
60
61
61
62
62
class ModelFormMutationTests (TestCase ):
Original file line number Diff line number Diff line change @@ -215,10 +215,10 @@ def test_model_mutate_and_get_payload_error():
215
215
216
216
217
217
def test_mutation_error_camelcased ():
218
- graphene_settings .DJANGO_GRAPHENE_CAMELCASE_ERRORS = True
218
+ graphene_settings .CAMELCASE_ERRORS = True
219
219
result = MyModelMutation .mutate_and_get_payload (None , mock_info (), ** {})
220
220
assert result .errors [0 ].field == "coolName"
221
- graphene_settings .DJANGO_GRAPHENE_CAMELCASE_ERRORS = False
221
+ graphene_settings .CAMELCASE_ERRORS = False
222
222
223
223
224
224
def test_invalid_serializer_operations ():
Original file line number Diff line number Diff line change 35
35
"RELAY_CONNECTION_ENFORCE_FIRST_OR_LAST" : False ,
36
36
# Max items returned in ConnectionFields / FilterConnectionFields
37
37
"RELAY_CONNECTION_MAX_LIMIT" : 100 ,
38
- "DJANGO_GRAPHENE_CAMELCASE_ERRORS " : False ,
38
+ "CAMELCASE_ERRORS " : False ,
39
39
}
40
40
41
41
if settings .DEBUG :
Original file line number Diff line number Diff line change @@ -191,9 +191,5 @@ class ErrorType(ObjectType):
191
191
192
192
@classmethod
193
193
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