Skip to content

Commit 600db31

Browse files
committed
introduce GroupedFieldSet type
Replicates graphql/graphql-js@45f2a59
1 parent 1a96cfd commit 600db31

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/graphql/execution/collect_fields.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import sys
66
from collections import defaultdict
7-
from typing import Any, List, NamedTuple
7+
from typing import Any, Dict, List, NamedTuple
88

99
from ..language import (
1010
FieldNode,
@@ -32,25 +32,33 @@
3232
from typing_extensions import TypeAlias
3333

3434

35-
__all__ = ["collect_fields", "collect_subfields", "FieldGroup", "FieldsAndPatches"]
35+
__all__ = [
36+
"collect_fields",
37+
"collect_subfields",
38+
"FieldGroup",
39+
"FieldsAndPatches",
40+
"GroupedFieldSet",
41+
]
3642

3743
if sys.version_info < (3, 9):
3844
FieldGroup: TypeAlias = List[FieldNode]
45+
GroupedFieldSet = Dict[str, FieldGroup]
3946
else: # Python >= 3.9
4047
FieldGroup: TypeAlias = list[FieldNode]
48+
GroupedFieldSet = dict[str, FieldGroup]
4149

4250

4351
class PatchFields(NamedTuple):
4452
"""Optionally labelled set of fields to be used as a patch."""
4553

4654
label: str | None
47-
fields: dict[str, FieldGroup]
55+
fields: GroupedFieldSet
4856

4957

5058
class FieldsAndPatches(NamedTuple):
5159
"""Tuple of collected fields and patches to be applied."""
5260

53-
fields: dict[str, FieldGroup]
61+
fields: GroupedFieldSet
5462
patches: list[PatchFields]
5563

5664

src/graphql/execution/execute.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
from .collect_fields import (
7878
FieldGroup,
7979
FieldsAndPatches,
80+
GroupedFieldSet,
8081
collect_fields,
8182
collect_subfields,
8283
)
@@ -841,7 +842,7 @@ def execute_fields_serially(
841842
parent_type: GraphQLObjectType,
842843
source_value: Any,
843844
path: Path | None,
844-
fields: dict[str, FieldGroup],
845+
fields: GroupedFieldSet,
845846
) -> AwaitableOrValue[dict[str, Any]]:
846847
"""Execute the given fields serially.
847848
@@ -881,7 +882,7 @@ def execute_fields(
881882
parent_type: GraphQLObjectType,
882883
source_value: Any,
883884
path: Path | None,
884-
fields: dict[str, FieldGroup],
885+
fields: GroupedFieldSet,
885886
async_payload_record: AsyncPayloadRecord | None = None,
886887
) -> AwaitableOrValue[dict[str, Any]]:
887888
"""Execute the given fields concurrently.
@@ -1692,7 +1693,7 @@ def execute_deferred_fragment(
16921693
self,
16931694
parent_type: GraphQLObjectType,
16941695
source_value: Any,
1695-
fields: dict[str, FieldGroup],
1696+
fields: GroupedFieldSet,
16961697
label: str | None = None,
16971698
path: Path | None = None,
16981699
parent_context: AsyncPayloadRecord | None = None,

0 commit comments

Comments
 (0)