@@ -114,7 +114,7 @@ export function OverlappingFieldsCanBeMergedRule(
114114 // selection set.
115115 cachedFieldsAndFragmentSpreads : new Map ( ) ,
116116 } ;
117- let fragmentVarMap : Map < string , ValueNode > | undefined ;
117+ let fragmentVarMap : VariableMap | undefined ;
118118
119119 return {
120120 FragmentDefinition : {
@@ -162,10 +162,12 @@ type NodeAndDef = [
162162] ;
163163// Map of array of those.
164164type NodeAndDefCollection = Map < string , Array < NodeAndDef > > ;
165+ // Variable-map identity distinguishes fragment scopes in the caches.
166+ type VariableMap = Map < string , ValueNode > ;
165167interface FragmentSpread {
166168 key : string ;
167169 node : FragmentSpreadNode ;
168- varMap : Map < string , ValueNode > | undefined ;
170+ varMap : VariableMap | undefined ;
169171}
170172type FragmentSpreads = ReadonlyArray < FragmentSpread > ;
171173type FieldsAndFragmentSpreads = readonly [
@@ -174,7 +176,7 @@ type FieldsAndFragmentSpreads = readonly [
174176] ;
175177type FieldsAndFragmentSpreadsCache = Map <
176178 SelectionSetNode ,
177- Map < Map < string , ValueNode > | undefined , FieldsAndFragmentSpreads >
179+ Map < VariableMap | undefined , FieldsAndFragmentSpreads >
178180> ;
179181interface RuleContext {
180182 comparedFieldsAndFragmentPairs : OrderedPairSet < NodeAndDefCollection , string > ;
@@ -246,7 +248,7 @@ function findConflictsWithinSelectionSet(
246248 ruleContext : RuleContext ,
247249 parentType : Maybe < GraphQLNamedType > ,
248250 selectionSet : SelectionSetNode ,
249- varMap : Map < string , ValueNode > | undefined ,
251+ varMap : VariableMap | undefined ,
250252) : Array < Conflict > {
251253 const conflicts : Array < Conflict > = [ ] ;
252254
@@ -308,7 +310,7 @@ function collectConflictsBetweenFieldsAndFragment(
308310 conflicts : Array < Conflict > ,
309311 areMutuallyExclusive : boolean ,
310312 fieldMap : NodeAndDefCollection ,
311- varMap : Map < string , ValueNode > | undefined ,
313+ varMap : VariableMap | undefined ,
312314 fragmentSpread : FragmentSpread ,
313315) : void {
314316 const { comparedFieldsAndFragmentPairs } = ruleContext ;
@@ -499,10 +501,10 @@ function findConflictsBetweenSubSelectionSets(
499501 areMutuallyExclusive : boolean ,
500502 parentType1 : Maybe < GraphQLNamedType > ,
501503 selectionSet1 : SelectionSetNode ,
502- varMap1 : Map < string , ValueNode > | undefined ,
504+ varMap1 : VariableMap | undefined ,
503505 parentType2 : Maybe < GraphQLNamedType > ,
504506 selectionSet2 : SelectionSetNode ,
505- varMap2 : Map < string , ValueNode > | undefined ,
507+ varMap2 : VariableMap | undefined ,
506508) : Array < Conflict > {
507509 const conflicts : Array < Conflict > = [ ] ;
508510
@@ -585,7 +587,7 @@ function collectConflictsWithin(
585587 ruleContext : RuleContext ,
586588 conflicts : Array < Conflict > ,
587589 fieldMap : NodeAndDefCollection ,
588- varMap : Map < string , ValueNode > | undefined ,
590+ varMap : VariableMap | undefined ,
589591) : void {
590592 // A field map is a keyed collection, where each key represents a response
591593 // name and the value at that key is a list of all fields which provide that
@@ -628,9 +630,9 @@ function collectConflictsBetween(
628630 conflicts : Array < Conflict > ,
629631 parentFieldsAreMutuallyExclusive : boolean ,
630632 fieldMap1 : NodeAndDefCollection ,
631- varMap1 : Map < string , ValueNode > | undefined ,
633+ varMap1 : VariableMap | undefined ,
632634 fieldMap2 : NodeAndDefCollection ,
633- varMap2 : Map < string , ValueNode > | undefined ,
635+ varMap2 : VariableMap | undefined ,
634636) : void {
635637 // A field map is a keyed collection, where each key represents a response
636638 // name and the value at that key is a list of all fields which provide that
@@ -669,9 +671,9 @@ function findConflict(
669671 parentFieldsAreMutuallyExclusive : boolean ,
670672 responseName : string ,
671673 field1 : NodeAndDef ,
672- varMap1 : Map < string , ValueNode > | undefined ,
674+ varMap1 : VariableMap | undefined ,
673675 field2 : NodeAndDef ,
674- varMap2 : Map < string , ValueNode > | undefined ,
676+ varMap2 : VariableMap | undefined ,
675677) : Maybe < Conflict > {
676678 const [ parentType1 , node1 , def1 ] = field1 ;
677679 const [ parentType2 , node2 , def2 ] = field2 ;
@@ -764,9 +766,9 @@ function findConflict(
764766
765767function sameArguments < T extends ArgumentNode | FragmentArgumentNode > (
766768 args1 : ReadonlyArray < T > | undefined ,
767- varMap1 : Map < string , ValueNode > | undefined ,
769+ varMap1 : VariableMap | undefined ,
768770 args2 : ReadonlyArray < T > | undefined ,
769- varMap2 : Map < string , ValueNode > | undefined ,
771+ varMap2 : VariableMap | undefined ,
770772) : boolean {
771773 if ( args1 === undefined || args1 . length === 0 ) {
772774 return args2 === undefined || args2 . length === 0 ;
@@ -801,7 +803,7 @@ function sameArguments<T extends ArgumentNode | FragmentArgumentNode>(
801803
802804function replaceFragmentVariables (
803805 valueNode : ValueNode ,
804- varMap : ReadonlyMap < string , ValueNode > ,
806+ varMap : VariableMap ,
805807) : ValueNode {
806808 switch ( valueNode . kind ) {
807809 case Kind . VARIABLE :
@@ -839,9 +841,9 @@ function getStreamDirective(
839841
840842function hasNoOverlappingStreams (
841843 directives1 : ReadonlyArray < DirectiveNode > | undefined ,
842- varMap1 : Map < string , ValueNode > | undefined ,
844+ varMap1 : VariableMap | undefined ,
843845 directives2 : ReadonlyArray < DirectiveNode > | undefined ,
844- varMap2 : Map < string , ValueNode > | undefined ,
846+ varMap2 : VariableMap | undefined ,
845847) : string | undefined {
846848 const stream1 = getStreamDirective ( directives1 ) ;
847849 const stream2 = getStreamDirective ( directives2 ) ;
@@ -897,7 +899,7 @@ function getFieldsAndFragmentSpreads(
897899 ruleContext : RuleContext ,
898900 parentType : Maybe < GraphQLNamedType > ,
899901 selectionSet : SelectionSetNode ,
900- varMap : Map < string , ValueNode > | undefined ,
902+ varMap : VariableMap | undefined ,
901903) : FieldsAndFragmentSpreads {
902904 const { cachedFieldsAndFragmentSpreads } = ruleContext ;
903905 let cache = cachedFieldsAndFragmentSpreads . get ( selectionSet ) ;
@@ -933,7 +935,7 @@ function getReferencedFieldsAndFragmentSpreads(
933935 validationContext : ValidationContext ,
934936 ruleContext : RuleContext ,
935937 fragment : FragmentDefinitionNode ,
936- varMap : Map < string , ValueNode > | undefined ,
938+ varMap : VariableMap | undefined ,
937939) {
938940 const { cachedFieldsAndFragmentSpreads } = ruleContext ;
939941 // Short-circuit building a type from the node if possible.
@@ -963,7 +965,7 @@ function _collectFieldsAndFragmentSpreads(
963965 selectionSet : SelectionSetNode ,
964966 nodeAndDefs : NodeAndDefCollection ,
965967 fragmentSpreads : Map < string , FragmentSpread > ,
966- varMap : Map < string , ValueNode > | undefined ,
968+ varMap : VariableMap | undefined ,
967969) : void {
968970 for ( const selection of selectionSet . selections ) {
969971 switch ( selection . kind ) {
@@ -1016,7 +1018,7 @@ function _collectFieldsAndFragmentSpreads(
10161018function getFragmentSpread (
10171019 validationContext : ValidationContext ,
10181020 fragmentSpreadNode : FragmentSpreadNode ,
1019- varMap : Map < string , ValueNode > | undefined ,
1021+ varMap : VariableMap | undefined ,
10201022) : FragmentSpread {
10211023 let key = '' ;
10221024 const fragmentSignature = validationContext . getFragmentSignatureByName ( ) (
@@ -1051,7 +1053,7 @@ function getFragmentSpread(
10511053function getVarMap (
10521054 fragmentSignature : ReturnType < ValidationContext [ 'getFragmentSignature' ] > ,
10531055 key = '' ,
1054- ) : Map < string , ValueNode > | undefined {
1056+ ) : VariableMap | undefined {
10551057 if ( ! fragmentSignature || fragmentSignature . variableDefinitions . size === 0 ) {
10561058 return ;
10571059 }
0 commit comments