@@ -83,10 +83,7 @@ export interface ParsedResolversConfig extends ParsedConfig {
83
83
}
84
84
85
85
type FieldDefinitionPrintFn = (
86
- parent : {
87
- node : ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode ;
88
- typeName : string ;
89
- } ,
86
+ parentName : string ,
90
87
avoidResolverOptionals : boolean
91
88
) => { value : string | null ; meta : { federation ?: { isResolveReference : boolean } } } ;
92
89
export type FieldDefinitionResult = [ { node : FieldDefinitionNode } , FieldDefinitionPrintFn ] ;
@@ -1530,15 +1527,17 @@ export class BaseResolversVisitor<
1530
1527
1531
1528
return [
1532
1529
{ node } ,
1533
- ( parentNode , avoidResolverOptionals ) => {
1534
- const parentName = parentNode . typeName ;
1535
-
1530
+ ( parentName , avoidResolverOptionals ) => {
1536
1531
const original : FieldDefinitionNode = parent [ key ] ;
1537
1532
const parentType = this . schema . getType ( parentName ) ;
1538
1533
const meta : ReturnType < FieldDefinitionPrintFn > [ 'meta' ] = { } ;
1534
+ const typeName = node . name as unknown as string ;
1535
+
1536
+ const fieldsToGenerate = this . _federation . findFieldNodesToGenerate ( { type : parentType } ) ;
1537
+ const shouldGenerateField =
1538
+ fieldsToGenerate . some ( field => field . name . value === typeName ) ||
1539
+ this . _federation . isResolveReferenceField ( node ) ;
1539
1540
1540
- const fieldsToGenerate = this . _federation . findFieldNodesToGenerate ( { node : parentNode . node } ) ;
1541
- const shouldGenerateField = fieldsToGenerate . some ( field => field . name === node . name ) ;
1542
1541
if ( ! shouldGenerateField ) {
1543
1542
return { value : null , meta } ;
1544
1543
}
@@ -1549,7 +1548,7 @@ export class BaseResolversVisitor<
1549
1548
? this . convertName (
1550
1549
parentName +
1551
1550
( this . config . addUnderscoreToArgsType ? '_' : '' ) +
1552
- this . convertName ( node . name , {
1551
+ this . convertName ( typeName , {
1553
1552
useTypesPrefix : false ,
1554
1553
useTypesSuffix : false ,
1555
1554
} ) +
@@ -1600,7 +1599,7 @@ export class BaseResolversVisitor<
1600
1599
1601
1600
if ( isSubscriptionType ) {
1602
1601
return {
1603
- mappedTypeKey : `${ mappedType } , "${ node . name } "` ,
1602
+ mappedTypeKey : `${ mappedType } , "${ typeName } "` ,
1604
1603
resolverType : 'SubscriptionResolver' ,
1605
1604
} ;
1606
1605
}
@@ -1623,7 +1622,7 @@ export class BaseResolversVisitor<
1623
1622
type : string ;
1624
1623
genericTypes : string [ ] ;
1625
1624
} = {
1626
- name : node . name as any ,
1625
+ name : typeName ,
1627
1626
modifier : avoidResolverOptionals ? '' : '?' ,
1628
1627
type : resolverType ,
1629
1628
genericTypes : [ mappedTypeKey , parentTypeSignature , contextType , argsType ] . filter ( f => f ) ,
@@ -1720,7 +1719,10 @@ export class BaseResolversVisitor<
1720
1719
}
1721
1720
1722
1721
ObjectTypeDefinition ( node : ObjectTypeDefinitionNode ) : string | null {
1723
- const fieldsToGenerate = this . _federation . findFieldNodesToGenerate ( { node } ) ;
1722
+ const typeName = node . name as unknown as string ;
1723
+ const type = this . schema . getType ( typeName ) ;
1724
+
1725
+ const fieldsToGenerate = this . _federation . findFieldNodesToGenerate ( { type } ) ;
1724
1726
if ( fieldsToGenerate . length === 0 ) {
1725
1727
return null ;
1726
1728
}
@@ -1729,7 +1731,6 @@ export class BaseResolversVisitor<
1729
1731
const name = this . convertName ( node , {
1730
1732
suffix : this . config . resolverTypeSuffix ,
1731
1733
} ) ;
1732
- const typeName = node . name as any as string ;
1733
1734
const parentType = this . getParentTypeToUse ( typeName ) ;
1734
1735
1735
1736
const rootType = ( ( ) : false | 'query' | 'mutation' | 'subscription' => {
@@ -1748,7 +1749,7 @@ export class BaseResolversVisitor<
1748
1749
const fieldsContent = ( node . fields as unknown as FieldDefinitionResult [ ] )
1749
1750
. map ( ( [ _ , f ] ) => {
1750
1751
return f (
1751
- { node , typeName } ,
1752
+ typeName ,
1752
1753
( rootType === 'query' && this . config . avoidOptionals . query ) ||
1753
1754
( rootType === 'mutation' && this . config . avoidOptionals . mutation ) ||
1754
1755
( rootType === 'subscription' && this . config . avoidOptionals . subscription ) ||
@@ -1982,7 +1983,7 @@ export class BaseResolversVisitor<
1982
1983
// An Interface in Federation may have the additional __resolveReference resolver, if resolvable.
1983
1984
// So, we filter out the normal fields declared on the Interface and add the __resolveReference resolver.
1984
1985
const fields = ( node . fields as unknown as FieldDefinitionResult [ ] ) . map ( ( [ _ , f ] ) =>
1985
- f ( { node , typeName } , this . config . avoidOptionals . resolvers )
1986
+ f ( typeName , this . config . avoidOptionals . resolvers )
1986
1987
) ;
1987
1988
for ( const field of fields ) {
1988
1989
if ( field . meta . federation ?. isResolveReference ) {
0 commit comments