1
1
import { AccumulatorMap } from '../jsutils/AccumulatorMap.js' ;
2
2
import { inspect } from '../jsutils/inspect.js' ;
3
3
import { invariant } from '../jsutils/invariant.js' ;
4
- import { keyMap } from '../jsutils/keyMap.js' ;
5
4
import { mapValue } from '../jsutils/mapValue.js' ;
6
5
import type { Maybe } from '../jsutils/Maybe.js' ;
7
6
@@ -217,14 +216,13 @@ export function extendSchemaImpl(
217
216
return schemaConfig ;
218
217
}
219
218
220
- const typeMap = Object . create ( null ) ;
221
- for ( const existingType of schemaConfig . types ) {
222
- typeMap [ existingType . name ] = extendNamedType ( existingType ) ;
223
- }
219
+ const typeMap = new Map < string , GraphQLNamedType > (
220
+ schemaConfig . types . map ( ( type ) => [ type . name , extendNamedType ( type ) ] ) ,
221
+ ) ;
224
222
225
223
for ( const typeNode of typeDefs ) {
226
224
const name = typeNode . name . value ;
227
- typeMap [ name ] = stdTypeMap [ name ] ?? buildType ( typeNode ) ;
225
+ typeMap . set ( name , stdTypeMap . get ( name ) ?? buildType ( typeNode ) ) ;
228
226
}
229
227
230
228
const operationTypes = {
@@ -242,7 +240,7 @@ export function extendSchemaImpl(
242
240
return {
243
241
description : schemaDef ?. description ?. value ?? schemaConfig . description ,
244
242
...operationTypes ,
245
- types : Object . values ( typeMap ) ,
243
+ types : Array . from ( typeMap . values ( ) ) ,
246
244
directives : [
247
245
...schemaConfig . directives . map ( replaceDirective ) ,
248
246
...directiveDefs . map ( buildDirective ) ,
@@ -273,7 +271,7 @@ export function extendSchemaImpl(
273
271
// Note: While this could make early assertions to get the correctly
274
272
// typed values, that would throw immediately while type system
275
273
// validation with validateSchema() will produce more actionable results.
276
- return typeMap [ type . name ] ;
274
+ return typeMap . get ( type . name ) as T ;
277
275
}
278
276
279
277
function replaceDirective ( directive : GraphQLDirective ) : GraphQLDirective {
@@ -462,7 +460,7 @@ export function extendSchemaImpl(
462
460
463
461
function getNamedType ( node : NamedTypeNode ) : GraphQLNamedType {
464
462
const name = node . name . value ;
465
- const type = stdTypeMap [ name ] ?? typeMap [ name ] ;
463
+ const type = stdTypeMap . get ( name ) ?? typeMap . get ( name ) ;
466
464
467
465
if ( type === undefined ) {
468
466
throw new Error ( `Unknown type: "${ name } ".` ) ;
@@ -704,9 +702,11 @@ export function extendSchemaImpl(
704
702
}
705
703
}
706
704
707
- const stdTypeMap = keyMap (
708
- [ ...specifiedScalarTypes , ...introspectionTypes ] ,
709
- ( type ) => type . name ,
705
+ const stdTypeMap = new Map (
706
+ [ ...specifiedScalarTypes , ...introspectionTypes ] . map ( ( type ) => [
707
+ type . name ,
708
+ type ,
709
+ ] ) ,
710
710
) ;
711
711
712
712
/**
0 commit comments