@@ -36,6 +36,7 @@ def execute(schema, document_ast, root_value=None, context_value=None,
3636 'Schema must be an instance of GraphQLSchema. Also ensure that there are ' +
3737 'not multiple versions of GraphQL installed in your node_modules directory.'
3838 )
39+
3940 if middleware :
4041 if not isinstance (middleware , MiddlewareManager ):
4142 middleware = MiddlewareManager (* middleware )
@@ -73,10 +74,10 @@ def on_resolve(data):
7374
7475 if not context .errors :
7576 return ExecutionResult (data = data )
77+
7678 return ExecutionResult (data = data , errors = context .errors )
7779
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 )
8081
8182 if not return_promise :
8283 context .executor .wait_until_finished ()
@@ -107,7 +108,7 @@ def execute_operation(exe_context, operation, root_value):
107108 )
108109 return subscribe_fields (exe_context , type , root_value , fields )
109110
110- return execute_fields (exe_context , type , root_value , fields )
111+ return execute_fields (exe_context , type , root_value , fields , None )
111112
112113
113114def execute_fields_serially (exe_context , parent_type , source_value , fields ):
@@ -117,7 +118,8 @@ def execute_field_callback(results, response_name):
117118 exe_context ,
118119 parent_type ,
119120 source_value ,
120- field_asts
121+ field_asts ,
122+ None
121123 )
122124 if result is Undefined :
123125 return results
@@ -138,14 +140,13 @@ def execute_field(prev_promise, response_name):
138140 return functools .reduce (execute_field , fields .keys (), Promise .resolve (collections .OrderedDict ()))
139141
140142
141- def execute_fields (exe_context , parent_type , source_value , fields ):
143+ def execute_fields (exe_context , parent_type , source_value , fields , info ):
142144 contains_promise = False
143145
144146 final_results = OrderedDict ()
145147
146148 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 )
149150 if result is Undefined :
150151 continue
151152
@@ -179,8 +180,7 @@ def map_result(data):
179180
180181 for response_name , field_asts in fields .items ():
181182
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 )
184184 if result is Undefined :
185185 continue
186186
@@ -197,7 +197,7 @@ def catch_error(error):
197197 return Observable .merge (observables )
198198
199199
200- def resolve_field (exe_context , parent_type , source , field_asts ):
200+ def resolve_field (exe_context , parent_type , source , field_asts , parent_info ):
201201 field_ast = field_asts [0 ]
202202 field_name = field_ast .name .value
203203
@@ -232,12 +232,12 @@ def resolve_field(exe_context, parent_type, source, field_asts):
232232 root_value = exe_context .root_value ,
233233 operation = exe_context .operation ,
234234 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 ]
236237 )
237238
238239 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 )
241241
242242 return complete_value_catching_error (
243243 exe_context ,
@@ -283,7 +283,8 @@ def subscribe_field(exe_context, parent_type, source, field_asts):
283283 root_value = exe_context .root_value ,
284284 operation = exe_context .operation ,
285285 variable_values = exe_context .variable_values ,
286- context = context
286+ context = context ,
287+ path = [field_name ]
287288 )
288289
289290 executor = exe_context .executor
@@ -326,8 +327,7 @@ def complete_value_catching_error(exe_context, return_type, field_asts, info, re
326327 # Otherwise, error protection is applied, logging the error and
327328 # resolving a null value for this field if one is encountered.
328329 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 )
331331 if is_thenable (completed ):
332332 def handle_error (error ):
333333 traceback = completed ._traceback
@@ -364,7 +364,6 @@ def complete_value(exe_context, return_type, field_asts, info, result):
364364 """
365365 # If field type is NonNull, complete for inner type, and throw field error
366366 # if result is null.
367-
368367 if is_thenable (result ):
369368 return Promise .resolve (result ).then (
370369 lambda resolved : complete_value (
@@ -419,13 +418,17 @@ def complete_list_value(exe_context, return_type, field_asts, info, result):
419418 item_type = return_type .of_type
420419 completed_results = []
421420 contains_promise = False
421+
422+ index = 0
423+ path = info .path [:]
422424 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 )
425427 if not contains_promise and is_thenable (completed_item ):
426428 contains_promise = True
427429
428430 completed_results .append (completed_item )
431+ index += 1
429432
430433 return Promise .all (completed_results ) if contains_promise else completed_results
431434
@@ -501,7 +504,7 @@ def complete_object_value(exe_context, return_type, field_asts, info, result):
501504
502505 # Collect sub-fields to execute to complete this value.
503506 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 )
505508
506509
507510def complete_nonnull_value (exe_context , return_type , field_asts , info , result ):
0 commit comments