1+ from collections import defaultdict
12from typing import Any , Dict , List , Set , Union , cast
23
34from ..language import (
@@ -39,7 +40,7 @@ def collect_fields(
3940
4041 For internal use only.
4142 """
42- fields : Dict [str , List [FieldNode ]] = {}
43+ fields : Dict [str , List [FieldNode ]] = defaultdict ( list )
4344 collect_fields_impl (
4445 schema , fragments , variable_values , runtime_type , selection_set , fields , set ()
4546 )
@@ -64,7 +65,7 @@ def collect_sub_fields(
6465
6566 For internal use only.
6667 """
67- sub_field_nodes : Dict [str , List [FieldNode ]] = {}
68+ sub_field_nodes : Dict [str , List [FieldNode ]] = defaultdict ( list )
6869 visited_fragment_names : Set [str ] = set ()
6970 for node in field_nodes :
7071 if node .selection_set :
@@ -94,8 +95,7 @@ def collect_fields_impl(
9495 if isinstance (selection , FieldNode ):
9596 if not should_include_node (variable_values , selection ):
9697 continue
97- name = get_field_entry_key (selection )
98- fields .setdefault (name , []).append (selection )
98+ fields [get_field_entry_key (selection )].append (selection )
9999 elif isinstance (selection , InlineFragmentNode ):
100100 if not should_include_node (
101101 variable_values , selection
0 commit comments