Skip to content

Commit 182782c

Browse files
committed
Removed params from response
1 parent 9cbe59b commit 182782c

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

flask_graphql/graphqlview.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818

1919
GraphQLParams = namedtuple('GraphQLParams', 'query,variables,operation_name,id')
20-
GraphQLResponse = namedtuple('GraphQLResponse', 'result,params,status_code')
20+
GraphQLResponse = namedtuple('GraphQLResponse', 'result,status_code')
2121

2222

2323
class HttpQueryError(Exception):
@@ -51,19 +51,23 @@ def __init__(self, **kwargs):
5151

5252
assert isinstance(self.schema, GraphQLSchema), 'A Schema is required to be provided to GraphQLView.'
5353

54+
# Flask
5455
# noinspection PyUnusedLocal
55-
def get_root_value(self, request):
56+
def get_root_value(self):
5657
return self.root_value
5758

58-
def get_context(self, request):
59+
# Flask
60+
def get_context(self):
5961
if self.context is not None:
6062
return self.context
6163
return request
6264

63-
def get_middleware(self, request):
65+
# Flask
66+
def get_middleware(self):
6467
return self.middleware
6568

66-
def get_executor(self, request):
69+
# Flask
70+
def get_executor(self):
6771
return self.executor
6872

6973
def render_graphiql(self, params, result):
@@ -108,19 +112,20 @@ def dispatch_request(self):
108112
'Batch GraphQL requests are not enabled.'
109113
)
110114

115+
all_params = [self.get_graphql_params(entry) for entry in data]
111116

112117
responses = [self.get_response(
113118
self.schema,
114-
self.get_graphql_params(entry),
119+
params,
115120
catch,
116121
only_allow_query,
117-
root_value=self.get_root_value(request),
118-
context_value=self.get_context(request),
119-
middleware=self.get_middleware(request),
120-
executor=self.get_executor(request),
121-
) for entry in data]
122+
root_value=self.get_root_value(),
123+
context_value=self.get_context(),
124+
middleware=self.get_middleware(),
125+
executor=self.get_executor(),
126+
) for params in all_params]
122127

123-
response, params, status_codes = zip(*responses)
128+
response, status_codes = zip(*responses)
124129
status_code = max(status_codes)
125130

126131
if not is_batch:
@@ -131,7 +136,7 @@ def dispatch_request(self):
131136

132137
if show_graphiql:
133138
return self.render_graphiql(
134-
params=params[0],
139+
params=all_params[0],
135140
result=result
136141
)
137142

@@ -160,14 +165,9 @@ def get_response(self, schema, params, catch=None, only_allow_query=False, **kwa
160165
**kwargs
161166
)
162167
except catch:
163-
execution_result = None
168+
return GraphQLResponse(None, 400)
164169

165-
response, status_code = self.format_execution_result(execution_result, params.id, self.format_error)
166-
return GraphQLResponse(
167-
response,
168-
params,
169-
status_code
170-
)
170+
return self.format_execution_result(execution_result, params.id, self.format_error)
171171

172172
@staticmethod
173173
def format_execution_result(execution_result, id, format_error):
@@ -190,8 +190,9 @@ def format_execution_result(execution_result, id, format_error):
190190
else:
191191
response = None
192192

193-
return response, status_code
193+
return GraphQLResponse(response, status_code)
194194

195+
# Flask
195196
# noinspection PyBroadException
196197
def parse_body(self):
197198
# We use mimetype here since we don't need the other
@@ -267,12 +268,14 @@ def json_encode(data, pretty=False):
267268
separators=(',', ': ')
268269
)
269270

271+
# Flask
270272
def should_display_graphiql(self, data):
271273
if not self.graphiql or 'raw' in data:
272274
return False
273275

274276
return self.request_wants_html()
275277

278+
# Flask
276279
def request_wants_html(self):
277280
best = request.accept_mimetypes \
278281
.best_match(['application/json', 'text/html'])

0 commit comments

Comments
 (0)