11"""Collect fields"""
22
3+ from __future__ import annotations
4+
35from collections import defaultdict
4- from typing import Any , Dict , List , NamedTuple , Optional , Set , Union
6+ from typing import Any , NamedTuple
57
68from ..language import (
79 FieldNode ,
2931class PatchFields (NamedTuple ):
3032 """Optionally labelled set of fields to be used as a patch."""
3133
32- label : Optional [ str ]
33- fields : Dict [str , List [FieldNode ]]
34+ label : str | None
35+ fields : dict [str , list [FieldNode ]]
3436
3537
3638class FieldsAndPatches (NamedTuple ):
3739 """Tuple of collected fields and patches to be applied."""
3840
39- fields : Dict [str , List [FieldNode ]]
40- patches : List [PatchFields ]
41+ fields : dict [str , list [FieldNode ]]
42+ patches : list [PatchFields ]
4143
4244
4345def collect_fields (
4446 schema : GraphQLSchema ,
45- fragments : Dict [str , FragmentDefinitionNode ],
46- variable_values : Dict [str , Any ],
47+ fragments : dict [str , FragmentDefinitionNode ],
48+ variable_values : dict [str , Any ],
4749 runtime_type : GraphQLObjectType ,
4850 operation : OperationDefinitionNode ,
4951) -> FieldsAndPatches :
@@ -57,8 +59,8 @@ def collect_fields(
5759
5860 For internal use only.
5961 """
60- fields : Dict [str , List [FieldNode ]] = defaultdict (list )
61- patches : List [PatchFields ] = []
62+ fields : dict [str , list [FieldNode ]] = defaultdict (list )
63+ patches : list [PatchFields ] = []
6264 collect_fields_impl (
6365 schema ,
6466 fragments ,
@@ -75,11 +77,11 @@ def collect_fields(
7577
7678def collect_subfields (
7779 schema : GraphQLSchema ,
78- fragments : Dict [str , FragmentDefinitionNode ],
79- variable_values : Dict [str , Any ],
80+ fragments : dict [str , FragmentDefinitionNode ],
81+ variable_values : dict [str , Any ],
8082 operation : OperationDefinitionNode ,
8183 return_type : GraphQLObjectType ,
82- field_nodes : List [FieldNode ],
84+ field_nodes : list [FieldNode ],
8385) -> FieldsAndPatches :
8486 """Collect subfields.
8587
@@ -92,10 +94,10 @@ def collect_subfields(
9294
9395 For internal use only.
9496 """
95- sub_field_nodes : Dict [str , List [FieldNode ]] = defaultdict (list )
96- visited_fragment_names : Set [str ] = set ()
97+ sub_field_nodes : dict [str , list [FieldNode ]] = defaultdict (list )
98+ visited_fragment_names : set [str ] = set ()
9799
98- sub_patches : List [PatchFields ] = []
100+ sub_patches : list [PatchFields ] = []
99101 sub_fields_and_patches = FieldsAndPatches (sub_field_nodes , sub_patches )
100102
101103 for node in field_nodes :
@@ -116,17 +118,17 @@ def collect_subfields(
116118
117119def collect_fields_impl (
118120 schema : GraphQLSchema ,
119- fragments : Dict [str , FragmentDefinitionNode ],
120- variable_values : Dict [str , Any ],
121+ fragments : dict [str , FragmentDefinitionNode ],
122+ variable_values : dict [str , Any ],
121123 operation : OperationDefinitionNode ,
122124 runtime_type : GraphQLObjectType ,
123125 selection_set : SelectionSetNode ,
124- fields : Dict [str , List [FieldNode ]],
125- patches : List [PatchFields ],
126- visited_fragment_names : Set [str ],
126+ fields : dict [str , list [FieldNode ]],
127+ patches : list [PatchFields ],
128+ visited_fragment_names : set [str ],
127129) -> None :
128130 """Collect fields (internal implementation)."""
129- patch_fields : Dict [str , List [FieldNode ]]
131+ patch_fields : dict [str , list [FieldNode ]]
130132
131133 for selection in selection_set .selections :
132134 if isinstance (selection , FieldNode ):
@@ -216,14 +218,14 @@ def collect_fields_impl(
216218class DeferValues (NamedTuple ):
217219 """Values of an active defer directive."""
218220
219- label : Optional [ str ]
221+ label : str | None
220222
221223
222224def get_defer_values (
223225 operation : OperationDefinitionNode ,
224- variable_values : Dict [str , Any ],
225- node : Union [ FragmentSpreadNode , InlineFragmentNode ] ,
226- ) -> Optional [ DeferValues ] :
226+ variable_values : dict [str , Any ],
227+ node : FragmentSpreadNode | InlineFragmentNode ,
228+ ) -> DeferValues | None :
227229 """Get values of defer directive if active.
228230
229231 Returns an object containing the `@defer` arguments if a field should be
@@ -246,8 +248,8 @@ def get_defer_values(
246248
247249
248250def should_include_node (
249- variable_values : Dict [str , Any ],
250- node : Union [ FragmentSpreadNode , FieldNode , InlineFragmentNode ] ,
251+ variable_values : dict [str , Any ],
252+ node : FragmentSpreadNode | FieldNode | InlineFragmentNode ,
251253) -> bool :
252254 """Check if node should be included
253255
@@ -267,7 +269,7 @@ def should_include_node(
267269
268270def does_fragment_condition_match (
269271 schema : GraphQLSchema ,
270- fragment : Union [ FragmentDefinitionNode , InlineFragmentNode ] ,
272+ fragment : FragmentDefinitionNode | InlineFragmentNode ,
271273 type_ : GraphQLObjectType ,
272274) -> bool :
273275 """Determine if a fragment is applicable to the given type."""
0 commit comments