Skip to content

Commit d22798f

Browse files
committed
Simplified field_ast collection in experimental executor
1 parent dd38759 commit d22798f

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

graphql/execution/experimental/executor.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from promise import Promise
22

33
from ...type import GraphQLSchema
4-
from ...pyutils.default_ordered_dict import DefaultOrderedDict
5-
from ..base import ExecutionContext, ExecutionResult, get_operation_root_type, collect_fields
4+
from ..base import ExecutionContext, ExecutionResult, get_operation_root_type
65
from ..executors.sync import SyncExecutor
76
from ..middleware import MiddlewareManager
87
from .fragment import Fragment
@@ -57,15 +56,7 @@ def execute_operation(exe_context, operation, root_value):
5756
type = get_operation_root_type(exe_context.schema, operation)
5857
execute_serially = operation.operation == 'mutation'
5958

60-
fields = collect_fields(
61-
exe_context,
62-
type,
63-
operation.selection_set,
64-
DefaultOrderedDict(list),
65-
set()
66-
)
67-
68-
fragment = Fragment(type=type, field_asts=fields, context=exe_context)
59+
fragment = Fragment(type=type, field_asts=[operation], context=exe_context)
6960
if execute_serially:
7061
return fragment.resolve_serially(root_value)
7162
return fragment.resolve(root_value)

graphql/execution/experimental/fragment.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ def get_subfield_asts(context, return_type, field_asts):
3737

3838
def get_resolvers(context, type, field_asts):
3939
from .resolver import field_resolver
40+
subfield_asts = get_subfield_asts(context, type, field_asts)
4041

41-
resolvers = []
42-
for response_name, field_asts in field_asts.items():
42+
for response_name, field_asts in subfield_asts.items():
4343
field_ast = field_asts[0]
4444
field_name = field_ast.name.value
4545
field_def = get_field_def(context and context.schema, type, field_name)
@@ -61,7 +61,7 @@ def get_resolvers(context, type, field_asts):
6161
if isinstance(field_base_type, GraphQLObjectType):
6262
field_fragment = Fragment(
6363
type=field_base_type,
64-
field_asts=get_subfield_asts(context, field_base_type, field_asts),
64+
field_asts=field_asts,
6565
info=info,
6666
context=context
6767
)
@@ -78,8 +78,7 @@ def get_resolvers(context, type, field_asts):
7878
field_ast.arguments,
7979
context and context.variable_values
8080
)
81-
resolvers.append((response_name, resolver, args, context and context.context_value, info))
82-
return resolvers
81+
yield (response_name, resolver, args, context and context.context_value, info)
8382

8483

8584
class Fragment(object):
@@ -92,11 +91,11 @@ def __init__(self, type, field_asts, context=None, info=None):
9291

9392
@cached_property
9493
def partial_resolvers(self):
95-
return get_resolvers(
94+
return list(get_resolvers(
9695
self.context,
9796
self.type,
9897
self.field_asts
99-
)
98+
))
10099

101100
def have_type(self, root):
102101
return not self.type.is_type_of or self.type.is_type_of(root, self.context.context_value, self.info)
@@ -191,7 +190,7 @@ def get_fragment(self, type):
191190
).format(type, self.abstract_type)
192191
self._fragments[type] = Fragment(
193192
type,
194-
get_subfield_asts(self.context, type, self.field_asts),
193+
self.field_asts,
195194
self.context,
196195
self.info
197196
)

0 commit comments

Comments
 (0)