1
+ from collections import defaultdict
1
2
from typing import Any , Dict , List , Set , Union , cast
2
3
3
4
from ..language import (
@@ -39,7 +40,7 @@ def collect_fields(
39
40
40
41
For internal use only.
41
42
"""
42
- fields : Dict [str , List [FieldNode ]] = {}
43
+ fields : Dict [str , List [FieldNode ]] = defaultdict ( list )
43
44
collect_fields_impl (
44
45
schema , fragments , variable_values , runtime_type , selection_set , fields , set ()
45
46
)
@@ -64,7 +65,7 @@ def collect_sub_fields(
64
65
65
66
For internal use only.
66
67
"""
67
- sub_field_nodes : Dict [str , List [FieldNode ]] = {}
68
+ sub_field_nodes : Dict [str , List [FieldNode ]] = defaultdict ( list )
68
69
visited_fragment_names : Set [str ] = set ()
69
70
for node in field_nodes :
70
71
if node .selection_set :
@@ -94,8 +95,7 @@ def collect_fields_impl(
94
95
if isinstance (selection , FieldNode ):
95
96
if not should_include_node (variable_values , selection ):
96
97
continue
97
- name = get_field_entry_key (selection )
98
- fields .setdefault (name , []).append (selection )
98
+ fields [get_field_entry_key (selection )].append (selection )
99
99
elif isinstance (selection , InlineFragmentNode ):
100
100
if not should_include_node (
101
101
variable_values , selection
0 commit comments