@@ -12,6 +12,7 @@ import {
1212import { resolveTemplate } from './ast/resolve' ;
1313import {
1414 FragmentDefinitionNode ,
15+ Kind ,
1516 parse ,
1617 print ,
1718 visit ,
@@ -183,8 +184,22 @@ export const generateHashForDocument = (
183184 foundFilename ,
184185 info
185186 ) . combinedText ;
187+ const parsed = parse ( text ) ;
188+ const seen = new Set < unknown > ( ) ;
189+ for ( const definition of parsed . definitions ) {
190+ if (
191+ definition . kind === Kind . FRAGMENT_DEFINITION &&
192+ ! seen . has ( definition )
193+ ) {
194+ stripUnmaskDirectivesFromDefinition ( definition ) ;
195+ }
196+ }
197+
186198 const deduplicatedFragments = fragments
187- . map ( fragment => print ( fragment ) )
199+ . map ( fragment => {
200+ stripUnmaskDirectivesFromDefinition ( fragment ) ;
201+ return print ( fragment )
202+ } )
188203 . filter ( ( fragment , index , array ) => array . indexOf ( fragment ) === index ) ;
189204
190205 deduplicatedFragments . forEach ( fragmentDefinition => {
@@ -203,6 +218,16 @@ export const generateHashForDocument = (
203218 ) . combinedText ;
204219
205220 const parsed = parse ( text ) ;
221+ const seen = new Set < unknown > ( ) ;
222+ for ( const definition of parsed . definitions ) {
223+ if (
224+ definition . kind === Kind . FRAGMENT_DEFINITION &&
225+ ! seen . has ( definition )
226+ ) {
227+ stripUnmaskDirectivesFromDefinition ( definition ) ;
228+ }
229+ }
230+
206231 const spreads = new Set < string > ( ) ;
207232 visit ( parsed , {
208233 FragmentSpread : node => {
@@ -227,6 +252,8 @@ export const generateHashForDocument = (
227252 return ;
228253 }
229254
255+ stripUnmaskDirectivesFromDefinition ( fragmentDefinition ) ;
256+
230257 visit ( fragmentDefinition , {
231258 FragmentSpread : node => {
232259 if ( ! visited . has ( node . name . value ) )
@@ -322,3 +349,14 @@ export const getDocumentReferenceFromDocumentNode = (
322349 return { node : documentNodeArgument , filename } ;
323350 }
324351} ;
352+
353+ type writable < T > = { - readonly [ K in keyof T ] : T [ K ] } ;
354+
355+ const stripUnmaskDirectivesFromDefinition = (
356+ definition : FragmentDefinitionNode
357+ ) => {
358+ ( definition as writable < FragmentDefinitionNode > ) . directives =
359+ definition . directives ?. filter (
360+ directive => directive . name . value !== '_unmask'
361+ ) ;
362+ } ;
0 commit comments