15
15
from graphql .error import format_error as format_error_default
16
16
from graphql .execution import ExecutionResult , execute
17
17
from graphql .language import OperationType , parse
18
- from graphql .pyutils import AwaitableOrValue
18
+ from graphql .pyutils import AwaitableOrValue , is_awaitable
19
19
from graphql .type import GraphQLSchema , validate_schema
20
20
from graphql .utilities import get_operation_ast
21
21
from graphql .validation import ASTValidationRule , validate
@@ -99,9 +99,7 @@ def run_http_query(
99
99
100
100
if not is_batch :
101
101
if not isinstance (data , (dict , MutableMapping )):
102
- raise HttpQueryError (
103
- 400 , f"GraphQL params should be a dict. Received { data !r} ."
104
- )
102
+ raise HttpQueryError (400 , f"GraphQL params should be a dict. Received { data !r} ." )
105
103
data = [data ]
106
104
elif not batch_enabled :
107
105
raise HttpQueryError (400 , "Batch GraphQL requests are not enabled." )
@@ -114,15 +112,10 @@ def run_http_query(
114
112
if not is_batch :
115
113
extra_data = query_data or {}
116
114
117
- all_params : List [GraphQLParams ] = [
118
- get_graphql_params (entry , extra_data ) for entry in data
119
- ]
115
+ all_params : List [GraphQLParams ] = [get_graphql_params (entry , extra_data ) for entry in data ]
120
116
121
117
results : List [Optional [AwaitableOrValue [ExecutionResult ]]] = [
122
- get_response (
123
- schema , params , catch_exc , allow_only_query , run_sync , ** execute_options
124
- )
125
- for params in all_params
118
+ get_response (schema , params , catch_exc , allow_only_query , run_sync , ** execute_options ) for params in all_params
126
119
]
127
120
return GraphQLResponse (results , all_params )
128
121
@@ -160,10 +153,7 @@ def encode_execution_results(
160
153
Returns a ServerResponse tuple with the serialized response as the first item and
161
154
a status code of 200 or 400 in case any result was invalid as the second item.
162
155
"""
163
- results = [
164
- format_execution_result (execution_result , format_error )
165
- for execution_result in execution_results
166
- ]
156
+ results = [format_execution_result (execution_result , format_error ) for execution_result in execution_results ]
167
157
result , status_codes = zip (* results )
168
158
status_code = max (status_codes )
169
159
@@ -274,14 +264,11 @@ def get_response(
274
264
if operation != OperationType .QUERY .value :
275
265
raise HttpQueryError (
276
266
405 ,
277
- f"Can only perform a { operation } operation"
278
- " from a POST request." ,
267
+ f"Can only perform a { operation } operation" " from a POST request." ,
279
268
headers = {"Allow" : "POST" },
280
269
)
281
270
282
- validation_errors = validate (
283
- schema , document , rules = validation_rules , max_errors = max_errors
284
- )
271
+ validation_errors = validate (schema , document , rules = validation_rules , max_errors = max_errors )
285
272
if validation_errors :
286
273
return ExecutionResult (data = None , errors = validation_errors )
287
274
@@ -290,7 +277,7 @@ def get_response(
290
277
document ,
291
278
variable_values = params .variables ,
292
279
operation_name = params .operation_name ,
293
- is_awaitable = assume_not_awaitable if run_sync else None ,
280
+ is_awaitable = assume_not_awaitable if run_sync else is_awaitable ,
294
281
** kwargs ,
295
282
)
296
283
@@ -317,9 +304,7 @@ def format_execution_result(
317
304
fe = [format_error (e ) for e in execution_result .errors ] # type: ignore
318
305
response = {"errors" : fe }
319
306
320
- if execution_result .errors and any (
321
- not getattr (e , "path" , None ) for e in execution_result .errors
322
- ):
307
+ if execution_result .errors and any (not getattr (e , "path" , None ) for e in execution_result .errors ):
323
308
status_code = 400
324
309
else :
325
310
response ["data" ] = execution_result .data
0 commit comments