Skip to content

Commit 197f1d3

Browse files
committed
Add FragmentArgumentKind
1 parent b1279ee commit 197f1d3

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

src/__tests__/__snapshots__/parser.test.ts.snap

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,7 @@ exports[`parse > parses the kitchen sink document like graphql.js does 1`] = `
645645
"value": {
646646
"block": true,
647647
"kind": "StringValue",
648-
"value": "block string uses """
649-
",
648+
"value": "block string uses """",
650649
},
651650
},
652651
],

src/__tests__/parser.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ describe('parse', () => {
244244
},
245245
arguments: [
246246
{
247-
kind: 'Argument',
247+
kind: 'FragmentArgument',
248248
name: {
249249
kind: 'Name',
250250
value: 'varA',
@@ -255,7 +255,7 @@ describe('parse', () => {
255255
},
256256
},
257257
{
258-
kind: 'Argument',
258+
kind: 'FragmentArgument',
259259
name: {
260260
kind: 'Name',
261261
value: 'varB',

src/ast.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export type ASTNode = Or<
3838
| FieldNode
3939
| ArgumentNode
4040
| FragmentSpreadNode
41+
| FragmentArgumentNode
4142
| InlineFragmentNode
4243
| FragmentDefinitionNode
4344
| IntValueNode
@@ -185,6 +186,13 @@ export type ConstArgumentNode = Or<
185186
}
186187
>;
187188

189+
export type FragmentArgumentNode = {
190+
readonly kind: Kind.FRAGMENT_ARGUMENT;
191+
readonly name: NameNode;
192+
readonly value: ValueNode;
193+
readonly loc?: Location;
194+
};
195+
188196
export type FragmentSpreadNode = Or<
189197
GraphQL.FragmentSpreadNode,
190198
{
@@ -194,7 +202,7 @@ export type FragmentSpreadNode = Or<
194202
readonly loc?: Location;
195203
}
196204
> & {
197-
readonly arguments?: ReadonlyArray<ArgumentNode>;
205+
readonly arguments?: ReadonlyArray<FragmentArgumentNode>;
198206
};
199207

200208
export type InlineFragmentNode = Or<

src/parser.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,17 +246,22 @@ function value(constant: boolean): ast.ValueNode {
246246
};
247247
}
248248

249-
function arguments_(constant: boolean): ast.ArgumentNode[] | undefined {
249+
function arguments_(
250+
constant: boolean,
251+
fragmentArgument?: boolean
252+
): ast.ArgumentNode[] | ast.FragmentArgumentNode[] | undefined {
250253
if (input.charCodeAt(idx) === 40 /*'('*/) {
251-
const args: ast.ArgumentNode[] = [];
254+
const args: ast.ArgumentNode[] | ast.FragmentArgumentNode[] = [];
252255
idx++;
253256
ignored();
254257
do {
255258
const name = nameNode();
256259
if (input.charCodeAt(idx++) !== 58 /*':'*/) throw error('Argument');
257260
ignored();
258261
args.push({
259-
kind: 'Argument' as Kind.ARGUMENT,
262+
kind: fragmentArgument
263+
? ('FragmentArgument' as Kind.FRAGMENT_ARGUMENT)
264+
: ('Argument' as Kind.ARGUMENT),
260265
name,
261266
value: value(constant),
262267
});
@@ -358,7 +363,8 @@ function selectionSet(): ast.SelectionSetNode {
358363
selections.push({
359364
kind: 'FragmentSpread' as Kind.FRAGMENT_SPREAD,
360365
name: nameNode(),
361-
arguments: arguments_(false),
366+
// @ts-expect-error
367+
arguments: arguments_(false, true) as readonly ast.FragmentArgumentNode[],
362368
directives: directives(false),
363369
});
364370
}
@@ -379,7 +385,8 @@ function selectionSet(): ast.SelectionSetNode {
379385
selections.push({
380386
kind: 'FragmentSpread' as Kind.FRAGMENT_SPREAD,
381387
name: nameNode(),
382-
arguments: arguments_(false),
388+
// @ts-expect-error
389+
arguments: arguments_(false, true) as readonly ast.FragmentArgumentNode[],
383390
directives: directives(false),
384391
});
385392
}

0 commit comments

Comments
 (0)