11import { AccumulatorMap } from '../jsutils/AccumulatorMap.js' ;
22import { inspect } from '../jsutils/inspect.js' ;
33import { invariant } from '../jsutils/invariant.js' ;
4- import { keyMap } from '../jsutils/keyMap.js' ;
54import { mapValue } from '../jsutils/mapValue.js' ;
65import type { Maybe } from '../jsutils/Maybe.js' ;
76
@@ -217,14 +216,13 @@ export function extendSchemaImpl(
217216 return schemaConfig ;
218217 }
219218
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+ ) ;
224222
225223 for ( const typeNode of typeDefs ) {
226224 const name = typeNode . name . value ;
227- typeMap [ name ] = stdTypeMap [ name ] ?? buildType ( typeNode ) ;
225+ typeMap . set ( name , stdTypeMap . get ( name ) ?? buildType ( typeNode ) ) ;
228226 }
229227
230228 const operationTypes = {
@@ -242,7 +240,7 @@ export function extendSchemaImpl(
242240 return {
243241 description : schemaDef ?. description ?. value ?? schemaConfig . description ,
244242 ...operationTypes ,
245- types : Object . values ( typeMap ) ,
243+ types : Array . from ( typeMap . values ( ) ) ,
246244 directives : [
247245 ...schemaConfig . directives . map ( replaceDirective ) ,
248246 ...directiveDefs . map ( buildDirective ) ,
@@ -273,7 +271,7 @@ export function extendSchemaImpl(
273271 // Note: While this could make early assertions to get the correctly
274272 // typed values, that would throw immediately while type system
275273 // validation with validateSchema() will produce more actionable results.
276- return typeMap [ type . name ] ;
274+ return typeMap . get ( type . name ) as T ;
277275 }
278276
279277 function replaceDirective ( directive : GraphQLDirective ) : GraphQLDirective {
@@ -461,7 +459,7 @@ export function extendSchemaImpl(
461459
462460 function getNamedType ( node : NamedTypeNode ) : GraphQLNamedType {
463461 const name = node . name . value ;
464- const type = stdTypeMap [ name ] ?? typeMap [ name ] ;
462+ const type = stdTypeMap . get ( name ) ?? typeMap . get ( name ) ;
465463
466464 if ( type === undefined ) {
467465 throw new Error ( `Unknown type: "${ name } ".` ) ;
@@ -703,9 +701,11 @@ export function extendSchemaImpl(
703701 }
704702}
705703
706- const stdTypeMap = keyMap (
707- [ ...specifiedScalarTypes , ...introspectionTypes ] ,
708- ( type ) => type . name ,
704+ const stdTypeMap = new Map (
705+ [ ...specifiedScalarTypes , ...introspectionTypes ] . map ( ( type ) => [
706+ type . name ,
707+ type ,
708+ ] ) ,
709709) ;
710710
711711/**
0 commit comments