@@ -326,7 +326,7 @@ function validateInterfaces(
326
326
context : SchemaValidationContext ,
327
327
type : GraphQLObjectType | GraphQLInterfaceType ,
328
328
) : void {
329
- const ifaceTypeNames = Object . create ( null ) ;
329
+ const ifaceTypeNames = new Set < string > ( ) ;
330
330
for ( const iface of type . getInterfaces ( ) ) {
331
331
if ( ! isInterfaceType ( iface ) ) {
332
332
context . reportError (
@@ -345,15 +345,15 @@ function validateInterfaces(
345
345
continue ;
346
346
}
347
347
348
- if ( ifaceTypeNames [ iface . name ] ) {
348
+ if ( ifaceTypeNames . has ( iface . name ) ) {
349
349
context . reportError (
350
350
`Type ${ type . name } can only implement ${ iface . name } once.` ,
351
351
getAllImplementsInterfaceNodes ( type , iface ) ,
352
352
) ;
353
353
continue ;
354
354
}
355
355
356
- ifaceTypeNames [ iface . name ] = true ;
356
+ ifaceTypeNames . add ( iface . name ) ;
357
357
358
358
validateTypeImplementsAncestors ( context , type , iface ) ;
359
359
validateTypeImplementsInterface ( context , type , iface ) ;
@@ -470,16 +470,16 @@ function validateUnionMembers(
470
470
) ;
471
471
}
472
472
473
- const includedTypeNames = Object . create ( null ) ;
473
+ const includedTypeNames = new Set < string > ( ) ;
474
474
for ( const memberType of memberTypes ) {
475
- if ( includedTypeNames [ memberType . name ] ) {
475
+ if ( includedTypeNames . has ( memberType . name ) ) {
476
476
context . reportError (
477
477
`Union type ${ union . name } can only include type ${ memberType . name } once.` ,
478
478
getUnionMemberTypeNodes ( union , memberType . name ) ,
479
479
) ;
480
480
continue ;
481
481
}
482
- includedTypeNames [ memberType . name ] = true ;
482
+ includedTypeNames . add ( memberType . name ) ;
483
483
if ( ! isObjectType ( memberType ) ) {
484
484
context . reportError (
485
485
`Union type ${ union . name } can only include Object types, ` +
@@ -551,7 +551,7 @@ function createInputObjectCircularRefsValidator(
551
551
// Modified copy of algorithm from 'src/validation/rules/NoFragmentCycles.js'.
552
552
// Tracks already visited types to maintain O(N) and to ensure that cycles
553
553
// are not redundantly reported.
554
- const visitedTypes = Object . create ( null ) ;
554
+ const visitedTypes = new Set < GraphQLInputObjectType > ( ) ;
555
555
556
556
// Array of types nodes used to produce meaningful errors
557
557
const fieldPath : Array < GraphQLInputField > = [ ] ;
@@ -565,11 +565,11 @@ function createInputObjectCircularRefsValidator(
565
565
// It does not terminate when a cycle was found but continues to explore
566
566
// the graph to find all possible cycles.
567
567
function detectCycleRecursive ( inputObj : GraphQLInputObjectType ) : void {
568
- if ( visitedTypes [ inputObj . name ] ) {
568
+ if ( visitedTypes . has ( inputObj ) ) {
569
569
return ;
570
570
}
571
571
572
- visitedTypes [ inputObj . name ] = true ;
572
+ visitedTypes . add ( inputObj ) ;
573
573
fieldPathIndexByTypeName [ inputObj . name ] = fieldPath . length ;
574
574
575
575
const fields = Object . values ( inputObj . getFields ( ) ) ;
0 commit comments