8000 Added GraphQLResponse structure · graphql-python/flask-graphql@31fcca5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 31fcca5

Browse files
committed
Added GraphQLResponse structure
1 parent fab7f04 commit 31fcca5

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

flask_graphql/graphqlview.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818

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

2123
class HttpQueryError(Exception):
2224
def __init__(self, status_code, message=None, is_graphql_error=False, headers=None):
@@ -85,7 +87,7 @@ def dispatch_request(self):
8587
}
8688
)
8789

88-
data = self.parse_body(request)
90+
data = self.parse_body()
8991
is_batch = isinstance(data, list)
9092

9193
show_graphiql = not is_batch and self.should_display_graphiql(data)
@@ -110,7 +112,7 @@ def dispatch_request(self):
110112
only_allow_query,
111113
) for entry in data]
112114

113-
response, status_codes = zip(*responses)
115+
response, params, status_codes = zip(*responses)
114116
status_code = max(status_codes)
115117

116118
if not is_batch:
@@ -120,9 +122,8 @@ def dispatch_request(self):
120122
result = self.json_encode(response, pretty)
121123

122124
if show_graphiql:
123-
params = self.get_graphql_params(data[0])
124125
return self.render_graphiql(
125-
params=params,
126+
params=params[0],
126127
result=result
127128
)
128129

@@ -154,7 +155,13 @@ def get_response(self, execute, data, catch=None, only_allow_query=False):
154155
)
155156
except catch:
156157
execution_result = None
157-
return self.format_execution_result(execution_result, params.id, self.format_error)
158+
159+
response, status_code = self.format_execution_result(execution_result, params.id, self.format_error)
160+
return GraphQLResponse(
161+
response,
162+
params,
163+
status_code
164+
)
158165

159166
@staticmethod
160167
def format_execution_result(execution_result, id, format_error):
@@ -180,7 +187,7 @@ def format_execution_result(execution_result, id, format_error):
180187
return response, status_code
181188

182189
# noinspection PyBroadException
183-
def parse_body(self, request):
190+
def parse_body(self):
184191
# We use mimetype here since we don't need the other
185192
# information provided by content_type
186193
content_type = request.mimetype

0 commit comments

Comments
 (0)
0