Skip to content

Commit 77838b4

Browse files
committed
execute: Rename resolve_field method and update comments
Replicates graphql/graphql-js@dc2a3eb
1 parent fc76d01 commit 77838b4

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/graphql/execution/execute.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def execute_operation(
325325
) -> Optional[AwaitableOrValue[Any]]:
326326
"""Execute an operation.
327327
328-
Implements the "Evaluating operations" section of the spec.
328+
Implements the "Executing operations" section of the spec.
329329
"""
330330
type_ = get_operation_root_type(self.schema, operation)
331331
fields = self.collect_fields(type_, operation.selection_set, {}, set())
@@ -366,13 +366,14 @@ def execute_fields_serially(
366366
) -> AwaitableOrValue[Dict[str, Any]]:
367367
"""Execute the given fields serially.
368368
369-
Implements the "Evaluating selection sets" section of the spec for "write" mode.
369+
Implements the "Executing selection sets" section of the spec
370+
for fields that must be executed serially.
370371
"""
371372
results: AwaitableOrValue[Dict[str, Any]] = {}
372373
is_awaitable = self.is_awaitable
373374
for response_name, field_nodes in fields.items():
374375
field_path = Path(path, response_name, parent_type.name)
375-
result = self.resolve_field(
376+
result = self.execute_field(
376377
parent_type, source_value, field_nodes, field_path
377378
)
378379
if result is Undefined:
@@ -425,15 +426,16 @@ def execute_fields(
425426
) -> AwaitableOrValue[Dict[str, Any]]:
426427
"""Execute the given fields concurrently.
427428
428-
Implements the "Evaluating selection sets" section of the spec for "read" mode.
429+
Implements the "Executing selection sets" section of the spec
430+
for fields that may be executed in parallel.
429431
"""
430432
results = {}
431433
is_awaitable = self.is_awaitable
432434
awaitable_fields: List[str] = []
433435
append_awaitable = awaitable_fields.append
434436
for response_name, field_nodes in fields.items():
435437
field_path = Path(path, response_name, parent_type.name)
436-
result = self.resolve_field(
438+
result = self.execute_field(
437439
parent_type, source_value, field_nodes, field_path
438440
)
439441
if result is not Undefined:
@@ -577,7 +579,7 @@ def build_resolve_info(
577579
self.is_awaitable,
578580
)
579581

580-
def resolve_field(
582+
def execute_field(
581583
self,
582584
parent_type: GraphQLObjectType,
583585
source: Any,
@@ -586,9 +588,11 @@ def resolve_field(
586588
) -> AwaitableOrValue[Any]:
587589
"""Resolve the field on the given source object.
588590
589-
In particular, this figures out the value that the field returns by calling its
590-
resolve function, then calls complete_value to await coroutine objects,
591-
serialize scalars, or execute the sub-selection-set for objects.
591+
Implements the "Executing field" section of the spec.
592+
593+
In particular, this method figures out the value that the field returns by
594+
calling its resolve function, then calls complete_value to await coroutine
595+
objects, serialize scalars, or execute the sub-selection-set for objects.
592596
"""
593597
field_def = get_field_def(self.schema, parent_type, field_nodes[0])
594598
if not field_def:
@@ -1060,7 +1064,7 @@ def execute(
10601064
) -> AwaitableOrValue[ExecutionResult]:
10611065
"""Execute a GraphQL operation.
10621066
1063-
Implements the "Evaluating requests" section of the GraphQL specification.
1067+
Implements the "Executing requests" section of the GraphQL specification.
10641068
10651069
Returns an ExecutionResult (if all encountered resolvers are synchronous),
10661070
or a coroutine object eventually yielding an ExecutionResult.
@@ -1125,7 +1129,7 @@ def execute_sync(
11251129
) -> ExecutionResult:
11261130
"""Execute a GraphQL operation synchronously.
11271131
1128-
Also implements the "Evaluating requests" section of the GraphQL specification.
1132+
Also implements the "Executing requests" section of the GraphQL specification.
11291133
11301134
However, it guarantees to complete synchronously (or throw an error) assuming
11311135
that all field resolvers are also synchronous.

tests/execution/test_customize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def uses_a_custom_execution_context_class():
3131
)
3232

3333
class TestExecutionContext(ExecutionContext):
34-
def resolve_field(self, parent_type, source, field_nodes, path):
35-
result = super().resolve_field(parent_type, source, field_nodes, path)
34+
def execute_field(self, parent_type, source, field_nodes, path):
35+
result = super().execute_field(parent_type, source, field_nodes, path)
3636
return result * 2 # type: ignore
3737

3838
assert execute(schema, query, execution_context_class=TestExecutionContext) == (

0 commit comments

Comments
 (0)