1
+ import { AccumulatorMap } from '../jsutils/AccumulatorMap' ;
1
2
import type { ObjMap } from '../jsutils/ObjMap' ;
2
3
3
4
import type {
@@ -37,7 +38,7 @@ export function collectFields(
37
38
runtimeType : GraphQLObjectType ,
38
39
selectionSet : SelectionSetNode ,
39
40
) : Map < string , ReadonlyArray < FieldNode > > {
40
- const fields = new Map ( ) ;
41
+ const fields = new AccumulatorMap < string , FieldNode > ( ) ;
41
42
collectFieldsImpl (
42
43
schema ,
43
44
fragments ,
@@ -67,7 +68,7 @@ export function collectSubfields(
67
68
returnType : GraphQLObjectType ,
68
69
fieldNodes : ReadonlyArray < FieldNode > ,
69
70
) : Map < string , ReadonlyArray < FieldNode > > {
70
- const subFieldNodes = new Map ( ) ;
71
+ const subFieldNodes = new AccumulatorMap < string , FieldNode > ( ) ;
71
72
const visitedFragmentNames = new Set < string > ( ) ;
72
73
for ( const node of fieldNodes ) {
73
74
if ( node . selectionSet ) {
@@ -91,7 +92,7 @@ function collectFieldsImpl(
91
92
variableValues : { [ variable : string ] : unknown } ,
92
93
runtimeType : GraphQLObjectType ,
93
94
selectionSet : SelectionSetNode ,
94
- fields : Map < string , Array < FieldNode > > ,
95
+ fields : AccumulatorMap < string , FieldNode > ,
95
96
visitedFragmentNames : Set < string > ,
96
97
) : void {
97
98
for ( const selection of selectionSet . selections ) {
@@ -100,13 +101,7 @@ function collectFieldsImpl(
100
101
if ( ! shouldIncludeNode ( variableValues , selection ) ) {
101
102
continue ;
102
103
}
103
- const name = getFieldEntryKey ( selection ) ;
104
- const fieldList = fields . get ( name ) ;
105
- if ( fieldList !== undefined ) {
106
- fieldList . push ( selection ) ;
107
- } else {
108
- fields . set ( name , [ selection ] ) ;
109
- }
104
+ fields . add ( getFieldEntryKey ( selection ) , selection ) ;
110
105
break ;
111
106
}
112
107
case Kind . INLINE_FRAGMENT : {
0 commit comments