UNPKG

15.9 kBTypeScriptView Raw
1import type { Kind } from './kinds';
2import type { Source } from './source';
3import type { TokenKind } from './tokenKind';
4/**
5 * Contains a range of UTF-8 character offsets and token references that
6 * identify the region of the source from which the AST derived.
7 */
8export declare class Location {
9 /**
10 * The character offset at which this Node begins.
11 */
12 readonly start: number;
13 /**
14 * The character offset at which this Node ends.
15 */
16 readonly end: number;
17 /**
18 * The Token at which this Node begins.
19 */
20 readonly startToken: Token;
21 /**
22 * The Token at which this Node ends.
23 */
24 readonly endToken: Token;
25 /**
26 * The Source document the AST represents.
27 */
28 readonly source: Source;
29 constructor(startToken: Token, endToken: Token, source: Source);
30 get [Symbol.toStringTag](): string;
31 toJSON(): {
32 start: number;
33 end: number;
34 };
35}
36/**
37 * Represents a range of characters represented by a lexical token
38 * within a Source.
39 */
40export declare class Token {
41 /**
42 * The kind of Token.
43 */
44 readonly kind: TokenKind;
45 /**
46 * The character offset at which this Node begins.
47 */
48 readonly start: number;
49 /**
50 * The character offset at which this Node ends.
51 */
52 readonly end: number;
53 /**
54 * The 1-indexed line number on which this Token appears.
55 */
56 readonly line: number;
57 /**
58 * The 1-indexed column number at which this Token begins.
59 */
60 readonly column: number;
61 /**
62 * For non-punctuation tokens, represents the interpreted value of the token.
63 *
64 * Note: is undefined for punctuation tokens, but typed as string for
65 * convenience in the parser.
66 */
67 readonly value: string;
68 /**
69 * Tokens exist as nodes in a double-linked-list amongst all tokens
70 * including ignored tokens. <SOF> is always the first node and <EOF>
71 * the last.
72 */
73 readonly prev: Token | null;
74 readonly next: Token | null;
75 constructor(
76 kind: TokenKind,
77 start: number,
78 end: number,
79 line: number,
80 column: number,
81 value?: string,
82 );
83 get [Symbol.toStringTag](): string;
84 toJSON(): {
85 kind: TokenKind;
86 value?: string;
87 line: number;
88 column: number;
89 };
90}
91/**
92 * The list of all possible AST node types.
93 */
94export declare type ASTNode =
95 | NameNode
96 | DocumentNode
97 | OperationDefinitionNode
98 | VariableDefinitionNode
99 | VariableNode
100 | SelectionSetNode
101 | FieldNode
102 | ArgumentNode
103 | FragmentSpreadNode
104 | InlineFragmentNode
105 | FragmentDefinitionNode
106 | IntValueNode
107 | FloatValueNode
108 | StringValueNode
109 | BooleanValueNode
110 | NullValueNode
111 | EnumValueNode
112 | ListValueNode
113 | ObjectValueNode
114 | ObjectFieldNode
115 | DirectiveNode
116 | NamedTypeNode
117 | ListTypeNode
118 | NonNullTypeNode
119 | SchemaDefinitionNode
120 | OperationTypeDefinitionNode
121 | ScalarTypeDefinitionNode
122 | ObjectTypeDefinitionNode
123 | FieldDefinitionNode
124 | InputValueDefinitionNode
125 | InterfaceTypeDefinitionNode
126 | UnionTypeDefinitionNode
127 | EnumTypeDefinitionNode
128 | EnumValueDefinitionNode
129 | InputObjectTypeDefinitionNode
130 | DirectiveDefinitionNode
131 | SchemaExtensionNode
132 | ScalarTypeExtensionNode
133 | ObjectTypeExtensionNode
134 | InterfaceTypeExtensionNode
135 | UnionTypeExtensionNode
136 | EnumTypeExtensionNode
137 | InputObjectTypeExtensionNode;
138/**
139 * Utility type listing all nodes indexed by their kind.
140 */
141export declare type ASTKindToNode = {
142 [NodeT in ASTNode as NodeT['kind']]: NodeT;
143};
144/**
145 * @internal
146 */
147export declare const QueryDocumentKeys: {
148 [NodeT in ASTNode as NodeT['kind']]: ReadonlyArray<keyof NodeT>;
149};
150/**
151 * @internal
152 */
153export declare function isNode(maybeNode: any): maybeNode is ASTNode;
154/** Name */
155export interface NameNode {
156 readonly kind: Kind.NAME;
157 readonly loc?: Location;
158 readonly value: string;
159}
160/** Document */
161export interface DocumentNode {
162 readonly kind: Kind.DOCUMENT;
163 readonly loc?: Location;
164 readonly definitions: ReadonlyArray<DefinitionNode>;
165 readonly tokenCount?: number | undefined;
166}
167export declare type DefinitionNode =
168 | ExecutableDefinitionNode
169 | TypeSystemDefinitionNode
170 | TypeSystemExtensionNode;
171export declare type ExecutableDefinitionNode =
172 | OperationDefinitionNode
173 | FragmentDefinitionNode;
174export interface OperationDefinitionNode {
175 readonly kind: Kind.OPERATION_DEFINITION;
176 readonly loc?: Location;
177 readonly operation: OperationTypeNode;
178 readonly name?: NameNode;
179 readonly variableDefinitions?: ReadonlyArray<VariableDefinitionNode>;
180 readonly directives?: ReadonlyArray<DirectiveNode>;
181 readonly selectionSet: SelectionSetNode;
182}
183declare enum OperationTypeNode {
184 QUERY = 'query',
185 MUTATION = 'mutation',
186 SUBSCRIPTION = 'subscription',
187}
188export { OperationTypeNode };
189export interface VariableDefinitionNode {
190 readonly kind: Kind.VARIABLE_DEFINITION;
191 readonly loc?: Location;
192 readonly variable: VariableNode;
193 readonly type: TypeNode;
194 readonly defaultValue?: ConstValueNode;
195 readonly directives?: ReadonlyArray<ConstDirectiveNode>;
196}
197export interface VariableNode {
198 readonly kind: Kind.VARIABLE;
199 readonly loc?: Location;
200 readonly name: NameNode;
201}
202export interface SelectionSetNode {
203 kind: Kind.SELECTION_SET;
204 loc?: Location;
205 selections: ReadonlyArray<SelectionNode>;
206}
207export declare type SelectionNode =
208 | FieldNode
209 | FragmentSpreadNode
210 | InlineFragmentNode;
211export interface FieldNode {
212 readonly kind: Kind.FIELD;
213 readonly loc?: Location;
214 readonly alias?: NameNode;
215 readonly name: NameNode;
216 readonly arguments?: ReadonlyArray<ArgumentNode>;
217 readonly directives?: ReadonlyArray<DirectiveNode>;
218 readonly selectionSet?: SelectionSetNode;
219}
220export interface ArgumentNode {
221 readonly kind: Kind.ARGUMENT;
222 readonly loc?: Location;
223 readonly name: NameNode;
224 readonly value: ValueNode;
225}
226export interface ConstArgumentNode {
227 readonly kind: Kind.ARGUMENT;
228 readonly loc?: Location;
229 readonly name: NameNode;
230 readonly value: ConstValueNode;
231}
232/** Fragments */
233export interface FragmentSpreadNode {
234 readonly kind: Kind.FRAGMENT_SPREAD;
235 readonly loc?: Location;
236 readonly name: NameNode;
237 readonly directives?: ReadonlyArray<DirectiveNode>;
238}
239export interface InlineFragmentNode {
240 readonly kind: Kind.INLINE_FRAGMENT;
241 readonly loc?: Location;
242 readonly typeCondition?: NamedTypeNode;
243 readonly directives?: ReadonlyArray<DirectiveNode>;
244 readonly selectionSet: SelectionSetNode;
245}
246export interface FragmentDefinitionNode {
247 readonly kind: Kind.FRAGMENT_DEFINITION;
248 readonly loc?: Location;
249 readonly name: NameNode;
250 /** @deprecated variableDefinitions will be removed in v17.0.0 */
251 readonly variableDefinitions?: ReadonlyArray<VariableDefinitionNode>;
252 readonly typeCondition: NamedTypeNode;
253 readonly directives?: ReadonlyArray<DirectiveNode>;
254 readonly selectionSet: SelectionSetNode;
255}
256/** Values */
257export declare type ValueNode =
258 | VariableNode
259 | IntValueNode
260 | FloatValueNode
261 | StringValueNode
262 | BooleanValueNode
263 | NullValueNode
264 | EnumValueNode
265 | ListValueNode
266 | ObjectValueNode;
267export declare type ConstValueNode =
268 | IntValueNode
269 | FloatValueNode
270 | StringValueNode
271 | BooleanValueNode
272 | NullValueNode
273 | EnumValueNode
274 | ConstListValueNode
275 | ConstObjectValueNode;
276export interface IntValueNode {
277 readonly kind: Kind.INT;
278 readonly loc?: Location;
279 readonly value: string;
280}
281export interface FloatValueNode {
282 readonly kind: Kind.FLOAT;
283 readonly loc?: Location;
284 readonly value: string;
285}
286export interface StringValueNode {
287 readonly kind: Kind.STRING;
288 readonly loc?: Location;
289 readonly value: string;
290 readonly block?: boolean;
291}
292export interface BooleanValueNode {
293 readonly kind: Kind.BOOLEAN;
294 readonly loc?: Location;
295 readonly value: boolean;
296}
297export interface NullValueNode {
298 readonly kind: Kind.NULL;
299 readonly loc?: Location;
300}
301export interface EnumValueNode {
302 readonly kind: Kind.ENUM;
303 readonly loc?: Location;
304 readonly value: string;
305}
306export interface ListValueNode {
307 readonly kind: Kind.LIST;
308 readonly loc?: Location;
309 readonly values: ReadonlyArray<ValueNode>;
310}
311export interface ConstListValueNode {
312 readonly kind: Kind.LIST;
313 readonly loc?: Location;
314 readonly values: ReadonlyArray<ConstValueNode>;
315}
316export interface ObjectValueNode {
317 readonly kind: Kind.OBJECT;
318 readonly loc?: Location;
319 readonly fields: ReadonlyArray<ObjectFieldNode>;
320}
321export interface ConstObjectValueNode {
322 readonly kind: Kind.OBJECT;
323 readonly loc?: Location;
324 readonly fields: ReadonlyArray<ConstObjectFieldNode>;
325}
326export interface ObjectFieldNode {
327 readonly kind: Kind.OBJECT_FIELD;
328 readonly loc?: Location;
329 readonly name: NameNode;
330 readonly value: ValueNode;
331}
332export interface ConstObjectFieldNode {
333 readonly kind: Kind.OBJECT_FIELD;
334 readonly loc?: Location;
335 readonly name: NameNode;
336 readonly value: ConstValueNode;
337}
338/** Directives */
339export interface DirectiveNode {
340 readonly kind: Kind.DIRECTIVE;
341 readonly loc?: Location;
342 readonly name: NameNode;
343 readonly arguments?: ReadonlyArray<ArgumentNode>;
344}
345export interface ConstDirectiveNode {
346 readonly kind: Kind.DIRECTIVE;
347 readonly loc?: Location;
348 readonly name: NameNode;
349 readonly arguments?: ReadonlyArray<ConstArgumentNode>;
350}
351/** Type Reference */
352export declare type TypeNode = NamedTypeNode | ListTypeNode | NonNullTypeNode;
353export interface NamedTypeNode {
354 readonly kind: Kind.NAMED_TYPE;
355 readonly loc?: Location;
356 readonly name: NameNode;
357}
358export interface ListTypeNode {
359 readonly kind: Kind.LIST_TYPE;
360 readonly loc?: Location;
361 readonly type: TypeNode;
362}
363export interface NonNullTypeNode {
364 readonly kind: Kind.NON_NULL_TYPE;
365 readonly loc?: Location;
366 readonly type: NamedTypeNode | ListTypeNode;
367}
368/** Type System Definition */
369export declare type TypeSystemDefinitionNode =
370 | SchemaDefinitionNode
371 | TypeDefinitionNode
372 | DirectiveDefinitionNode;
373export interface SchemaDefinitionNode {
374 readonly kind: Kind.SCHEMA_DEFINITION;
375 readonly loc?: Location;
376 readonly description?: StringValueNode;
377 readonly directives?: ReadonlyArray<ConstDirectiveNode>;
378 readonly operationTypes: ReadonlyArray<OperationTypeDefinitionNode>;
379}
380export interface OperationTypeDefinitionNode {
381 readonly kind: Kind.OPERATION_TYPE_DEFINITION;
382 readonly loc?: Location;
383 readonly operation: OperationTypeNode;
384 readonly type: NamedTypeNode;
385}
386/** Type Definition */
387export declare type TypeDefinitionNode =
388 | ScalarTypeDefinitionNode
389 | ObjectTypeDefinitionNode
390 | InterfaceTypeDefinitionNode
391 | UnionTypeDefinitionNode
392 | EnumTypeDefinitionNode
393 | InputObjectTypeDefinitionNode;
394export interface ScalarTypeDefinitionNode {
395 readonly kind: Kind.SCALAR_TYPE_DEFINITION;
396 readonly loc?: Location;
397 readonly description?: StringValueNode;
398 readonly name: NameNode;
399 readonly directives?: ReadonlyArray<ConstDirectiveNode>;
400}
401export interface ObjectTypeDefinitionNode {
402 readonly kind: Kind.OBJECT_TYPE_DEFINITION;
403 readonly loc?: Location;
404 readonly description?: StringValueNode;
405 readonly name: NameNode;
406 readonly interfaces?: ReadonlyArray<NamedTypeNode>;
407 readonly directives?: ReadonlyArray<ConstDirectiveNode>;
408 readonly fields?: ReadonlyArray<FieldDefinitionNode>;
409}
410export interface FieldDefinitionNode {
411 readonly kind: Kind.FIELD_DEFINITION;
412 readonly loc?: Location;
413 readonly description?: StringValueNode;
414 readonly name: NameNode;
415 readonly arguments?: ReadonlyArray<InputValueDefinitionNode>;
416 readonly type: TypeNode;
417 readonly directives?: ReadonlyArray<ConstDirectiveNode>;
418}
419export interface InputValueDefinitionNode {
420 readonly kind: Kind.INPUT_VALUE_DEFINITION;
421 readonly loc?: Location;
422 readonly description?: StringValueNode;
423 readonly name: NameNode;
424 readonly type: TypeNode;
425 readonly defaultValue?: ConstValueNode;
426 readonly directives?: ReadonlyArray<ConstDirectiveNode>;
427}
428export interface InterfaceTypeDefinitionNode {
429 readonly kind: Kind.INTERFACE_TYPE_DEFINITION;
430 readonly loc?: Location;
431 readonly description?: StringValueNode;
432 readonly name: NameNode;
433 readonly interfaces?: ReadonlyArray<NamedTypeNode>;
434 readonly directives?: ReadonlyArray<ConstDirectiveNode>;
435 readonly fields?: ReadonlyArray<FieldDefinitionNode>;
436}
437export interface UnionTypeDefinitionNode {
438 readonly kind: Kind.UNION_TYPE_DEFINITION;
439 readonly loc?: Location;
440 readonly description?: StringValueNode;
441 readonly name: NameNode;
442 readonly directives?: ReadonlyArray<ConstDirectiveNode>;
443 readonly types?: ReadonlyArray<NamedTypeNode>;
444}
445export interface EnumTypeDefinitionNode {
446 readonly kind: Kind.ENUM_TYPE_DEFINITION;
447 readonly loc?: Location;
448 readonly description?: StringValueNode;
449 readonly name: NameNode;
450 readonly directives?: ReadonlyArray<ConstDirectiveNode>;
451 readonly values?: ReadonlyArray<EnumValueDefinitionNode>;
452}
453export interface EnumValueDefinitionNode {
454 readonly kind: Kind.ENUM_VALUE_DEFINITION;
455 readonly loc?: Location;
456 readonly description?: StringValueNode;
457 readonly name: NameNode;
458 readonly directives?: ReadonlyArray<ConstDirectiveNode>;
459}
460export interface InputObjectTypeDefinitionNode {
461 readonly kind: Kind.INPUT_OBJECT_TYPE_DEFINITION;
462 readonly loc?: Location;
463 readonly description?: StringValueNode;
464 readonly name: NameNode;
465 readonly directives?: ReadonlyArray<ConstDirectiveNode>;
466 readonly fields?: ReadonlyArray<InputValueDefinitionNode>;
467}
468/** Directive Definitions */
469export interface DirectiveDefinitionNode {
470 readonly kind: Kind.DIRECTIVE_DEFINITION;
471 readonly loc?: Location;
472 readonly description?: StringValueNode;
473 readonly name: NameNode;
474 readonly arguments?: ReadonlyArray<InputValueDefinitionNode>;
475 readonly repeatable: boolean;
476 readonly locations: ReadonlyArray<NameNode>;
477}
478/** Type System Extensions */
479export declare type TypeSystemExtensionNode =
480 | SchemaExtensionNode
481 | TypeExtensionNode;
482export interface SchemaExtensionNode {
483 readonly kind: Kind.SCHEMA_EXTENSION;
484 readonly loc?: Location;
485 readonly directives?: ReadonlyArray<ConstDirectiveNode>;
486 readonly operationTypes?: ReadonlyArray<OperationTypeDefinitionNode>;
487}
488/** Type Extensions */
489export declare type TypeExtensionNode =
490 | ScalarTypeExtensionNode
491 | ObjectTypeExtensionNode
492 | InterfaceTypeExtensionNode
493 | UnionTypeExtensionNode
494 | EnumTypeExtensionNode
495 | InputObjectTypeExtensionNode;
496export interface ScalarTypeExtensionNode {
497 readonly kind: Kind.SCALAR_TYPE_EXTENSION;
498 readonly loc?: Location;
499 readonly name: NameNode;
500 readonly directives?: ReadonlyArray<ConstDirectiveNode>;
501}
502export interface ObjectTypeExtensionNode {
503 readonly kind: Kind.OBJECT_TYPE_EXTENSION;
504 readonly loc?: Location;
505 readonly name: NameNode;
506 readonly interfaces?: ReadonlyArray<NamedTypeNode>;
507 readonly directives?: ReadonlyArray<ConstDirectiveNode>;
508 readonly fields?: ReadonlyArray<FieldDefinitionNode>;
509}
510export interface InterfaceTypeExtensionNode {
511 readonly kind: Kind.INTERFACE_TYPE_EXTENSION;
512 readonly loc?: Location;
513 readonly name: NameNode;
514 readonly interfaces?: ReadonlyArray<NamedTypeNode>;
515 readonly directives?: ReadonlyArray<ConstDirectiveNode>;
516 readonly fields?: ReadonlyArray<FieldDefinitionNode>;
517}
518export interface UnionTypeExtensionNode {
519 readonly kind: Kind.UNION_TYPE_EXTENSION;
520 readonly loc?: Location;
521 readonly name: NameNode;
522 readonly directives?: ReadonlyArray<ConstDirectiveNode>;
523 readonly types?: ReadonlyArray<NamedTypeNode>;
524}
525export interface EnumTypeExtensionNode {
526 readonly kind: Kind.ENUM_TYPE_EXTENSION;
527 readonly loc?: Location;
528 readonly name: NameNode;
529 readonly directives?: ReadonlyArray<ConstDirectiveNode>;
530 readonly values?: ReadonlyArray<EnumValueDefinitionNode>;
531}
532export interface InputObjectTypeExtensionNode {
533 readonly kind: Kind.INPUT_OBJECT_TYPE_EXTENSION;
534 readonly loc?: Location;
535 readonly name: NameNode;
536 readonly directives?: ReadonlyArray<ConstDirectiveNode>;
537 readonly fields?: ReadonlyArray<InputValueDefinitionNode>;
538}