@@ -376,6 +376,7 @@ export class BaseResolversVisitor<
376
376
protected _hasFederation = false ;
377
377
protected _fieldContextTypeMap : FieldContextTypeMap ;
378
378
private _directiveResolverMappings : Record < string , string > ;
379
+ private _shouldMapType : { [ typeName : string ] : boolean } = { } ;
379
380
380
381
constructor (
381
382
rawConfig : TRawConfig ,
@@ -438,15 +439,7 @@ export class BaseResolversVisitor<
438
439
return `export type ResolverTypeWrapper<T> = ${ this . config . resolverTypeWrapperSignature } ;` ;
439
440
}
440
441
441
- protected shouldMapType (
442
- type : GraphQLNamedType ,
443
- checkedBefore : { [ typeName : string ] : boolean } = { } ,
444
- duringCheck : string [ ] = [ ]
445
- ) : boolean {
446
- if ( checkedBefore [ type . name ] !== undefined ) {
447
- return checkedBefore [ type . name ] ;
448
- }
449
-
442
+ protected shouldMapType ( type : GraphQLNamedType , duringCheck : string [ ] = [ ] ) : boolean {
450
443
if ( type . name . startsWith ( '__' ) || this . config . scalars [ type . name ] ) {
451
444
return false ;
452
445
}
@@ -469,16 +462,16 @@ export class BaseResolversVisitor<
469
462
const field = fields [ fieldName ] ;
470
463
const fieldType = getBaseType ( field . type ) ;
471
464
472
- if ( checkedBefore [ fieldType . name ] !== undefined ) {
473
- return checkedBefore [ fieldType . name ] ;
465
+ if ( this . _shouldMapType [ fieldType . name ] !== undefined ) {
466
+ return this . _shouldMapType [ fieldType . name ] ;
474
467
}
475
468
476
469
if ( this . config . mappers [ type . name ] ) {
477
470
return true ;
478
471
}
479
472
480
473
duringCheck . push ( type . name ) ;
481
- const innerResult = this . shouldMapType ( fieldType , checkedBefore , duringCheck ) ;
474
+ const innerResult = this . shouldMapType ( fieldType , duringCheck ) ;
482
475
483
476
return innerResult ;
484
477
} ) ;
@@ -507,13 +500,17 @@ export class BaseResolversVisitor<
507
500
shouldInclude ?: ( type : GraphQLNamedType ) => boolean
508
501
) : ResolverTypes {
509
502
const allSchemaTypes = this . _schema . getTypeMap ( ) ;
510
- const nestedMapping : { [ typeName : string ] : boolean } = { } ;
511
503
const typeNames = this . _federation . filterTypeNames ( Object . keys ( allSchemaTypes ) ) ;
512
504
513
- typeNames . forEach ( typeName => {
514
- const schemaType = allSchemaTypes [ typeName ] ;
515
- nestedMapping [ typeName ] = this . shouldMapType ( schemaType , nestedMapping ) ;
516
- } ) ;
505
+ // avoid checking all types recursively if we have no `mappers` defined
506
+ if ( Object . keys ( this . config . mappers ) . length > 0 ) {
507
+ typeNames . forEach ( typeName => {
508
+ if ( this . _shouldMapType [ typeName ] === undefined ) {
509
+ const schemaType = allSchemaTypes [ typeName ] ;
510
+ this . _shouldMapType [ typeName ] = this . shouldMapType ( schemaType ) ;
511
+ }
512
+ } ) ;
513
+ }
517
514
518
515
return typeNames . reduce ( ( prev : ResolverTypes , typeName : string ) => {
519
516
const schemaType = allSchemaTypes [ typeName ] ;
@@ -594,7 +591,7 @@ export class BaseResolversVisitor<
594
591
const baseType = getBaseType ( field . type ) ;
595
592
const isUnion = isUnionType ( baseType ) ;
596
593
597
- if ( ! this . config . mappers [ baseType . name ] && ! isUnion && ! nestedMapping [ baseType . name ] ) {
594
+ if ( ! this . config . mappers [ baseType . name ] && ! isUnion && ! this . _shouldMapType [ baseType . name ] ) {
598
595
return null ;
599
596
}
600
597
0 commit comments