Skip to content

2.0 #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 1, 2017
Merged

2.0 #133

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions graphql/error/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ def resolver(context, *_):
('test_reraise', 'result.errors[0].reraise()'),
('reraise', 'six.reraise(type(self), self, self.stack)'),
# ('reraise', 'raise value.with_traceback(tb)'),
('resolve_or_error', 'return executor.execute(resolve_fn, source, args, context, info)'),
('resolve_or_error', 'return executor.execute(resolve_fn, source, info, **args)'),
('execute', 'return fn(*args, **kwargs)'), ('resolver', "raise Exception('Failed')")
]
# assert formatted_tb == [
# ('test_reraise', 'result.errors[0].reraise()'),
# ('reraise', 'six.reraise(type(self), self, self.stack)'),
# ('on_complete_resolver', 'result = __resolver(*args, **kwargs)'),
# # ('reraise', 'raise value.with_traceback(tb)'),
# # ('resolve_or_error', 'return executor.execute(resolve_fn, source, args, context, info)'),
# # ('resolve_or_error', 'return executor.execute(resolve_fn, source, info, **args)'),
# # ('execute', 'return fn(*args, **kwargs)'),
# ('resolver', "raise Exception('Failed')")
# ]
Expand Down
7 changes: 4 additions & 3 deletions graphql/execution/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,10 @@ def get_field_entry_key(node):

class ResolveInfo(object):
__slots__ = ('field_name', 'field_asts', 'return_type', 'parent_type',
'schema', 'fragments', 'root_value', 'operation', 'variable_values')
'schema', 'fragments', 'root_value', 'operation', 'variable_values', 'context')

def __init__(self, field_name, field_asts, return_type, parent_type,
schema, fragments, root_value, operation, variable_values):
schema, fragments, root_value, operation, variable_values, context):
self.field_name = field_name
self.field_asts = field_asts
self.return_type = return_type
Expand All @@ -285,9 +285,10 @@ def __init__(self, field_name, field_asts, return_type, parent_type,
self.root_value = root_value
self.operation = operation
self.variable_values = variable_values
self.context = context


def default_resolve_fn(source, args, context, info):
def default_resolve_fn(source, info, **args):
"""If a resolve function is not given, then a default resolve behavior is used which takes the property of the source object
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."""
name = info.field_name
Expand Down
28 changes: 9 additions & 19 deletions graphql/execution/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,14 @@
collect_fields, default_resolve_fn, get_field_def,
get_operation_root_type)
from .executors.sync import SyncExecutor
from .experimental.executor import execute as experimental_execute
from .middleware import MiddlewareManager

logger = logging.getLogger(__name__)


use_experimental_executor = False


def execute(schema, document_ast, root_value=None, context_value=None,
variable_values=None, operation_name=None, executor=None,
return_promise=False, middleware=None):
if use_experimental_executor:
return experimental_execute(
schema, document_ast, root_value, context_value,
variable_values, operation_name, executor,
return_promise, middleware
)

assert schema, 'Must provide schema'
assert isinstance(schema, GraphQLSchema), (
'Schema must be an instance of GraphQLSchema. Also ensure that there are ' +
Expand Down Expand Up @@ -182,10 +171,11 @@ def resolve_field(exe_context, parent_type, source, field_asts):
root_value=exe_context.root_value,
operation=exe_context.operation,
variable_values=exe_context.variable_values,
context=context
)

executor = exe_context.executor
result = resolve_or_error(resolve_fn_middleware, source, args, context, info, executor)
result = resolve_or_error(resolve_fn_middleware, source, info, args, executor)

return complete_value_catching_error(
exe_context,
Expand All @@ -196,9 +186,9 @@ def resolve_field(exe_context, parent_type, source, field_asts):
)


def resolve_or_error(resolve_fn, source, args, context, info, executor):
def resolve_or_error(resolve_fn, source, info, args, executor):
try:
return executor.execute(resolve_fn, source, args, context, info)
return executor.execute(resolve_fn, source, info, **args)
except Exception as e:
logger.exception("An error occurred while resolving field {}.{}".format(
info.parent_type.name, info.field_name
Expand Down Expand Up @@ -334,9 +324,9 @@ def complete_abstract_value(exe_context, return_type, field_asts, info, result):
# Field type must be Object, Interface or Union and expect sub-selections.
if isinstance(return_type, (GraphQLInterfaceType, GraphQLUnionType)):
if return_type.resolve_type:
runtime_type = return_type.resolve_type(result, exe_context.context_value, info)
runtime_type = return_type.resolve_type(result, info)
else:
runtime_type = get_default_resolve_type_fn(result, exe_context.context_value, info, return_type)
runtime_type = get_default_resolve_type_fn(result, info, return_type)

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


def get_default_resolve_type_fn(value, context, info, abstract_type):
def get_default_resolve_type_fn(value, info, abstract_type):
possible_types = info.schema.get_possible_types(abstract_type)
for type in possible_types:
if callable(type.is_type_of) and type.is_type_of(value, context, info):
if callable(type.is_type_of) and type.is_type_of(value, info):
return type


def complete_object_value(exe_context, return_type, field_asts, info, result):
"""
Complete an Object value by evaluating all sub-selections.
"""
if return_type.is_type_of and not return_type.is_type_of(result, exe_context.context_value, info):
if return_type.is_type_of and not return_type.is_type_of(result, info):
raise GraphQLError(
u'Expected value of type "{}" but got: {}.'.format(return_type, type(result).__name__),
field_asts
Expand Down
Empty file.
66 changes: 0 additions & 66 deletions graphql/execution/experimental/executor.py

This file was deleted.

Loading