@@ -36,6 +36,7 @@ import {
3636}  from  'graphql' ; 
3737import  {  getDocumentMetadata  }  from  './getDocumentMetadata.js' ; 
3838import  {  getTypeInfo ,  getTypeInfoWithType  }  from  './getTypeInfo.js' ; 
39+ import  {  handleOverrideByDelegation  }  from  './handleOverrideByDelegation.js' ; 
3940import  {  Subschema  }  from  './Subschema.js' ; 
4041import  {  DelegationContext ,  StitchingInfo  }  from  './types.js' ; 
4142import  { 
@@ -82,6 +83,7 @@ function finalizeGatewayDocument<TContext>(
8283      validFragmentsWithType , 
8384      operation . selectionSet , 
8485      onOverlappingAliases , 
86+       delegationContext , 
8587    ) ; 
8688
8789    usedFragments  =  union ( usedFragments ,  operationUsedFragments ) ; 
@@ -97,6 +99,7 @@ function finalizeGatewayDocument<TContext>(
9799      validFragmentsWithType , 
98100      usedFragments , 
99101      onOverlappingAliases , 
102+       delegationContext , 
100103    ) ; 
101104    const  operationOrFragmentVariables  =  union ( 
102105      operationUsedVariables , 
@@ -393,6 +396,7 @@ function collectFragmentVariables(
393396  validFragmentsWithType : {  [ name : string ] : GraphQLType  } , 
394397  usedFragments : Array < string > , 
395398  onOverlappingAliases : ( )  =>  void , 
399+   delegationContext : DelegationContext < any > , 
396400)  { 
397401  let  remainingFragments  =  usedFragments . slice ( ) ; 
398402
@@ -423,6 +427,7 @@ function collectFragmentVariables(
423427        validFragmentsWithType , 
424428        fragment . selectionSet , 
425429        onOverlappingAliases , 
430+         delegationContext , 
426431      ) ; 
427432      remainingFragments  =  union ( remainingFragments ,  fragmentUsedFragments ) ; 
428433      usedVariables  =  union ( usedVariables ,  fragmentUsedVariables ) ; 
@@ -477,6 +482,7 @@ function finalizeSelectionSet(
477482  validFragments : {  [ name : string ] : GraphQLType  } , 
478483  selectionSet : SelectionSetNode , 
479484  onOverlappingAliases : ( )  =>  void , 
485+   delegationContext : DelegationContext < any > , 
480486)  { 
481487  const  usedFragments : Array < string >  =  [ ] ; 
482488  const  usedVariables : Array < string >  =  [ ] ; 
@@ -494,6 +500,7 @@ function finalizeSelectionSet(
494500    usedFragments , 
495501    seenNonNullableMap , 
496502    seenNullableMap , 
503+     delegationContext , 
497504  ) ; 
498505
499506  visit ( 
@@ -525,15 +532,37 @@ function filterSelectionSet(
525532  usedFragments : Array < string > , 
526533  seenNonNullableMap : WeakMap < readonly  ASTNode [ ] ,  Set < string > > , 
527534  seenNullableMap : WeakMap < readonly  ASTNode [ ] ,  Set < string > > , 
535+   delegationContext : DelegationContext < any > , 
528536)  { 
529537  return  visit ( 
530538    selectionSet , 
531539    visitWithTypeInfo ( typeInfo ,  { 
532540      [ Kind . FIELD ] : { 
533541        enter : ( node )  =>  { 
534542          const  parentType  =  typeInfo . getParentType ( ) ; 
543+           const  field  =  typeInfo . getFieldDef ( ) ; 
544+           if  ( 
545+             delegationContext . context  !=  null  && 
546+             delegationContext . info  !=  null  && 
547+             parentType  !=  null  && 
548+             field  !=  null 
549+           )  { 
550+             const  parentTypeName  =  parentType . name ; 
551+             const  overrideConfig  = 
552+               delegationContext . subschemaConfig ?. merge ?. [ parentTypeName ] 
553+                 ?. fields ?. [ field . name ] ?. override ; 
554+             if  ( overrideConfig  !=  null )  { 
555+               const  overridden  =  handleOverrideByDelegation ( 
556+                 delegationContext . info , 
557+                 delegationContext . context , 
558+                 overrideConfig . handle , 
559+               ) ; 
560+               if  ( ! overridden )  { 
561+                 return  null ; 
562+               } 
563+             } 
564+           } 
535565          if  ( isObjectType ( parentType )  ||  isInterfaceType ( parentType ) )  { 
536-             const  field  =  typeInfo . getFieldDef ( ) ; 
537566            if  ( ! field )  { 
538567              return  null ; 
539568            } 
@@ -624,6 +653,7 @@ function filterSelectionSet(
624653                  usedFragments , 
625654                  seenNonNullableMap , 
626655                  seenNullableMap , 
656+                   delegationContext , 
627657                ) ; 
628658
629659                if  ( ! fieldFilteredSelectionSet . selections . length )  { 
0 commit comments