Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5051d3b

Browse files
Fixed lint
1 parent de39473 commit 5051d3b

File tree

1 file changed

+35
-18
lines changed

1 file changed

+35
-18
lines changed

‎graphene_django/views.py‎

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ def __init__(self, schema=None, executor=None, middleware=None, root_value=None,
8181
self.graphiql = graphiql
8282
self.batch = batch
8383

84-
assert isinstance(self.schema, GraphQLSchema), 'A Schema is required to be provided to GraphQLView.'
85-
assert not all((graphiql, batch)), 'Use either graphiql or batch processing'
84+
assert isinstance(
85+
self.schema, GraphQLSchema), 'A Schema is required to be provided to GraphQLView.'
86+
assert not all((graphiql, batch)
87+
), 'Use either graphiql or batch processing'
8688

8789
# noinspection PyUnusedLocal
8890
def get_root_value(self, request):
@@ -98,20 +100,27 @@ def get_context(self, request):
98100
def dispatch(self, request, *args, **kwargs):
99101
try:
100102
if request.method.lower() not in ('get', 'post'):
101-
raise HttpError(HttpResponseNotAllowed(['GET', 'POST'], 'GraphQL only supports GET and POST requests.'))
103+
raise HttpError(HttpResponseNotAllowed(
104+
['GET', 'POST'], 'GraphQL only supports GET and POST requests.'))
102105

103106
data = self.parse_body(request)
104-
show_graphiql = self.graphiql and self.can_display_graphiql(request, data)
107+
show_graphiql = self.graphiql and self.can_display_graphiql(
108+
request, data)
105109

106110
if self.batch:
107-
responses = [self.get_response(request, entry) for entry in data]
108-
result = '[{}]'.format(','.join([response[0] for response in responses]))
109-
status_code = max(responses, key=lambda response: response[1])[1]
111+
responses = [self.get_response(
112+
request, entry) for entry in data]
113+
result = '[{}]'.format(
114+
','.join([response[0] for response in responses]))
115+
status_code = max(
116+
responses, key=lambda response: response[1])[1]
110117
else:
111-
result, status_code = self.get_response(request, data, show_graphiql)
118+
result, status_code = self.get_response(
119+
request, data, show_graphiql)
112120

113121
if show_graphiql:
114-
query, variables, operation_name, id = self.get_graphql_params(request, data)
122+
query, variables, operation_name, id = self.get_graphql_params(
123+
request, data)
115124
return self.render_graphiql(
116125
request,
117126
graphiql_version=self.graphiql_version,
@@ -136,7 +145,8 @@ def dispatch(self, request, *args, **kwargs):
136145
return response
137146

138147
def get_response(self, request, data, show_graphiql=False):
139-
query, variables, operation_name, id = self.get_graphql_params(request, data)
148+
query, variables, operation_name, id = self.get_graphql_params(
149+
request, data)
140150

141151
execution_result = self.execute_graphql_request(
142152
request,
@@ -152,7 +162,8 @@ def get_response(self, request, data, show_graphiql=False):
152162
response = {}
153163

154164
if execution_result.errors:
155-
response['errors'] = [self.format_error(e) for e in execution_result.errors]
165+
response['errors'] = [self.format_error(
166+
e) for e in execution_result.errors]
156167

157168
if execution_result.invalid:
158169
status_code = 400
@@ -209,7 +220,8 @@ def parse_body(self, request):
209220
except AssertionError as e:
210221
raise HttpError(HttpResponseBadRequest(str(e)))
211222
except (TypeError, ValueError):
212-
raise HttpError(HttpResponseBadRequest('POST body sent invalid JSON.'))
223+
raise HttpError(HttpResponseBadRequest(
224+
'POST body sent invalid JSON.'))
213225

214226
elif content_type in ['application/x-www-form-urlencoded', 'multipart/form-data']:
215227
return request.POST
@@ -223,7 +235,8 @@ def execute_graphql_request(self, request, data, query, variables, operation_nam
223235
if not query:
224236
if show_graphiql:
225237
return None
226-
raise HttpError(HttpResponseBadRequest('Must provide query string.'))
238+
raise HttpError(HttpResponseBadRequest(
239+
'Must provide query string.'))
227240

228241
source = Source(query, name='GraphQL request')
229242

@@ -245,7 +258,8 @@ def execute_graphql_request(self, request, data, query, variables, operation_nam
245258
return None
246259

247260
raise HttpError(HttpResponseNotAllowed(
248-
['POST'], 'Can only perform a {} operation from a POST request.'.format(operation_ast.operation)
261+
['POST'], 'Can only perform a {} operation from a POST request.'.format(
262+
operation_ast.operation)
249263
))
250264

251265
try:
@@ -283,10 +297,12 @@ def get_graphql_params(request, data):
283297
if variables and isinstance(variables, six.text_type):
284298
try:
285299
variables = json.loads(variables)
286-
except:
287-
raise HttpError(HttpResponseBadRequest('Variables are invalid JSON.'))
300+
except Exception:
301+
raise HttpError(HttpResponseBadRequest(
302+
'Variables are invalid JSON.'))
288303

289-
operation_name = request.GET.get('operationName') or data.get('operationName')
304+
operation_name = request.GET.get(
305+
'operationName') or data.get('operationName')
290306
if operation_name == "null":
291307
operation_name = None
292308

@@ -302,5 +318,6 @@ def format_error(error):
302318
@staticmethod
303319
def get_content_type(request):
304320
meta = request.META
305-
content_type = meta.get('CONTENT_TYPE', meta.get('HTTP_CONTENT_TYPE', ''))
321+
content_type = meta.get(
322+
'CONTENT_TYPE', meta.get('HTTP_CONTENT_TYPE', ''))
306323
return content_type.split(';', 1)[0].lower()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /