Skip to content

Commit d21f79b

Browse files
committed
refactor: add execution mode/serially argument to execute_root_selection_set
The analog of executeRootSelectionSet() is Executor.execute_operation(), which kept its name, so the argument was added there. Replicates graphql/graphql-js@cf0de41
1 parent f2c37de commit d21f79b

2 files changed

Lines changed: 30 additions & 9 deletions

File tree

src/graphql/execution/execute.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ def build_per_event_executor(self, payload: Any) -> Executor:
441441

442442
def execute_operation(
443443
self,
444+
serially: bool | None = None,
444445
) -> AwaitableOrValue[ExecutionResult | ExperimentalIncrementalExecutionResults]:
445446
"""Execute an operation.
446447
@@ -500,7 +501,13 @@ def execute_operation(
500501
)
501502
if new_defer_usages
502503
else self.execute_root_grouped_field_set(
503-
operation_type, root_type, root_value, grouped_field_set, None
504+
root_type,
505+
root_value,
506+
grouped_field_set,
507+
operation_type == OperationType.MUTATION
508+
if serially is None
509+
else serially,
510+
None,
504511
)
505512
)
506513

@@ -579,18 +586,14 @@ def execute_execution_plan(
579586

580587
def execute_root_grouped_field_set(
581588
self,
582-
operation: OperationType,
583589
root_type: GraphQLObjectType,
584590
root_value: Any,
585591
grouped_field_set: GroupedFieldSet,
592+
serially: bool,
586593
defer_map: RefMap[DeferUsage, DeferredFragmentRecord] | None,
587594
) -> AwaitableOrValue[GraphQLWrappedResult[dict[str, Any]]]:
588595
"""Execute the root grouped field set."""
589-
return (
590-
self.execute_fields_serially
591-
if operation == OperationType.MUTATION
592-
else self.execute_fields
593-
)(
596+
return (self.execute_fields_serially if serially else self.execute_fields)(
594597
root_type,
595598
root_value,
596599
None,
@@ -3028,7 +3031,7 @@ def execute_subscription_event(
30283031
The passed executor should be a per-event executor as created by
30293032
:meth:`Executor.build_per_event_executor`.
30303033
"""
3031-
return execute_root_selection_set(executor)
3034+
return cast("AwaitableOrValue[ExecutionResult]", executor.execute_operation(False))
30323035

30333036

30343037
def create_source_event_stream(

tests/execution/test_executor.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
import pytest
88

99
from graphql.error import GraphQLError
10-
from graphql.execution import Executor, execute, execute_sync
10+
from graphql.execution import (
11+
Executor,
12+
execute,
13+
execute_root_selection_set,
14+
execute_sync,
15+
)
1116
from graphql.execution.collect_fields import FieldDetails
1217
from graphql.execution.get_variable_signature import GraphQLVariableSignature
1318
from graphql.execution.values import VariableValues, VariableValueSource
@@ -55,6 +60,19 @@ def accepts_positional_arguments():
5560

5661
assert result == ({"a": "rootValue"}, None)
5762

63+
def executes_the_root_selection_set_of_a_built_executor():
64+
schema = GraphQLSchema(
65+
GraphQLObjectType(
66+
"Type",
67+
{"a": GraphQLField(GraphQLString, resolve=lambda obj, *_args: obj)},
68+
)
69+
)
70+
71+
executor = Executor.build(schema, parse("{ a }"), "rootValue")
72+
assert isinstance(executor, Executor)
73+
74+
assert execute_root_selection_set(executor) == ({"a": "rootValue"}, None)
75+
5876
async def executes_arbitrary_code():
5977
class Data:
6078
def a(self, _info):

0 commit comments

Comments
 (0)