@@ -36,6 +36,7 @@ def execute(schema, document_ast, root_value=None, context_value=None,
36
36
'Schema must be an instance of GraphQLSchema. Also ensure that there are ' +
37
37
'not multiple versions of GraphQL installed in your node_modules directory.'
38
38
)
39
+
39
40
if middleware :
40
41
if not isinstance (middleware , MiddlewareManager ):
41
42
middleware = MiddlewareManager (* middleware )
@@ -73,10 +74,10 @@ def on_resolve(data):
73
74
74
75
if not context .errors :
75
76
return ExecutionResult (data = data )
77
+
76
78
return ExecutionResult (data = data , errors = context .errors )
77
79
78
- promise = Promise .resolve (None ).then (
79
- executor ).catch (on_rejected ).then (on_resolve )
80
+ promise = Promise .resolve (None ).then (executor ).catch (on_rejected ).then (on_resolve )
80
81
81
82
if not return_promise :
82
83
context .executor .wait_until_finished ()
@@ -107,7 +108,7 @@ def execute_operation(exe_context, operation, root_value):
107
108
)
108
109
return subscribe_fields (exe_context , type , root_value , fields )
109
110
110
- return execute_fields (exe_context , type , root_value , fields )
111
+ return execute_fields (exe_context , type , root_value , fields , None )
111
112
112
113
113
114
def execute_fields_serially (exe_context , parent_type , source_value , fields ):
@@ -117,7 +118,8 @@ def execute_field_callback(results, response_name):
117
118
exe_context ,
118
119
parent_type ,
119
120
source_value ,
120
- field_asts
121
+ field_asts ,
122
+ None
121
123
)
122
124
if result is Undefined :
123
125
return results
@@ -138,14 +140,13 @@ def execute_field(prev_promise, response_name):
138
140
return functools .reduce (execute_field , fields .keys (), Promise .resolve (collections .OrderedDict ()))
139
141
140
142
141
- def execute_fields (exe_context , parent_type , source_value , fields ):
143
+ def execute_fields (exe_context , parent_type , source_value , fields , info ):
142
144
contains_promise = False
143
145
144
146
final_results = OrderedDict ()
145
147
146
148
for response_name , field_asts in fields .items ():
147
- result = resolve_field (exe_context , parent_type ,
148
- source_value , field_asts )
149
+ result = resolve_field (exe_context , parent_type , source_value , field_asts , info )
149
150
if result is Undefined :
150
151
continue
151
152
@@ -179,8 +180,7 @@ def map_result(data):
179
180
180
181
for response_name , field_asts in fields .items ():
181
182
182
- result = subscribe_field (exe_context , parent_type ,
183
- source_value , field_asts )
183
+ result = subscribe_field (exe_context , parent_type , source_value , field_asts )
184
184
if result is Undefined :
185
185
continue
186
186
@@ -197,7 +197,7 @@ def catch_error(error):
197
197
return Observable .merge (observables )
198
198
199
199
200
- def resolve_field (exe_context , parent_type , source , field_asts ):
200
+ def resolve_field (exe_context , parent_type , source , field_asts , parent_info ):
201
201
field_ast = field_asts [0 ]
202
202
field_name = field_ast .name .value
203
203
@@ -232,12 +232,12 @@ def resolve_field(exe_context, parent_type, source, field_asts):
232
232
root_value = exe_context .root_value ,
233
233
operation = exe_context .operation ,
234
234
variable_values = exe_context .variable_values ,
235
- context = context
235
+ context = context ,
236
+ path = parent_info .path + [field_name ] if parent_info else [field_name ]
236
237
)
237
238
238
239
executor = exe_context .executor
239
- result = resolve_or_error (resolve_fn_middleware ,
240
- source , info , args , executor )
240
+ result = resolve_or_error (resolve_fn_middleware , source , info , args , executor )
241
241
242
242
return complete_value_catching_error (
243
243
exe_context ,
@@ -283,7 +283,8 @@ def subscribe_field(exe_context, parent_type, source, field_asts):
283
283
root_value = exe_context .root_value ,
284
284
operation = exe_context .operation ,
285
285
variable_values = exe_context .variable_values ,
286
- context = context
286
+ context = context ,
287
+ path = [field_name ]
287
288
)
288
289
289
290
executor = exe_context .executor
@@ -326,8 +327,7 @@ def complete_value_catching_error(exe_context, return_type, field_asts, info, re
326
327
# Otherwise, error protection is applied, logging the error and
327
328
# resolving a null value for this field if one is encountered.
328
329
try :
329
- completed = complete_value (
330
- exe_context , return_type , field_asts , info , result )
330
+ completed = complete_value (exe_context , return_type , field_asts , info , result )
331
331
if is_thenable (completed ):
332
332
def handle_error (error ):
333
333
traceback = completed ._traceback
@@ -364,7 +364,6 @@ def complete_value(exe_context, return_type, field_asts, info, result):
364
364
"""
365
365
# If field type is NonNull, complete for inner type, and throw field error
366
366
# if result is null.
367
-
368
367
if is_thenable (result ):
369
368
return Promise .resolve (result ).then (
370
369
lambda resolved : complete_value (
@@ -419,13 +418,17 @@ def complete_list_value(exe_context, return_type, field_asts, info, result):
419
418
item_type = return_type .of_type
420
419
completed_results = []
421
420
contains_promise = False
421
+
422
+ index = 0
423
+ path = info .path [:]
422
424
for item in result :
423
- completed_item = complete_value_catching_error (
424
- exe_context , item_type , field_asts , info , item )
425
+ info . path = path + [ index ]
426
+ completed_item = complete_value_catching_error ( exe_context , item_type , field_asts , info , item )
425
427
if not contains_promise and is_thenable (completed_item ):
426
428
contains_promise = True
427
429
428
430
completed_results .append (completed_item )
431
+ index += 1
429
432
430
433
return Promise .all (completed_results ) if contains_promise else completed_results
431
434
@@ -501,7 +504,7 @@ def complete_object_value(exe_context, return_type, field_asts, info, result):
501
504
502
505
# Collect sub-fields to execute to complete this value.
503
506
subfield_asts = exe_context .get_sub_fields (return_type , field_asts )
504
- return execute_fields (exe_context , return_type , result , subfield_asts )
507
+ return execute_fields (exe_context , return_type , result , subfield_asts , info )
505
508
506
509
507
510
def complete_nonnull_value (exe_context , return_type , field_asts , info , result ):
0 commit comments