Skip to content

Commit f811dc9

Browse files
committed
First iteration for implementing promises approach simplifying executor
1 parent e54543d commit f811dc9

File tree

12 files changed

+971
-532
lines changed

12 files changed

+971
-532
lines changed

graphql/execution/__init__.py

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,44 @@
1818
2) fragment "spreads" e.g. "...c"
1919
3) inline fragment "spreads" e.g. "...on Type { a }"
2020
"""
21-
21+
from .execute import execute as _execute
2222
from .base import ExecutionResult
23-
from .executor import Executor
24-
from .middlewares.sync import SynchronousExecutionMiddleware
25-
23+
# from .executor import Executor
24+
# from .middlewares.sync import SynchronousExecutionMiddleware
2625

2726
def execute(schema, root, ast, operation_name='', args=None):
28-
"""
29-
Executes an AST synchronously. Assumes that the AST is already validated.
30-
"""
31-
return get_default_executor().execute(schema, ast, root, args, operation_name, validate_ast=False)
27+
return _execute(schema, ast, root, variable_values=args, operation_name=operation_name)
28+
29+
# def execute(schema, root, ast, operation_name='', args=None):
30+
# """
31+
# Executes an AST synchronously. Assumes that the AST is already validated.
32+
# """
33+
# return get_default_executor().execute(schema, ast, root, args, operation_name, validate_ast=False)
3234

3335

34-
_default_executor = None
36+
# _default_executor = None
3537

3638

37-
def get_default_executor():
38-
"""
39-
Gets the default executor to be used in the `execute` function above.
40-
"""
41-
global _default_executor
42-
if _default_executor is None:
43-
_default_executor = Executor([SynchronousExecutionMiddleware()])
39+
# def get_default_executor():
40+
# """
41+
# Gets the default executor to be used in the `execute` function above.
42+
# """
43+
# global _default_executor
44+
# if _default_executor is None:
45+
# _default_executor = Executor([SynchronousExecutionMiddleware()])
4446

45-
return _default_executor
47+
# return _default_executor
4648

4749

48-
def set_default_executor(executor):
49-
"""
50-
Sets the default executor to be used in the `execute` function above.
50+
# def set_default_executor(executor):
51+
# """
52+
# Sets the default executor to be used in the `execute` function above.
5153

52-
If passed `None` will reset to the original default synchronous executor.
53-
"""
54-
assert isinstance(executor, Executor) or executor is None
55-
global _default_executor
56-
_default_executor = executor
54+
# If passed `None` will reset to the original default synchronous executor.
55+
# """
56+
# assert isinstance(executor, Executor) or executor is None
57+
# global _default_executor
58+
# _default_executor = executor
5759

5860

59-
__all__ = ['ExecutionResult', 'Executor', 'execute', 'get_default_executor', 'set_default_executor']
61+
# __all__ = ['ExecutionResult', 'Executor', 'execute', 'get_default_executor', 'set_default_executor']

graphql/execution/base.py

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ class ExecutionContext(object):
1818
Namely, schema of the type system that is currently executing,
1919
and the fragments defined in the query document"""
2020

21-
__slots__ = 'schema', 'fragments', 'root', 'operation', 'variables', 'errors', 'request_context', \
21+
__slots__ = 'schema', 'fragments', 'root_value', 'operation', 'variable_values', 'errors', 'context_value', \
2222
'argument_values_cache'
2323

24-
def __init__(self, schema, root, document_ast, operation_name, args, request_context):
24+
def __init__(self, schema, document_ast, root_value, context_value, variable_values, operation_name):
2525
"""Constructs a ExecutionContext object from the arguments passed
2626
to execute, which we will pass throughout the other execution
2727
methods."""
@@ -53,15 +53,15 @@ def __init__(self, schema, root, document_ast, operation_name, args, request_con
5353
else:
5454
raise GraphQLError('Must provide an operation.')
5555

56-
variables = get_variable_values(schema, operation.variable_definitions or [], args)
56+
variable_values = get_variable_values(schema, operation.variable_definitions or [], variable_values)
5757

5858
self.schema = schema
5959
self.fragments = fragments
60-
self.root = root
60+
self.root_value = root_value
6161
self.operation = operation
62-
self.variables = variables
62+
self.variable_values = variable_values
6363
self.errors = errors
64-
self.request_context = request_context
64+
self.context_value = context_value
6565
self.argument_values_cache = {}
6666

6767
def get_argument_values(self, field_def, field_ast):
@@ -70,7 +70,7 @@ def get_argument_values(self, field_def, field_ast):
7070

7171
if not result:
7272
result = self.argument_values_cache[k] = get_argument_values(field_def.args, field_ast.arguments,
73-
self.variables)
73+
self.variable_values)
7474

7575
return result
7676

@@ -190,6 +190,7 @@ def collect_fields(ctx, runtime_type, selection_set, fields, prev_fragment_names
190190
def should_include_node(ctx, directives):
191191
"""Determines if a field should be included based on the @include and
192192
@skip directives, where @skip has higher precidence than @include."""
193+
# TODO: Refactor based on latest code
193194
if directives:
194195
skip_ast = None
195196

@@ -202,7 +203,7 @@ def should_include_node(ctx, directives):
202203
args = get_argument_values(
203204
GraphQLSkipDirective.args,
204205
skip_ast.arguments,
205-
ctx.variables,
206+
ctx.variable_values,
206207
)
207208
return not args.get('if')
208209

@@ -217,7 +218,7 @@ def should_include_node(ctx, directives):
217218
args = get_argument_values(
218219
GraphQLIncludeDirective.args,
219220
include_ast.arguments,
220-
ctx.variables,
221+
ctx.variable_values,
221222
)
222223

223224
return bool(args.get('if'))
@@ -249,36 +250,16 @@ def get_field_entry_key(node):
249250

250251
class ResolveInfo(object):
251252

252-
def __init__(self, field_name, field_asts, return_type, parent_type, context):
253+
def __init__(self, field_name, field_asts, return_type, parent_type, schema, fragments, root_value, operation, variable_values):
253254
self.field_name = field_name
254255
self.field_asts = field_asts
255256
self.return_type = return_type
256257
self.parent_type = parent_type
257-
self.context = context
258-
259-
@property
260-
def schema(self):
261-
return self.context.schema
262-
263-
@property
264-
def fragments(self):
265-
return self.context.fragments
266-
267-
@property
268-
def root_value(self):
269-
return self.context.root
270-
271-
@property
272-
def operation(self):
273-
return self.context.operation
274-
275-
@property
276-
def variable_values(self):
277-
return self.context.variables
278-
279-
@property
280-
def request_context(self):
281-
return self.context.request_context
258+
self.schema = schema
259+
self.fragments = fragments
260+
self.root_value = root_value
261+
self.operation = operation
262+
self.variable_values = variable_values
282263

283264

284265
def default_resolve_fn(source, args, info):

0 commit comments

Comments
 (0)