Skip to content

Commit f9ed20b

Browse files
authored
Merge pull request #133 from graphql-python/2.0
2.0
2 parents cb9ea88 + cece343 commit f9ed20b

39 files changed

+72
-4104
lines changed

graphql/error/tests/test_base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ def resolver(context, *_):
4444
('test_reraise', 'result.errors[0].reraise()'),
4545
('reraise', 'six.reraise(type(self), self, self.stack)'),
4646
# ('reraise', 'raise value.with_traceback(tb)'),
47-
('resolve_or_error', 'return executor.execute(resolve_fn, source, args, context, info)'),
47+
('resolve_or_error', 'return executor.execute(resolve_fn, source, info, **args)'),
4848
('execute', 'return fn(*args, **kwargs)'), ('resolver', "raise Exception('Failed')")
4949
]
5050
# assert formatted_tb == [
5151
# ('test_reraise', 'result.errors[0].reraise()'),
5252
# ('reraise', 'six.reraise(type(self), self, self.stack)'),
5353
# ('on_complete_resolver', 'result = __resolver(*args, **kwargs)'),
5454
# # ('reraise', 'raise value.with_traceback(tb)'),
55-
# # ('resolve_or_error', 'return executor.execute(resolve_fn, source, args, context, info)'),
55+
# # ('resolve_or_error', 'return executor.execute(resolve_fn, source, info, **args)'),
5656
# # ('execute', 'return fn(*args, **kwargs)'),
5757
# ('resolver', "raise Exception('Failed')")
5858
# ]

graphql/execution/base.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,10 @@ def get_field_entry_key(node):
272272

273273
class ResolveInfo(object):
274274
__slots__ = ('field_name', 'field_asts', 'return_type', 'parent_type',
275-
'schema', 'fragments', 'root_value', 'operation', 'variable_values')
275+
'schema', 'fragments', 'root_value', 'operation', 'variable_values', 'context')
276276

277277
def __init__(self, field_name, field_asts, return_type, parent_type,
278-
schema, fragments, root_value, operation, variable_values):
278+
schema, fragments, root_value, operation, variable_values, context):
279279
self.field_name = field_name
280280
self.field_asts = field_asts
281281
self.return_type = return_type
@@ -285,9 +285,10 @@ def __init__(self, field_name, field_asts, return_type, parent_type,
285285
self.root_value = root_value
286286
self.operation = operation
287287
self.variable_values = variable_values
288+
self.context = context
288289

289290

290-
def default_resolve_fn(source, args, context, info):
291+
def default_resolve_fn(source, info, **args):
291292
"""If a resolve function is not given, then a default resolve behavior is used which takes the property of the source object
292293
of the same name as the field and returns it as the result, or if it's a function, returns the result of calling that function."""
293294
name = info.field_name

graphql/execution/executor.py

+9-19
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,14 @@
1717
collect_fields, default_resolve_fn, get_field_def,
1818
get_operation_root_type)
1919
from .executors.sync import SyncExecutor
20-
from .experimental.executor import execute as experimental_execute
2120
from .middleware import MiddlewareManager
2221

2322
logger = logging.getLogger(__name__)
2423

2524

26-
use_experimental_executor = False
27-
28-
2925
def execute(schema, document_ast, root_value=None, context_value=None,
3026
variable_values=None, operation_name=None, executor=None,
3127
return_promise=False, middleware=None):
32-
if use_experimental_executor:
33-
return experimental_execute(
34-
schema, document_ast, root_value, context_value,
35-
variable_values, operation_name, executor,
36-
return_promise, middleware
37-
)
38-
3928
assert schema, 'Must provide schema'
4029
assert isinstance(schema, GraphQLSchema), (
4130
'Schema must be an instance of GraphQLSchema. Also ensure that there are ' +
@@ -182,10 +171,11 @@ def resolve_field(exe_context, parent_type, source, field_asts):
182171
root_value=exe_context.root_value,
183172
operation=exe_context.operation,
184173
variable_values=exe_context.variable_values,
174+
context=context
185175
)
186176

187177
executor = exe_context.executor
188-
result = resolve_or_error(resolve_fn_middleware, source, args, context, info, executor)
178+
result = resolve_or_error(resolve_fn_middleware, source, info, args, executor)
189179

190180
return complete_value_catching_error(
191181
exe_context,
@@ -196,9 +186,9 @@ def resolve_field(exe_context, parent_type, source, field_asts):
196186
)
197187

198188

199-
def resolve_or_error(resolve_fn, source, args, context, info, executor):
189+
def resolve_or_error(resolve_fn, source, info, args, executor):
200190
try:
201-
return executor.execute(resolve_fn, source, args, context, info)
191+
return executor.execute(resolve_fn, source, info, **args)
202192
except Exception as e:
203193
logger.exception("An error occurred while resolving field {}.{}".format(
204194
info.parent_type.name, info.field_name
@@ -334,9 +324,9 @@ def complete_abstract_value(exe_context, return_type, field_asts, info, result):
334324
# Field type must be Object, Interface or Union and expect sub-selections.
335325
if isinstance(return_type, (GraphQLInterfaceType, GraphQLUnionType)):
336326
if return_type.resolve_type:
337-
runtime_type = return_type.resolve_type(result, exe_context.context_value, info)
327+
runtime_type = return_type.resolve_type(result, info)
338328
else:
339-
runtime_type = get_default_resolve_type_fn(result, exe_context.context_value, info, return_type)
329+
runtime_type = get_default_resolve_type_fn(result, info, return_type)
340330

341331
if isinstance(runtime_type, string_types):
342332
runtime_type = info.schema.get_type(runtime_type)
@@ -363,18 +353,18 @@ def complete_abstract_value(exe_context, return_type, field_asts, info, result):
363353
return complete_object_value(exe_context, runtime_type, field_asts, info, result)
364354

365355

366-
def get_default_resolve_type_fn(value, context, info, abstract_type):
356+
def get_default_resolve_type_fn(value, info, abstract_type):
367357
possible_types = info.schema.get_possible_types(abstract_type)
368358
for type in possible_types:
369-
if callable(type.is_type_of) and type.is_type_of(value, context, info):
359+
if callable(type.is_type_of) and type.is_type_of(value, info):
370360
return type
371361

372362

373363
def complete_object_value(exe_context, return_type, field_asts, info, result):
374364
"""
375365
Complete an Object value by evaluating all sub-selections.
376366
"""
377-
if return_type.is_type_of and not return_type.is_type_of(result, exe_context.context_value, info):
367+
if return_type.is_type_of and not return_type.is_type_of(result, info):
378368
raise GraphQLError(
379369
u'Expected value of type "{}" but got: {}.'.format(return_type, type(result).__name__),
380370
field_asts

graphql/execution/experimental/__init__.py

Whitespace-only changes.

graphql/execution/experimental/executor.py

-66
This file was deleted.

0 commit comments

Comments
 (0)