Skip to content

Commit a7d822c

Browse files
committed
First phase of passing the context to the resolver function
1 parent 2879aaf commit a7d822c

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

graphql/execution/executor.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ def resolve_field(exe_context, parent_type, source, field_asts):
131131
# fulfill any variable references.
132132
args = exe_context.get_argument_values(field_def, field_ast)
133133

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+
134139
# The resolve function's optional third argument is a collection of
135140
# information about the current execution state.
136141
info = ResolveInfo(
@@ -145,7 +150,8 @@ def resolve_field(exe_context, parent_type, source, field_asts):
145150
variable_values=exe_context.variable_values,
146151
)
147152

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)
149155

150156
return complete_value_catching_error(
151157
exe_context,
@@ -156,10 +162,9 @@ def resolve_field(exe_context, parent_type, source, field_asts):
156162
)
157163

158164

159-
def resolve_or_error(resolve_fn, source, args, exe_context, info):
165+
def resolve_or_error(resolve_fn, source, args, context, info, executor):
160166
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)
163168
except Exception as e:
164169
logger.exception("An error occurred while resolving field {}.{}".format(
165170
info.parent_type.name, info.field_name
@@ -307,7 +312,7 @@ def complete_abstract_value(exe_context, return_type, field_asts, info, result):
307312
if return_type.resolve_type:
308313
runtime_type = return_type.resolve_type(result, info)
309314
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)
311316

312317
assert runtime_type, (
313318
'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):
334339
return complete_object_value(exe_context, runtime_type, field_asts, info, result)
335340

336341

337-
def get_default_resolve_type_fn(value, info, abstract_type):
342+
def get_default_resolve_type_fn(value, context, info, abstract_type):
338343
possible_types = info.schema.get_possible_types(abstract_type)
339344
for type in possible_types:
340345
if callable(type.is_type_of) and type.is_type_of(value, info):

0 commit comments

Comments
 (0)