8000 Improved query params retreival · graphql-python/flask-graphql@258af89 · GitHub
[go: up one dir, main page]

Skip to content

Commit 258af89

Browse files
committed
Improved query params retreival
1 parent c3c9ad4 commit 258af89

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

flask_graphql/graphqlview.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,20 @@ def dispatch_request(self):
8181
)
8282

8383
data = self.parse_body(request)
84+
is_batch = isinstance(data, list)
8485

85-
show_graphiql = self.graphiql and self.can_display_graphiql(data)
86+
show_graphiql = not is_batch and self.graphiql and self.can_display_graphiql(data)
8687

87-
is_batch = isinstance(data, list)
88-
if is_batch:
89-
if not self.batch or show_graphiql:
90-
raise HttpError(
91-
400,
92-
'Batch requests are not allowed.'
93-
)
94-
else:
88+
if not is_batch:
89+
# print data
90+
data = dict(data, **request.args.to_dict())
9591
data = [data]
92+
elif not self.batch:
93+
raise HttpError(
94+
400,
95+
'Batch requests are not allowed.'
96+
)
97+
9698
responses = [self.get_response(request, entry, show_graphiql) for entry in data]
9799
response, status_codes = zip(*responses)
98100
status_code = max(status_codes)
@@ -185,10 +187,10 @@ def parse_body(self, request):
185187
)
186188

187189
elif content_type == 'application/x-www-form-urlencoded':
188-
return request.form
190+
return request.form.to_dict()
189191

190192
elif content_type == 'multipart/form-data':
191-
return request.form
193+
return request.form.to_dict()
192194

193195
return {}
194196

@@ -254,8 +256,8 @@ def request_wants_html(cls, request):
254256

255257
@staticmethod
256258
def get_graphql_params(request, data):
257-
query = request.args.get('query') or data.get('query')
258-
variables = request.args.get('variables') or data.get('variables')
259+
query = data.get('query')
260+
variables = data.get('variables')
259261
id = data.get('id')
260262

261263
if variables and isinstance(variables, six.text_type):
@@ -264,7 +266,7 @@ def get_graphql_params(request, data):
264266
except:
265267
raise HttpError(400, 'Variables are invalid JSON.')
266268

267-
operation_name = request.args.get('operationName') or data.get('operationName')
269+
operation_name = data.get('operationName')
268270

269271
return query, variables, operation_name, id
270272

0 commit comments

Comments
 (0)
0