@@ -548,6 +548,7 @@ export class SelectionSetToObject<Config extends ParsedDocumentsConfig = ParsedD
548
548
selectionNodes = [ ...selectionNodes ] ;
549
549
let inlineFragmentConditional = false ;
550
550
for ( const selectionNode of selectionNodes ) {
551
+ // 1. Handle Field or Directtives selection nodes
551
552
if ( 'kind' in selectionNode ) {
552
553
if ( selectionNode . kind === 'Field' ) {
553
554
if ( selectionNode . selectionSet ) {
@@ -598,21 +599,31 @@ export class SelectionSetToObject<Config extends ParsedDocumentsConfig = ParsedD
598
599
continue ;
599
600
}
600
601
601
- if ( this . _config . inlineFragmentTypes === 'combine' || this . _config . inlineFragmentTypes === 'mask' ) {
602
- fragmentsSpreadUsages . push ( selectionNode . typeName ) ;
602
+ // 2. Handle Fragment Spread nodes
603
+ // A Fragment Spread can be:
604
+ // - masked: the fields declared in the Fragment do not appear in the operation types
605
+ // - inline: the fields declared in the Fragment appear in the operation types
603
606
604
- const isApolloUnmaskEnabled = this . _config . customDirectives . apolloUnmask ;
607
+ // 2a. If `inlineFragmentTypes` is 'combine' or 'mask', the Fragment Spread is masked by default
608
+ // In some cases, a masked node could be unmasked (i.e. treated as inline):
609
+ // - Fragment spread node is marked with Apollo `@unmask`, e.g. `...User @unmask`
610
+ if ( this . _config . inlineFragmentTypes === 'combine' || this . _config . inlineFragmentTypes === 'mask' ) {
611
+ let isMasked = true ;
605
612
606
613
if (
607
- ! isApolloUnmaskEnabled ||
608
- ( isApolloUnmaskEnabled && ! selectionNode . fragmentDirectives ? .some ( d => d . name . value === 'unmask' ) )
614
+ this . _config . customDirectives . apolloUnmask &&
615
+ selectionNode . fragmentDirectives . some ( d => d . name . value === 'unmask' )
609
616
) {
617
+ isMasked = false ;
618
+ }
619
+
620
+ if ( isMasked ) {
621
+ fragmentsSpreadUsages . push ( selectionNode . typeName ) ;
610
622
continue ;
611
623
}
612
624
}
613
625
614
- // Handle Fragment Spreads by generating inline types.
615
-
626
+ // 2b. If the Fragment Spread is not masked, generate inline types.
616
627
const fragmentType = this . _schema . getType ( selectionNode . onType ) ;
617
628
618
629
if ( fragmentType == null ) {
0 commit comments