@@ -5,6 +5,7 @@ import type { GraphQLError } from '../error/GraphQLError.js';
5
5
6
6
import type {
7
7
DocumentNode ,
8
+ FragmentArgumentDefinitionNode ,
8
9
FragmentDefinitionNode ,
9
10
FragmentSpreadNode ,
10
11
OperationDefinitionNode ,
@@ -26,13 +27,15 @@ import type {
26
27
import type { GraphQLDirective } from '../type/directives.js' ;
27
28
import type { GraphQLSchema } from '../type/schema.js' ;
28
29
29
- import { TypeInfo , visitWithTypeInfo } from '../utilities/TypeInfo.js' ;
30
+ import type { TypeInfo } from '../utilities/TypeInfo.js' ;
31
+ import { visitWithTypeInfo } from '../utilities/TypeInfo.js' ;
30
32
31
33
type NodeWithSelectionSet = OperationDefinitionNode | FragmentDefinitionNode ;
32
34
interface VariableUsage {
33
35
readonly node : VariableNode ;
34
36
readonly type : Maybe < GraphQLInputType > ;
35
37
readonly defaultValue : Maybe < unknown > ;
38
+ readonly fragmentArgDef : Maybe < FragmentArgumentDefinitionNode > ;
36
39
}
37
40
38
41
/**
@@ -199,16 +202,23 @@ export class ValidationContext extends ASTValidationContext {
199
202
let usages = this . _variableUsages . get ( node ) ;
200
203
if ( ! usages ) {
201
204
const newUsages : Array < VariableUsage > = [ ] ;
202
- const typeInfo = new TypeInfo ( this . _schema ) ;
205
+ const typeInfo = this . _typeInfo ;
206
+ const localArgumentDefinitions =
207
+ node . kind === Kind . FRAGMENT_DEFINITION ? node . arguments : undefined ;
203
208
visit (
204
209
node ,
205
210
visitWithTypeInfo ( typeInfo , {
206
211
VariableDefinition : ( ) => false ,
212
+ FragmentArgumentDefinition : ( ) => false ,
207
213
Variable ( variable ) {
214
+ const fragmentArgDef = localArgumentDefinitions ?. find (
215
+ ( argDef ) => argDef . variable . name . value === variable . name . value ,
216
+ ) ;
208
217
newUsages . push ( {
209
218
node : variable ,
210
219
type : typeInfo . getInputType ( ) ,
211
220
defaultValue : typeInfo . getDefaultValue ( ) ,
221
+ fragmentArgDef,
212
222
} ) ;
213
223
} ,
214
224
} ) ,
0 commit comments