@@ -131,6 +131,11 @@ def resolve_field(exe_context, parent_type, source, field_asts):
131
131
# fulfill any variable references.
132
132
args = exe_context .get_argument_values (field_def , field_ast )
133
133
134
+ # The resolve function's optional third argument is a context value that
135
+ # is provided to every resolve function within an execution. It is commonly
136
+ # used to represent an authenticated user, or request-specific caches.
137
+ context = exe_context .context_value
138
+
134
139
# The resolve function's optional third argument is a collection of
135
140
# information about the current execution state.
136
141
info = ResolveInfo (
@@ -145,7 +150,8 @@ def resolve_field(exe_context, parent_type, source, field_asts):
145
150
variable_values = exe_context .variable_values ,
146
151
)
147
152
148
- result = resolve_or_error (resolve_fn , source , args , exe_context , info )
153
+ executor = exe_context .executor
154
+ result = resolve_or_error (resolve_fn , source , args , context , info , executor )
149
155
150
156
return complete_value_catching_error (
151
157
exe_context ,
@@ -156,10 +162,9 @@ def resolve_field(exe_context, parent_type, source, field_asts):
156
162
)
157
163
158
164
159
- def resolve_or_error (resolve_fn , source , args , exe_context , info ):
165
+ def resolve_or_error (resolve_fn , source , args , context , info , executor ):
160
166
try :
161
- # return resolve_fn(source, args, exe_context, info)
162
- return exe_context .executor .execute (resolve_fn , source , args , info )
167
+ return executor .execute (resolve_fn , source , args , info )
163
168
except Exception as e :
164
169
logger .exception ("An error occurred while resolving field {}.{}" .format (
165
170
info .parent_type .name , info .field_name
@@ -307,7 +312,7 @@ def complete_abstract_value(exe_context, return_type, field_asts, info, result):
307
312
if return_type .resolve_type :
308
313
runtime_type = return_type .resolve_type (result , info )
309
314
else :
310
- runtime_type = get_default_resolve_type_fn (result , info , return_type )
315
+ runtime_type = get_default_resolve_type_fn (result , exe_context . context_value , info , return_type )
311
316
312
317
assert runtime_type , (
313
318
'Could not determine runtime type of value "{}" for field {}.{}.' .format (
@@ -334,7 +339,7 @@ def complete_abstract_value(exe_context, return_type, field_asts, info, result):
334
339
return complete_object_value (exe_context , runtime_type , field_asts , info , result )
335
340
336
341
337
- def get_default_resolve_type_fn (value , info , abstract_type ):
342
+ def get_default_resolve_type_fn (value , context , info , abstract_type ):
338
343
possible_types = info .schema .get_possible_types (abstract_type )
339
344
for type in possible_types :
340
345
if callable (type .is_type_of ) and type .is_type_of (value , info ):
0 commit comments