Skip to content

Commit 222cbc1

Browse files
committed
Fix type issues
1 parent 197f1d3 commit 222cbc1

File tree

3 files changed

+65
-66
lines changed

3 files changed

+65
-66
lines changed

src/ast.ts

Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -27,53 +27,54 @@ import type {
2727
InputObjectTypeExtensionNode,
2828
} from './schemaAst';
2929

30-
export type ASTNode = Or<
31-
GraphQL.ASTNode,
32-
| NameNode
33-
| DocumentNode
34-
| OperationDefinitionNode
35-
| VariableDefinitionNode
36-
| VariableNode
37-
| SelectionSetNode
38-
| FieldNode
39-
| ArgumentNode
40-
| FragmentSpreadNode
41-
| FragmentArgumentNode
42-
| InlineFragmentNode
43-
| FragmentDefinitionNode
44-
| IntValueNode
45-
| FloatValueNode
46-
| StringValueNode
47-
| BooleanValueNode
48-
| NullValueNode
49-
| EnumValueNode
50-
| ListValueNode
51-
| ObjectValueNode
52-
| ObjectFieldNode
53-
| DirectiveNode
54-
| NamedTypeNode
55-
| ListTypeNode
56-
| NonNullTypeNode
57-
| SchemaDefinitionNode
58-
| OperationTypeDefinitionNode
59-
| ScalarTypeDefinitionNode
60-
| ObjectTypeDefinitionNode
61-
| FieldDefinitionNode
62-
| InputValueDefinitionNode
63-
| InterfaceTypeDefinitionNode
64-
| UnionTypeDefinitionNode
65-
| EnumTypeDefinitionNode
66-
| EnumValueDefinitionNode
67-
| InputObjectTypeDefinitionNode
68-
| DirectiveDefinitionNode
69-
| SchemaExtensionNode
70-
| ScalarTypeExtensionNode
71-
| ObjectTypeExtensionNode
72-
| InterfaceTypeExtensionNode
73-
| UnionTypeExtensionNode
74-
| EnumTypeExtensionNode
75-
| InputObjectTypeExtensionNode
76-
>;
30+
export type ASTNode =
31+
| Or<
32+
GraphQL.ASTNode,
33+
| NameNode
34+
| DocumentNode
35+
| OperationDefinitionNode
36+
| VariableDefinitionNode
37+
| VariableNode
38+
| SelectionSetNode
39+
| FieldNode
40+
| ArgumentNode
41+
| FragmentSpreadNode
42+
| InlineFragmentNode
43+
| FragmentDefinitionNode
44+
| IntValueNode
45+
| FloatValueNode
46+
| StringValueNode
47+
| BooleanValueNode
48+
| NullValueNode
49+
| EnumValueNode
50+
| ListValueNode
51+
| ObjectValueNode
52+
| ObjectFieldNode
53+
| DirectiveNode
54+
| NamedTypeNode
55+
| ListTypeNode
56+
| NonNullTypeNode
57+
| SchemaDefinitionNode
58+
| OperationTypeDefinitionNode
59+
| ScalarTypeDefinitionNode
60+
| ObjectTypeDefinitionNode
61+
| FieldDefinitionNode
62+
| InputValueDefinitionNode
63+
| InterfaceTypeDefinitionNode
64+
| UnionTypeDefinitionNode
65+
| EnumTypeDefinitionNode
66+
| EnumValueDefinitionNode
67+
| InputObjectTypeDefinitionNode
68+
| DirectiveDefinitionNode
69+
| SchemaExtensionNode
70+
| ScalarTypeExtensionNode
71+
| ObjectTypeExtensionNode
72+
| InterfaceTypeExtensionNode
73+
| UnionTypeExtensionNode
74+
| EnumTypeExtensionNode
75+
| InputObjectTypeExtensionNode
76+
>
77+
| FragmentArgumentNode;
7778

7879
export type NameNode = Or<
7980
GraphQL.NameNode,
@@ -148,10 +149,7 @@ export type SelectionSetNode = Or<
148149
}
149150
>;
150151

151-
export declare type SelectionNode = Or<
152-
GraphQL.SelectionNode,
153-
FieldNode | FragmentSpreadNode | InlineFragmentNode
154-
>;
152+
export declare type SelectionNode = FieldNode | FragmentSpreadNode | InlineFragmentNode;
155153

156154
export type FieldNode = Or<
157155
GraphQL.FieldNode,
@@ -187,7 +185,7 @@ export type ConstArgumentNode = Or<
187185
>;
188186

189187
export type FragmentArgumentNode = {
190-
readonly kind: Kind.FRAGMENT_ARGUMENT;
188+
readonly kind: 'FragmentArgument';
191189
readonly name: NameNode;
192190
readonly value: ValueNode;
193191
readonly loc?: Location;
@@ -222,13 +220,14 @@ export type FragmentDefinitionNode = Or<
222220
readonly kind: Kind.FRAGMENT_DEFINITION;
223221
readonly name: NameNode;
224222
readonly description?: StringValueNode;
225-
readonly variableDefinitions?: ReadonlyArray<VariableDefinitionNode>;
226223
readonly typeCondition: NamedTypeNode;
227224
readonly directives?: ReadonlyArray<DirectiveNode>;
228225
readonly selectionSet: SelectionSetNode;
229226
readonly loc?: Location;
230227
}
231-
>;
228+
> & {
229+
readonly variableDefinitions?: ReadonlyArray<VariableDefinitionNode>;
230+
};
232231

233232
export type ValueNode = Or<
234233
GraphQL.ValueNode,

src/kind.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export declare enum Kind {
88
SELECTION_SET = 'SelectionSet',
99
FIELD = 'Field',
1010
ARGUMENT = 'Argument',
11-
FRAGMENT_ARGUMENT = 'FragmentArgument',
1211
/** Fragments */
1312
FRAGMENT_SPREAD = 'FragmentSpread',
1413
INLINE_FRAGMENT = 'InlineFragment',

src/parser.ts

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

249+
function arguments_(constant: boolean, fragmentArgument: false): ast.ArgumentNode[] | undefined;
249250
function arguments_(
250251
constant: boolean,
251-
fragmentArgument?: boolean
252+
fragmentArgument: true
253+
): ast.FragmentArgumentNode[] | undefined;
254+
function arguments_(
255+
constant: boolean,
256+
fragmentArgument: boolean
252257
): ast.ArgumentNode[] | ast.FragmentArgumentNode[] | undefined {
253258
if (input.charCodeAt(idx) === 40 /*'('*/) {
254-
const args: ast.ArgumentNode[] | ast.FragmentArgumentNode[] = [];
259+
const args: (ast.ArgumentNode | ast.FragmentArgumentNode)[] = [];
255260
idx++;
256261
ignored();
257262
do {
258263
const name = nameNode();
259264
if (input.charCodeAt(idx++) !== 58 /*':'*/) throw error('Argument');
260265
ignored();
261266
args.push({
262-
kind: fragmentArgument
263-
? ('FragmentArgument' as Kind.FRAGMENT_ARGUMENT)
264-
: ('Argument' as Kind.ARGUMENT),
267+
kind: fragmentArgument ? 'FragmentArgument' : ('Argument' as Kind.ARGUMENT),
265268
name,
266269
value: value(constant),
267270
});
268271
} while (input.charCodeAt(idx) !== 41 /*')'*/);
269272
idx++;
270273
ignored();
271-
return args;
274+
return args as ast.ArgumentNode[] | ast.FragmentArgumentNode[];
272275
}
273276
}
274277

@@ -283,7 +286,7 @@ function directives(constant: boolean): ast.DirectiveNode[] | undefined {
283286
directives.push({
284287
kind: 'Directive' as Kind.DIRECTIVE,
285288
name: nameNode(),
286-
arguments: arguments_(constant),
289+
arguments: arguments_(constant, false),
287290
});
288291
} while (input.charCodeAt(idx) === 64 /*'@'*/);
289292
return directives;
@@ -363,7 +366,6 @@ function selectionSet(): ast.SelectionSetNode {
363366
selections.push({
364367
kind: 'FragmentSpread' as Kind.FRAGMENT_SPREAD,
365368
name: nameNode(),
366-
// @ts-expect-error
367369
arguments: arguments_(false, true) as readonly ast.FragmentArgumentNode[],
368370
directives: directives(false),
369371
});
@@ -385,8 +387,7 @@ function selectionSet(): ast.SelectionSetNode {
385387
selections.push({
386388
kind: 'FragmentSpread' as Kind.FRAGMENT_SPREAD,
387389
name: nameNode(),
388-
// @ts-expect-error
389-
arguments: arguments_(false, true) as readonly ast.FragmentArgumentNode[],
390+
arguments: arguments_(false, true),
390391
directives: directives(false),
391392
});
392393
}
@@ -399,7 +400,7 @@ function selectionSet(): ast.SelectionSetNode {
399400
alias = name;
400401
name = nameNode();
401402
}
402-
const _arguments = arguments_(false);
403+
const _arguments = arguments_(false, false);
403404
const _directives = directives(false);
404405
let _selectionSet: ast.SelectionSetNode | undefined;
405406
if (input.charCodeAt(idx) === 123 /*'{'*/) {

0 commit comments

Comments
 (0)