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 {
@@ -462,7 +460,7 @@ export function extendSchemaImpl(
462460
463461 function getNamedType ( node : NamedTypeNode ) : GraphQLNamedType {
464462 const name = node . name . value ;
465- const type = stdTypeMap [ name ] ?? typeMap [ name ] ;
463+ const type = stdTypeMap . get ( name ) ?? typeMap . get ( name ) ;
466464
467465 if ( type === undefined ) {
468466 throw new Error ( `Unknown type: "${ name } ".` ) ;
@@ -704,9 +702,11 @@ export function extendSchemaImpl(
704702 }
705703}
706704
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+ ] ) ,
710710) ;
711711
712712/**
0 commit comments