Skip to content

Commit 76fb6a6

Browse files
committed
Update ValidationContext for Fragment Args. Fixes typeInfo doc resetting
1 parent 938a983 commit 76fb6a6

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/validation/ValidationContext.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { GraphQLError } from '../error/GraphQLError.js';
55

66
import type {
77
DocumentNode,
8+
FragmentArgumentDefinitionNode,
89
FragmentDefinitionNode,
910
FragmentSpreadNode,
1011
OperationDefinitionNode,
@@ -26,13 +27,15 @@ import type {
2627
import type { GraphQLDirective } from '../type/directives.js';
2728
import type { GraphQLSchema } from '../type/schema.js';
2829

29-
import { TypeInfo, visitWithTypeInfo } from '../utilities/TypeInfo.js';
30+
import type { TypeInfo } from '../utilities/TypeInfo.js';
31+
import { visitWithTypeInfo } from '../utilities/TypeInfo.js';
3032

3133
type NodeWithSelectionSet = OperationDefinitionNode | FragmentDefinitionNode;
3234
interface VariableUsage {
3335
readonly node: VariableNode;
3436
readonly type: Maybe<GraphQLInputType>;
3537
readonly defaultValue: Maybe<unknown>;
38+
readonly fragmentArgDef: Maybe<FragmentArgumentDefinitionNode>;
3639
}
3740

3841
/**
@@ -199,16 +202,23 @@ export class ValidationContext extends ASTValidationContext {
199202
let usages = this._variableUsages.get(node);
200203
if (!usages) {
201204
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;
203208
visit(
204209
node,
205210
visitWithTypeInfo(typeInfo, {
206211
VariableDefinition: () => false,
212+
FragmentArgumentDefinition: () => false,
207213
Variable(variable) {
214+
const fragmentArgDef = localArgumentDefinitions?.find(
215+
(argDef) => argDef.variable.name.value === variable.name.value,
216+
);
208217
newUsages.push({
209218
node: variable,
210219
type: typeInfo.getInputType(),
211220
defaultValue: typeInfo.getDefaultValue(),
221+
fragmentArgDef,
212222
});
213223
},
214224
}),

0 commit comments

Comments
 (0)