17
17
18
18
19
19
GraphQLParams = namedtuple ('GraphQLParams' , 'query,variables,operation_name,id' )
20
+ GraphQLResponse = namedtuple ('GraphQLResponse' , 'result,params,status_code' )
21
+
20
22
21
23
class HttpQueryError (Exception ):
22
24
def __init__ (self , status_code , message = None , is_graphql_error = False , headers = None ):
@@ -85,7 +87,7 @@ def dispatch_request(self):
85
87
}
86
88
)
87
89
88
- data = self .parse_body (request )
90
+ data = self .parse_body ()
89
91
is_batch = isinstance (data , list )
90
92
91
93
show_graphiql = not is_batch and self .should_display_graphiql (data )
@@ -110,7 +112,7 @@ def dispatch_request(self):
110
112
only_allow_query ,
111
113
) for entry in data ]
112
114
113
- response , status_codes = zip (* responses )
115
+ response , params , status_codes = zip (* responses )
114
116
status_code = max (status_codes )
115
117
116
118
if not is_batch :
@@ -120,9 +122,8 @@ def dispatch_request(self):
120
122
result = self .json_encode (response , pretty )
121
123
122
124
if show_graphiql :
123
- params = self .get_graphql_params (data [0 ])
124
125
return self .render_graphiql (
125
- params = params ,
126
+ params = params [ 0 ] ,
126
127
result = result
127
128
)
128
129
@@ -154,7 +155,13 @@ def get_response(self, execute, data, catch=None, only_allow_query=False):
154
155
)
155
156
except catch :
156
157
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
+ )
158
165
159
166
@staticmethod
160
167
def format_execution_result (execution_result , id , format_error ):
@@ -180,7 +187,7 @@ def format_execution_result(execution_result, id, format_error):
180
187
return response , status_code
181
188
182
189
# noinspection PyBroadException
183
- def parse_body (self , request ):
190
+ def parse_body (self ):
184
191
# We use mimetype here since we don't need the other
185
192
# information provided by content_type
186
193
content_type = request .mimetype
0 commit comments