@@ -65,11 +65,14 @@ def on_resolve(data):
65
65
return ExecutionResult (data = data )
66
66
return ExecutionResult (data = data , errors = context .errors )
67
67
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 ()
68
+ promise = Promise .resolve (None ).then (
69
+ executor ).catch (on_rejected ).then (on_resolve )
70
+
71
+ if not return_promise :
72
+ context .executor .wait_until_finished ()
73
+ return promise .get ()
74
+
75
+ return promise
73
76
74
77
75
78
def execute_operation (exe_context , operation , root_value ):
@@ -122,7 +125,8 @@ def execute_fields(exe_context, parent_type, source_value, fields):
122
125
final_results = OrderedDict ()
123
126
124
127
for response_name , field_asts in fields .items ():
125
- result = resolve_field (exe_context , parent_type , source_value , field_asts )
128
+ result = resolve_field (exe_context , parent_type ,
129
+ source_value , field_asts )
126
130
if result is Undefined :
127
131
continue
128
132
@@ -175,7 +179,8 @@ def resolve_field(exe_context, parent_type, source, field_asts):
175
179
)
176
180
177
181
executor = exe_context .executor
178
- result = resolve_or_error (resolve_fn_middleware , source , info , args , executor )
182
+ result = resolve_or_error (resolve_fn_middleware ,
183
+ source , info , args , executor )
179
184
180
185
return complete_value_catching_error (
181
186
exe_context ,
@@ -206,7 +211,8 @@ def complete_value_catching_error(exe_context, return_type, field_asts, info, re
206
211
# Otherwise, error protection is applied, logging the error and
207
212
# resolving a null value for this field if one is encountered.
208
213
try :
209
- completed = complete_value (exe_context , return_type , field_asts , info , result )
214
+ completed = complete_value (
215
+ exe_context , return_type , field_asts , info , result )
210
216
if is_thenable (completed ):
211
217
def handle_error (error ):
212
218
traceback = completed ._traceback
@@ -241,7 +247,8 @@ def complete_value(exe_context, return_type, field_asts, info, result):
241
247
Otherwise, the field type expects a sub-selection set, and will complete the value by evaluating all
242
248
sub-selections.
243
249
"""
244
- # If field type is NonNull, complete for inner type, and throw field error if result is null.
250
+ # If field type is NonNull, complete for inner type, and throw field error
251
+ # if result is null.
245
252
246
253
if is_thenable (result ):
247
254
return Promise .resolve (result ).then (
@@ -252,7 +259,8 @@ def complete_value(exe_context, return_type, field_asts, info, result):
252
259
info ,
253
260
resolved
254
261
),
255
- lambda error : Promise .rejected (GraphQLLocatedError (field_asts , original_error = error ))
262
+ lambda error : Promise .rejected (
263
+ GraphQLLocatedError (field_asts , original_error = error ))
256
264
)
257
265
258
266
# print return_type, type(result)
@@ -270,7 +278,8 @@ def complete_value(exe_context, return_type, field_asts, info, result):
270
278
if isinstance (return_type , GraphQLList ):
271
279
return complete_list_value (exe_context , return_type , field_asts , info , result )
272
280
273
- # If field type is Scalar or Enum, serialize to a valid value, returning null if coercion is not possible.
281
+ # If field type is Scalar or Enum, serialize to a valid value, returning
282
+ # null if coercion is not possible.
274
283
if isinstance (return_type , (GraphQLScalarType , GraphQLEnumType )):
275
284
return complete_leaf_value (return_type , result )
276
285
@@ -280,7 +289,8 @@ def complete_value(exe_context, return_type, field_asts, info, result):
280
289
if isinstance (return_type , GraphQLObjectType ):
281
290
return complete_object_value (exe_context , return_type , field_asts , info , result )
282
291
283
- assert False , u'Cannot complete value of unexpected type "{}".' .format (return_type )
292
+ assert False , u'Cannot complete value of unexpected type "{}".' .format (
293
+ return_type )
284
294
285
295
286
296
def complete_list_value (exe_context , return_type , field_asts , info , result ):
@@ -295,7 +305,8 @@ def complete_list_value(exe_context, return_type, field_asts, info, result):
295
305
completed_results = []
296
306
contains_promise = False
297
307
for item in result :
298
- completed_item = complete_value_catching_error (exe_context , item_type , field_asts , info , item )
308
+ completed_item = complete_value_catching_error (
309
+ exe_context , item_type , field_asts , info , item )
299
310
if not contains_promise and is_thenable (completed_item ):
300
311
contains_promise = True
301
312
@@ -326,7 +337,8 @@ def complete_abstract_value(exe_context, return_type, field_asts, info, result):
326
337
if return_type .resolve_type :
327
338
runtime_type = return_type .resolve_type (result , info )
328
339
else :
329
- runtime_type = get_default_resolve_type_fn (result , info , return_type )
340
+ runtime_type = get_default_resolve_type_fn (
341
+ result , info , return_type )
330
342
331
343
if isinstance (runtime_type , string_types ):
332
344
runtime_type = info .schema .get_type (runtime_type )
@@ -340,13 +352,14 @@ def complete_abstract_value(exe_context, return_type, field_asts, info, result):
340
352
info .field_name ,
341
353
result ,
342
354
runtime_type ,
343
- ),
355
+ ),
344
356
field_asts
345
357
)
346
358
347
359
if not exe_context .schema .is_possible_type (return_type , runtime_type ):
348
360
raise GraphQLError (
349
- u'Runtime Object type "{}" is not a possible type for "{}".' .format (runtime_type , return_type ),
361
+ u'Runtime Object type "{}" is not a possible type for "{}".' .format (
362
+ runtime_type , return_type ),
350
363
field_asts
351
364
)
352
365
@@ -366,7 +379,8 @@ def complete_object_value(exe_context, return_type, field_asts, info, result):
366
379
"""
367
380
if return_type .is_type_of and not return_type .is_type_of (result , info ):
368
381
raise GraphQLError (
369
- u'Expected value of type "{}" but got: {}.' .format (return_type , type (result ).__name__ ),
382
+ u'Expected value of type "{}" but got: {}.' .format (
383
+ return_type , type (result ).__name__ ),
370
384
field_asts
371
385
)
372
386
@@ -384,7 +398,8 @@ def complete_nonnull_value(exe_context, return_type, field_asts, info, result):
384
398
)
385
399
if completed is None :
386
400
raise GraphQLError (
387
- 'Cannot return null for non-nullable field {}.{}.' .format (info .parent_type , info .field_name ),
401
+ 'Cannot return null for non-nullable field {}.{}.' .format (
402
+ info .parent_type , info .field_name ),
388
403
field_asts
389
404
)
390
405
0 commit comments