23
23
24
24
25
25
def execute (schema , document_ast , root_value = None , context_value = None ,
26
- variable_values = None , operation_name = None , executor = None ,
27
- return_promise = False , middleware = None ):
26
+ variable_values = None , operation_name = None , executor = None , middleware = None ):
28
27
assert schema , 'Must provide schema'
29
28
assert isinstance (schema , GraphQLSchema ), (
30
29
'Schema must be an instance of GraphQLSchema. Also ensure that there are ' +
@@ -65,11 +64,7 @@ def on_resolve(data):
65
64
return ExecutionResult (data = data )
66
65
return ExecutionResult (data = data , errors = context .errors )
67
66
68
- promise = Promise .resolve (None ).then (executor ).catch (on_rejected ).then (on_resolve )
69
- if return_promise :
70
- return promise
71
- context .executor .wait_until_finished ()
72
- return promise .get ()
67
+ return Promise .resolve (None ).then (executor ).catch (on_rejected ).then (on_resolve )
73
68
74
69
75
70
def execute_operation (exe_context , operation , root_value ):
@@ -122,7 +117,8 @@ def execute_fields(exe_context, parent_type, source_value, fields):
122
117
final_results = OrderedDict ()
123
118
124
119
for response_name , field_asts in fields .items ():
125
- result = resolve_field (exe_context , parent_type , source_value , field_asts )
120
+ result = resolve_field (exe_context , parent_type ,
121
+ source_value , field_asts )
126
122
if result is Undefined :
127
123
continue
128
124
@@ -175,7 +171,8 @@ def resolve_field(exe_context, parent_type, source, field_asts):
175
171
)
176
172
177
173
executor = exe_context .executor
178
- result = resolve_or_error (resolve_fn_middleware , source , info , args , executor )
174
+ result = resolve_or_error (resolve_fn_middleware ,
175
+ source , info , args , executor )
179
176
180
177
return complete_value_catching_error (
181
178
exe_context ,
@@ -206,7 +203,8 @@ def complete_value_catching_error(exe_context, return_type, field_asts, info, re
206
203
# Otherwise, error protection is applied, logging the error and
207
204
# resolving a null value for this field if one is encountered.
208
205
try :
209
- completed = complete_value (exe_context , return_type , field_asts , info , result )
206
+ completed = complete_value (
207
+ exe_context , return_type , field_asts , info , result )
210
208
if is_thenable (completed ):
211
209
def handle_error (error ):
212
210
traceback = completed ._traceback
@@ -241,7 +239,8 @@ def complete_value(exe_context, return_type, field_asts, info, result):
241
239
Otherwise, the field type expects a sub-selection set, and will complete the value by evaluating all
242
240
sub-selections.
243
241
"""
244
- # If field type is NonNull, complete for inner type, and throw field error if result is null.
242
+ # If field type is NonNull, complete for inner type, and throw field error
243
+ # if result is null.
245
244
246
245
if is_thenable (result ):
247
246
return Promise .resolve (result ).then (
@@ -252,7 +251,8 @@ def complete_value(exe_context, return_type, field_asts, info, result):
252
251
info ,
253
252
resolved
254
253
),
255
- lambda error : Promise .rejected (GraphQLLocatedError (field_asts , original_error = error ))
254
+ lambda error : Promise .rejected (
255
+ GraphQLLocatedError (field_asts , original_error = error ))
256
256
)
257
257
258
258
# print return_type, type(result)
@@ -270,7 +270,8 @@ def complete_value(exe_context, return_type, field_asts, info, result):
270
270
if isinstance (return_type , GraphQLList ):
271
271
return complete_list_value (exe_context , return_type , field_asts , info , result )
272
272
273
- # If field type is Scalar or Enum, serialize to a valid value, returning null if coercion is not possible.
273
+ # If field type is Scalar or Enum, serialize to a valid value, returning
274
+ # null if coercion is not possible.
274
275
if isinstance (return_type , (GraphQLScalarType , GraphQLEnumType )):
275
276
return complete_leaf_value (return_type , result )
276
277
@@ -280,7 +281,8 @@ def complete_value(exe_context, return_type, field_asts, info, result):
280
281
if isinstance (return_type , GraphQLObjectType ):
281
282
return complete_object_value (exe_context , return_type , field_asts , info , result )
282
283
283
- assert False , u'Cannot complete value of unexpected type "{}".' .format (return_type )
284
+ assert False , u'Cannot complete value of unexpected type "{}".' .format (
285
+ return_type )
284
286
285
287
286
288
def complete_list_value (exe_context , return_type , field_asts , info , result ):
@@ -295,7 +297,8 @@ def complete_list_value(exe_context, return_type, field_asts, info, result):
295
297
completed_results = []
296
298
contains_promise = False
297
299
for item in result :
298
- completed_item = complete_value_catching_error (exe_context , item_type , field_asts , info , item )
300
+ completed_item = complete_value_catching_error (
301
+ exe_context , item_type , field_asts , info , item )
299
302
if not contains_promise and is_thenable (completed_item ):
300
303
contains_promise = True
301
304
@@ -326,7 +329,8 @@ def complete_abstract_value(exe_context, return_type, field_asts, info, result):
326
329
if return_type .resolve_type :
327
330
runtime_type = return_type .resolve_type (result , info )
328
331
else :
329
- runtime_type = get_default_resolve_type_fn (result , info , return_type )
332
+ runtime_type = get_default_resolve_type_fn (
333
+ result , info , return_type )
330
334
331
335
if isinstance (runtime_type , string_types ):
332
336
runtime_type = info .schema .get_type (runtime_type )
@@ -340,13 +344,14 @@ def complete_abstract_value(exe_context, return_type, field_asts, info, result):
340
344
info .field_name ,
341
345
result ,
342
346
runtime_type ,
343
- ),
347
+ ),
344
348
field_asts
345
349
)
346
350
347
351
if not exe_context .schema .is_possible_type (return_type , runtime_type ):
348
352
raise GraphQLError (
349
- u'Runtime Object type "{}" is not a possible type for "{}".' .format (runtime_type , return_type ),
353
+ u'Runtime Object type "{}" is not a possible type for "{}".' .format (
354
+ runtime_type , return_type ),
350
355
field_asts
351
356
)
352
357
@@ -366,7 +371,8 @@ def complete_object_value(exe_context, return_type, field_asts, info, result):
366
371
"""
367
372
if return_type .is_type_of and not return_type .is_type_of (result , info ):
368
373
raise GraphQLError (
369
- u'Expected value of type "{}" but got: {}.' .format (return_type , type (result ).__name__ ),
374
+ u'Expected value of type "{}" but got: {}.' .format (
375
+ return_type , type (result ).__name__ ),
370
376
field_asts
371
377
)
372
378
@@ -384,7 +390,8 @@ def complete_nonnull_value(exe_context, return_type, field_asts, info, result):
384
390
)
385
391
if completed is None :
386
392
raise GraphQLError (
387
- 'Cannot return null for non-nullable field {}.{}.' .format (info .parent_type , info .field_name ),
393
+ 'Cannot return null for non-nullable field {}.{}.' .format (
394
+ info .parent_type , info .field_name ),
388
395
field_asts
389
396
)
390
397
0 commit comments