Skip to content

Commit d48d502

Browse files
refactor(language/ast.d.ts): use Kind enum type (#2984)
Co-authored-by: Ivan Goncharov <[email protected]>
1 parent b1ce2c3 commit d48d502

File tree

1 file changed

+44
-43
lines changed

1 file changed

+44
-43
lines changed

src/language/ast.ts

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Kind } from './kinds';
12
import type { Source } from './source';
23
import type { TokenKindEnum } from './tokenKind';
34

@@ -332,15 +333,15 @@ export function isNode(maybeNode: any): maybeNode is ASTNode {
332333
/** Name */
333334

334335
export interface NameNode {
335-
readonly kind: 'Name';
336+
readonly kind: typeof Kind.NAME;
336337
readonly loc?: Location;
337338
readonly value: string;
338339
}
339340

340341
/** Document */
341342

342343
export interface DocumentNode {
343-
readonly kind: 'Document';
344+
readonly kind: typeof Kind.DOCUMENT;
344345
readonly loc?: Location;
345346
readonly definitions: ReadonlyArray<DefinitionNode>;
346347
}
@@ -355,7 +356,7 @@ export type ExecutableDefinitionNode =
355356
| FragmentDefinitionNode;
356357

357358
export interface OperationDefinitionNode {
358-
readonly kind: 'OperationDefinition';
359+
readonly kind: typeof Kind.OPERATION_DEFINITION;
359360
readonly loc?: Location;
360361
readonly operation: OperationTypeNode;
361362
readonly name?: NameNode;
@@ -367,7 +368,7 @@ export interface OperationDefinitionNode {
367368
export type OperationTypeNode = 'query' | 'mutation' | 'subscription';
368369

369370
export interface VariableDefinitionNode {
370-
readonly kind: 'VariableDefinition';
371+
readonly kind: typeof Kind.VARIABLE_DEFINITION;
371372
readonly loc?: Location;
372373
readonly variable: VariableNode;
373374
readonly type: TypeNode;
@@ -376,21 +377,21 @@ export interface VariableDefinitionNode {
376377
}
377378

378379
export interface VariableNode {
379-
readonly kind: 'Variable';
380+
readonly kind: typeof Kind.VARIABLE;
380381
readonly loc?: Location;
381382
readonly name: NameNode;
382383
}
383384

384385
export interface SelectionSetNode {
385-
kind: 'SelectionSet';
386+
kind: typeof Kind.SELECTION_SET;
386387
loc?: Location;
387388
selections: ReadonlyArray<SelectionNode>;
388389
}
389390

390391
export type SelectionNode = FieldNode | FragmentSpreadNode | InlineFragmentNode;
391392

392393
export interface FieldNode {
393-
readonly kind: 'Field';
394+
readonly kind: typeof Kind.FIELD;
394395
readonly loc?: Location;
395396
readonly alias?: NameNode;
396397
readonly name: NameNode;
@@ -400,7 +401,7 @@ export interface FieldNode {
400401
}
401402

402403
export interface ArgumentNode {
403-
readonly kind: 'Argument';
404+
readonly kind: typeof Kind.ARGUMENT;
404405
readonly loc?: Location;
405406
readonly name: NameNode;
406407
readonly value: ValueNode;
@@ -416,22 +417,22 @@ export interface ConstArgumentNode {
416417
/** Fragments */
417418

418419
export interface FragmentSpreadNode {
419-
readonly kind: 'FragmentSpread';
420+
readonly kind: typeof Kind.FRAGMENT_SPREAD;
420421
readonly loc?: Location;
421422
readonly name: NameNode;
422423
readonly directives?: ReadonlyArray<DirectiveNode>;
423424
}
424425

425426
export interface InlineFragmentNode {
426-
readonly kind: 'InlineFragment';
427+
readonly kind: typeof Kind.INLINE_FRAGMENT;
427428
readonly loc?: Location;
428429
readonly typeCondition?: NamedTypeNode;
429430
readonly directives?: ReadonlyArray<DirectiveNode>;
430431
readonly selectionSet: SelectionSetNode;
431432
}
432433

433434
export interface FragmentDefinitionNode {
434-
readonly kind: 'FragmentDefinition';
435+
readonly kind: typeof Kind.FRAGMENT_DEFINITION;
435436
readonly loc?: Location;
436437
readonly name: NameNode;
437438
/** @deprecated variableDefinitions will be removed in v17.0.0 */
@@ -465,43 +466,43 @@ export type ConstValueNode =
465466
| ConstObjectValueNode;
466467

467468
export interface IntValueNode {
468-
readonly kind: 'IntValue';
469+
readonly kind: typeof Kind.INT;
469470
readonly loc?: Location;
470471
readonly value: string;
471472
}
472473

473474
export interface FloatValueNode {
474-
readonly kind: 'FloatValue';
475+
readonly kind: typeof Kind.FLOAT;
475476
readonly loc?: Location;
476477
readonly value: string;
477478
}
478479

479480
export interface StringValueNode {
480-
readonly kind: 'StringValue';
481+
readonly kind: typeof Kind.STRING;
481482
readonly loc?: Location;
482483
readonly value: string;
483484
readonly block?: boolean;
484485
}
485486

486487
export interface BooleanValueNode {
487-
readonly kind: 'BooleanValue';
488+
readonly kind: typeof Kind.BOOLEAN;
488489
readonly loc?: Location;
489490
readonly value: boolean;
490491
}
491492

492493
export interface NullValueNode {
493-
readonly kind: 'NullValue';
494+
readonly kind: typeof Kind.NULL;
494495
readonly loc?: Location;
495496
}
496497

497498
export interface EnumValueNode {
498-
readonly kind: 'EnumValue';
499+
readonly kind: typeof Kind.ENUM;
499500
readonly loc?: Location;
500501
readonly value: string;
501502
}
502503

503504
export interface ListValueNode {
504-
readonly kind: 'ListValue';
505+
readonly kind: typeof Kind.LIST;
505506
readonly loc?: Location;
506507
readonly values: ReadonlyArray<ValueNode>;
507508
}
@@ -513,7 +514,7 @@ export interface ConstListValueNode {
513514
}
514515

515516
export interface ObjectValueNode {
516-
readonly kind: 'ObjectValue';
517+
readonly kind: typeof Kind.OBJECT;
517518
readonly loc?: Location;
518519
readonly fields: ReadonlyArray<ObjectFieldNode>;
519520
}
@@ -525,7 +526,7 @@ export interface ConstObjectValueNode {
525526
}
526527

527528
export interface ObjectFieldNode {
528-
readonly kind: 'ObjectField';
529+
readonly kind: typeof Kind.OBJECT_FIELD;
529530
readonly loc?: Location;
530531
readonly name: NameNode;
531532
readonly value: ValueNode;
@@ -541,7 +542,7 @@ export interface ConstObjectFieldNode {
541542
/** Directives */
542543

543544
export interface DirectiveNode {
544-
readonly kind: 'Directive';
545+
readonly kind: typeof Kind.DIRECTIVE;
545546
readonly loc?: Location;
546547
readonly name: NameNode;
547548
readonly arguments?: ReadonlyArray<ArgumentNode>;
@@ -559,19 +560,19 @@ export interface ConstDirectiveNode {
559560
export type TypeNode = NamedTypeNode | ListTypeNode | NonNullTypeNode;
560561

561562
export interface NamedTypeNode {
562-
readonly kind: 'NamedType';
563+
readonly kind: typeof Kind.NAMED_TYPE;
563564
readonly loc?: Location;
564565
readonly name: NameNode;
565566
}
566567

567568
export interface ListTypeNode {
568-
readonly kind: 'ListType';
569+
readonly kind: typeof Kind.LIST_TYPE;
569570
readonly loc?: Location;
570571
readonly type: TypeNode;
571572
}
572573

573574
export interface NonNullTypeNode {
574-
readonly kind: 'NonNullType';
575+
readonly kind: typeof Kind.NON_NULL_TYPE;
575576
readonly loc?: Location;
576577
readonly type: NamedTypeNode | ListTypeNode;
577578
}
@@ -584,15 +585,15 @@ export type TypeSystemDefinitionNode =
584585
| DirectiveDefinitionNode;
585586

586587
export interface SchemaDefinitionNode {
587-
readonly kind: 'SchemaDefinition';
588+
readonly kind: typeof Kind.SCHEMA_DEFINITION;
588589
readonly loc?: Location;
589590
readonly description?: StringValueNode;
590591
readonly directives?: ReadonlyArray<ConstDirectiveNode>;
591592
readonly operationTypes: ReadonlyArray<OperationTypeDefinitionNode>;
592593
}
593594

594595
export interface OperationTypeDefinitionNode {
595-
readonly kind: 'OperationTypeDefinition';
596+
readonly kind: typeof Kind.OPERATION_TYPE_DEFINITION;
596597
readonly loc?: Location;
597598
readonly operation: OperationTypeNode;
598599
readonly type: NamedTypeNode;
@@ -609,15 +610,15 @@ export type TypeDefinitionNode =
609610
| InputObjectTypeDefinitionNode;
610611

611612
export interface ScalarTypeDefinitionNode {
612-
readonly kind: 'ScalarTypeDefinition';
613+
readonly kind: typeof Kind.SCALAR_TYPE_DEFINITION;
613614
readonly loc?: Location;
614615
readonly description?: StringValueNode;
615616
readonly name: NameNode;
616617
readonly directives?: ReadonlyArray<ConstDirectiveNode>;
617618
}
618619

619620
export interface ObjectTypeDefinitionNode {
620-
readonly kind: 'ObjectTypeDefinition';
621+
readonly kind: typeof Kind.OBJECT_TYPE_DEFINITION;
621622
readonly loc?: Location;
622623
readonly description?: StringValueNode;
623624
readonly name: NameNode;
@@ -627,7 +628,7 @@ export interface ObjectTypeDefinitionNode {
627628
}
628629

629630
export interface FieldDefinitionNode {
630-
readonly kind: 'FieldDefinition';
631+
readonly kind: typeof Kind.FIELD_DEFINITION;
631632
readonly loc?: Location;
632633
readonly description?: StringValueNode;
633634
readonly name: NameNode;
@@ -637,7 +638,7 @@ export interface FieldDefinitionNode {
637638
}
638639

639640
export interface InputValueDefinitionNode {
640-
readonly kind: 'InputValueDefinition';
641+
readonly kind: typeof Kind.INPUT_VALUE_DEFINITION;
641642
readonly loc?: Location;
642643
readonly description?: StringValueNode;
643644
readonly name: NameNode;
@@ -647,7 +648,7 @@ export interface InputValueDefinitionNode {
647648
}
648649

649650
export interface InterfaceTypeDefinitionNode {
650-
readonly kind: 'InterfaceTypeDefinition';
651+
readonly kind: typeof Kind.INTERFACE_TYPE_DEFINITION;
651652
readonly loc?: Location;
652653
readonly description?: StringValueNode;
653654
readonly name: NameNode;
@@ -657,7 +658,7 @@ export interface InterfaceTypeDefinitionNode {
657658
}
658659

659660
export interface UnionTypeDefinitionNode {
660-
readonly kind: 'UnionTypeDefinition';
661+
readonly kind: typeof Kind.UNION_TYPE_DEFINITION;
661662
readonly loc?: Location;
662663
readonly description?: StringValueNode;
663664
readonly name: NameNode;
@@ -666,7 +667,7 @@ export interface UnionTypeDefinitionNode {
666667
}
667668

668669
export interface EnumTypeDefinitionNode {
669-
readonly kind: 'EnumTypeDefinition';
670+
readonly kind: typeof Kind.ENUM_TYPE_DEFINITION;
670671
readonly loc?: Location;
671672
readonly description?: StringValueNode;
672673
readonly name: NameNode;
@@ -675,15 +676,15 @@ export interface EnumTypeDefinitionNode {
675676
}
676677

677678
export interface EnumValueDefinitionNode {
678-
readonly kind: 'EnumValueDefinition';
679+
readonly kind: typeof Kind.ENUM_VALUE_DEFINITION;
679680
readonly loc?: Location;
680681
readonly description?: StringValueNode;
681682
readonly name: NameNode;
682683
readonly directives?: ReadonlyArray<ConstDirectiveNode>;
683684
}
684685

685686
export interface InputObjectTypeDefinitionNode {
686-
readonly kind: 'InputObjectTypeDefinition';
687+
readonly kind: typeof Kind.INPUT_OBJECT_TYPE_DEFINITION;
687688
readonly loc?: Location;
688689
readonly description?: StringValueNode;
689690
readonly name: NameNode;
@@ -694,7 +695,7 @@ export interface InputObjectTypeDefinitionNode {
694695
/** Directive Definitions */
695696

696697
export interface DirectiveDefinitionNode {
697-
readonly kind: 'DirectiveDefinition';
698+
readonly kind: typeof Kind.DIRECTIVE_DEFINITION;
698699
readonly loc?: Location;
699700
readonly description?: StringValueNode;
700701
readonly name: NameNode;
@@ -708,7 +709,7 @@ export interface DirectiveDefinitionNode {
708709
export type TypeSystemExtensionNode = SchemaExtensionNode | TypeExtensionNode;
709710

710711
export interface SchemaExtensionNode {
711-
readonly kind: 'SchemaExtension';
712+
readonly kind: typeof Kind.SCHEMA_EXTENSION;
712713
readonly loc?: Location;
713714
readonly directives?: ReadonlyArray<ConstDirectiveNode>;
714715
readonly operationTypes?: ReadonlyArray<OperationTypeDefinitionNode>;
@@ -725,14 +726,14 @@ export type TypeExtensionNode =
725726
| InputObjectTypeExtensionNode;
726727

727728
export interface ScalarTypeExtensionNode {
728-
readonly kind: 'ScalarTypeExtension';
729+
readonly kind: typeof Kind.SCALAR_TYPE_EXTENSION;
729730
readonly loc?: Location;
730731
readonly name: NameNode;
731732
readonly directives?: ReadonlyArray<ConstDirectiveNode>;
732733
}
733734

734735
export interface ObjectTypeExtensionNode {
735-
readonly kind: 'ObjectTypeExtension';
736+
readonly kind: typeof Kind.OBJECT_TYPE_EXTENSION;
736737
readonly loc?: Location;
737738
readonly name: NameNode;
738739
readonly interfaces?: ReadonlyArray<NamedTypeNode>;
@@ -741,7 +742,7 @@ export interface ObjectTypeExtensionNode {
741742
}
742743

743744
export interface InterfaceTypeExtensionNode {
744-
readonly kind: 'InterfaceTypeExtension';
745+
readonly kind: typeof Kind.INTERFACE_TYPE_EXTENSION;
745746
readonly loc?: Location;
746747
readonly name: NameNode;
747748
readonly interfaces?: ReadonlyArray<NamedTypeNode>;
@@ -750,23 +751,23 @@ export interface InterfaceTypeExtensionNode {
750751
}
751752

752753
export interface UnionTypeExtensionNode {
753-
readonly kind: 'UnionTypeExtension';
754+
readonly kind: typeof Kind.UNION_TYPE_EXTENSION;
754755
readonly loc?: Location;
755756
readonly name: NameNode;
756757
readonly directives?: ReadonlyArray<ConstDirectiveNode>;
757758
readonly types?: ReadonlyArray<NamedTypeNode>;
758759
}
759760

760761
export interface EnumTypeExtensionNode {
761-
readonly kind: 'EnumTypeExtension';
762+
readonly kind: typeof Kind.ENUM_TYPE_EXTENSION;
762763
readonly loc?: Location;
763764
readonly name: NameNode;
764765
readonly directives?: ReadonlyArray<ConstDirectiveNode>;
765766
readonly values?: ReadonlyArray<EnumValueDefinitionNode>;
766767
}
767768

768769
export interface InputObjectTypeExtensionNode {
769-
readonly kind: 'InputObjectTypeExtension';
770+
readonly kind: typeof Kind.INPUT_OBJECT_TYPE_EXTENSION;
770771
readonly loc?: Location;
771772
readonly name: NameNode;
772773
readonly directives?: ReadonlyArray<ConstDirectiveNode>;

0 commit comments

Comments
 (0)