@@ -548,6 +548,7 @@ export class SelectionSetToObject<Config extends ParsedDocumentsConfig = ParsedD
548548 selectionNodes = [ ...selectionNodes ] ;
549549 let inlineFragmentConditional = false ;
550550 for ( const selectionNode of selectionNodes ) {
551+ // 1. Handle Field or Directtives selection nodes
551552 if ( 'kind' in selectionNode ) {
552553 if ( selectionNode . kind === 'Field' ) {
553554 if ( selectionNode . selectionSet ) {
@@ -598,21 +599,31 @@ export class SelectionSetToObject<Config extends ParsedDocumentsConfig = ParsedD
598599 continue ;
599600 }
600601
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
603606
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 ;
605612
606613 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' )
609616 ) {
617+ isMasked = false ;
618+ }
619+
620+ if ( isMasked ) {
621+ fragmentsSpreadUsages . push ( selectionNode . typeName ) ;
610622 continue ;
611623 }
612624 }
613625
614- // Handle Fragment Spreads by generating inline types.
615-
626+ // 2b. If the Fragment Spread is not masked, generate inline types.
616627 const fragmentType = this . _schema . getType ( selectionNode . onType ) ;
617628
618629 if ( fragmentType == null ) {
0 commit comments