Skip to content

Commit

Permalink
refactor(language/ast.d.ts): use Kind enum type
Browse files Browse the repository at this point in the history
  • Loading branch information
jjangga0214 committed Mar 24, 2021
1 parent 32a053b commit 10a8570
Showing 1 changed file with 44 additions and 43 deletions.
87 changes: 44 additions & 43 deletions src/language/ast.d.ts
@@ -1,5 +1,6 @@
import { Source } from './source';
import { TokenKindEnum } from './tokenKind';
import { Kind } from './kinds';

/**
* Contains a range of UTF-8 character offsets and token references that
Expand Down Expand Up @@ -202,15 +203,15 @@ export interface ASTKindToNode {
// Name

export interface NameNode {
readonly kind: 'Name';
readonly kind: typeof Kind.NAME;
readonly loc?: Location;
readonly value: string;
}

// Document

export interface DocumentNode {
readonly kind: 'Document';
readonly kind: typeof Kind.DOCUMENT;
readonly loc?: Location;
readonly definitions: ReadonlyArray<DefinitionNode>;
}
Expand All @@ -225,7 +226,7 @@ export type ExecutableDefinitionNode =
| FragmentDefinitionNode;

export interface OperationDefinitionNode {
readonly kind: 'OperationDefinition';
readonly kind: typeof Kind.OPERATION_DEFINITION;
readonly loc?: Location;
readonly operation: OperationTypeNode;
readonly name?: NameNode;
Expand All @@ -237,7 +238,7 @@ export interface OperationDefinitionNode {
export type OperationTypeNode = 'query' | 'mutation' | 'subscription';

export interface VariableDefinitionNode {
readonly kind: 'VariableDefinition';
readonly kind: typeof Kind.VARIABLE_DEFINITION;
readonly loc?: Location;
readonly variable: VariableNode;
readonly type: TypeNode;
Expand All @@ -246,21 +247,21 @@ export interface VariableDefinitionNode {
}

export interface VariableNode {
readonly kind: 'Variable';
readonly kind: typeof Kind.VARIABLE;
readonly loc?: Location;
readonly name: NameNode;
}

export interface SelectionSetNode {
kind: 'SelectionSet';
kind: typeof Kind.SELECTION_SET;
loc?: Location;
selections: ReadonlyArray<SelectionNode>;
}

export type SelectionNode = FieldNode | FragmentSpreadNode | InlineFragmentNode;

export interface FieldNode {
readonly kind: 'Field';
readonly kind: typeof Kind.FIELD;
readonly loc?: Location;
readonly alias?: NameNode;
readonly name: NameNode;
Expand All @@ -270,7 +271,7 @@ export interface FieldNode {
}

export interface ArgumentNode {
readonly kind: 'Argument';
readonly kind: typeof Kind.ARGUMENT;
readonly loc?: Location;
readonly name: NameNode;
readonly value: ValueNode;
Expand All @@ -279,22 +280,22 @@ export interface ArgumentNode {
// Fragments

export interface FragmentSpreadNode {
readonly kind: 'FragmentSpread';
readonly kind: typeof Kind.FRAGMENT_SPREAD;
readonly loc?: Location;
readonly name: NameNode;
readonly directives?: ReadonlyArray<DirectiveNode>;
}

export interface InlineFragmentNode {
readonly kind: 'InlineFragment';
readonly kind: typeof Kind.INLINE_FRAGMENT;
readonly loc?: Location;
readonly typeCondition?: NamedTypeNode;
readonly directives?: ReadonlyArray<DirectiveNode>;
readonly selectionSet: SelectionSetNode;
}

export interface FragmentDefinitionNode {
readonly kind: 'FragmentDefinition';
readonly kind: typeof Kind.FRAGMENT_DEFINITION;
readonly loc?: Location;
readonly name: NameNode;
// Note: fragment variable definitions are deprecated and will removed in v17.0.0
Expand All @@ -318,55 +319,55 @@ export type ValueNode =
| ObjectValueNode;

export interface IntValueNode {
readonly kind: 'IntValue';
readonly kind: typeof Kind.INT;
readonly loc?: Location;
readonly value: string;
}

export interface FloatValueNode {
readonly kind: 'FloatValue';
readonly kind: typeof Kind.FLOAT;
readonly loc?: Location;
readonly value: string;
}

export interface StringValueNode {
readonly kind: 'StringValue';
readonly kind: typeof Kind.STRING;
readonly loc?: Location;
readonly value: string;
readonly block?: boolean;
}

export interface BooleanValueNode {
readonly kind: 'BooleanValue';
readonly kind: typeof Kind.BOOLEAN;
readonly loc?: Location;
readonly value: boolean;
}

export interface NullValueNode {
readonly kind: 'NullValue';
readonly kind: typeof Kind.NULL;
readonly loc?: Location;
}

export interface EnumValueNode {
readonly kind: 'EnumValue';
readonly kind: typeof Kind.ENUM;
readonly loc?: Location;
readonly value: string;
}

export interface ListValueNode {
readonly kind: 'ListValue';
readonly kind: typeof Kind.LIST;
readonly loc?: Location;
readonly values: ReadonlyArray<ValueNode>;
}

export interface ObjectValueNode {
readonly kind: 'ObjectValue';
readonly kind: typeof Kind.OBJECT;
readonly loc?: Location;
readonly fields: ReadonlyArray<ObjectFieldNode>;
}

export interface ObjectFieldNode {
readonly kind: 'ObjectField';
readonly kind: typeof Kind.OBJECT_FIELD;
readonly loc?: Location;
readonly name: NameNode;
readonly value: ValueNode;
Expand All @@ -375,7 +376,7 @@ export interface ObjectFieldNode {
// Directives

export interface DirectiveNode {
readonly kind: 'Directive';
readonly kind: typeof Kind.DIRECTIVE;
readonly loc?: Location;
readonly name: NameNode;
readonly arguments?: ReadonlyArray<ArgumentNode>;
Expand All @@ -386,19 +387,19 @@ export interface DirectiveNode {
export type TypeNode = NamedTypeNode | ListTypeNode | NonNullTypeNode;

export interface NamedTypeNode {
readonly kind: 'NamedType';
readonly kind: typeof Kind.NAMED_TYPE;
readonly loc?: Location;
readonly name: NameNode;
}

export interface ListTypeNode {
readonly kind: 'ListType';
readonly kind: typeof Kind.LIST_TYPE;
readonly loc?: Location;
readonly type: TypeNode;
}

export interface NonNullTypeNode {
readonly kind: 'NonNullType';
readonly kind: typeof Kind.NON_NULL_TYPE;
readonly loc?: Location;
readonly type: NamedTypeNode | ListTypeNode;
}
Expand All @@ -411,15 +412,15 @@ export type TypeSystemDefinitionNode =
| DirectiveDefinitionNode;

export interface SchemaDefinitionNode {
readonly kind: 'SchemaDefinition';
readonly kind: typeof Kind.SCHEMA_DEFINITION;
readonly loc?: Location;
readonly description?: StringValueNode;
readonly directives?: ReadonlyArray<DirectiveNode>;
readonly operationTypes: ReadonlyArray<OperationTypeDefinitionNode>;
}

export interface OperationTypeDefinitionNode {
readonly kind: 'OperationTypeDefinition';
readonly kind: typeof Kind.OPERATION_TYPE_DEFINITION;
readonly loc?: Location;
readonly operation: OperationTypeNode;
readonly type: NamedTypeNode;
Expand All @@ -436,15 +437,15 @@ export type TypeDefinitionNode =
| InputObjectTypeDefinitionNode;

export interface ScalarTypeDefinitionNode {
readonly kind: 'ScalarTypeDefinition';
readonly kind: typeof Kind.SCALAR_TYPE_DEFINITION;
readonly loc?: Location;
readonly description?: StringValueNode;
readonly name: NameNode;
readonly directives?: ReadonlyArray<DirectiveNode>;
}

export interface ObjectTypeDefinitionNode {
readonly kind: 'ObjectTypeDefinition';
readonly kind: typeof Kind.OBJECT_TYPE_DEFINITION;
readonly loc?: Location;
readonly description?: StringValueNode;
readonly name: NameNode;
Expand All @@ -454,7 +455,7 @@ export interface ObjectTypeDefinitionNode {
}

export interface FieldDefinitionNode {
readonly kind: 'FieldDefinition';
readonly kind: typeof Kind.FIELD_DEFINITION;
readonly loc?: Location;
readonly description?: StringValueNode;
readonly name: NameNode;
Expand All @@ -464,7 +465,7 @@ export interface FieldDefinitionNode {
}

export interface InputValueDefinitionNode {
readonly kind: 'InputValueDefinition';
readonly kind: typeof Kind.INPUT_VALUE_DEFINITION;
readonly loc?: Location;
readonly description?: StringValueNode;
readonly name: NameNode;
Expand All @@ -474,7 +475,7 @@ export interface InputValueDefinitionNode {
}

export interface InterfaceTypeDefinitionNode {
readonly kind: 'InterfaceTypeDefinition';
readonly kind: typeof Kind.INTERFACE_TYPE_DEFINITION;
readonly loc?: Location;
readonly description?: StringValueNode;
readonly name: NameNode;
Expand All @@ -484,7 +485,7 @@ export interface InterfaceTypeDefinitionNode {
}

export interface UnionTypeDefinitionNode {
readonly kind: 'UnionTypeDefinition';
readonly kind: typeof Kind.UNION_TYPE_DEFINITION;
readonly loc?: Location;
readonly description?: StringValueNode;
readonly name: NameNode;
Expand All @@ -493,7 +494,7 @@ export interface UnionTypeDefinitionNode {
}

export interface EnumTypeDefinitionNode {
readonly kind: 'EnumTypeDefinition';
readonly kind: typeof Kind.ENUM_TYPE_DEFINITION;
readonly loc?: Location;
readonly description?: StringValueNode;
readonly name: NameNode;
Expand All @@ -502,15 +503,15 @@ export interface EnumTypeDefinitionNode {
}

export interface EnumValueDefinitionNode {
readonly kind: 'EnumValueDefinition';
readonly kind: typeof Kind.ENUM_VALUE_DEFINITION;
readonly loc?: Location;
readonly description?: StringValueNode;
readonly name: NameNode;
readonly directives?: ReadonlyArray<DirectiveNode>;
}

export interface InputObjectTypeDefinitionNode {
readonly kind: 'InputObjectTypeDefinition';
readonly kind: typeof Kind.INPUT_OBJECT_TYPE_DEFINITION;
readonly loc?: Location;
readonly description?: StringValueNode;
readonly name: NameNode;
Expand All @@ -521,7 +522,7 @@ export interface InputObjectTypeDefinitionNode {
// Directive Definitions

export interface DirectiveDefinitionNode {
readonly kind: 'DirectiveDefinition';
readonly kind: typeof Kind.DIRECTIVE_DEFINITION;
readonly loc?: Location;
readonly description?: StringValueNode;
readonly name: NameNode;
Expand All @@ -535,7 +536,7 @@ export interface DirectiveDefinitionNode {
export type TypeSystemExtensionNode = SchemaExtensionNode | TypeExtensionNode;

export interface SchemaExtensionNode {
readonly kind: 'SchemaExtension';
readonly kind: typeof Kind.SCHEMA_EXTENSION;
readonly loc?: Location;
readonly directives?: ReadonlyArray<DirectiveNode>;
readonly operationTypes?: ReadonlyArray<OperationTypeDefinitionNode>;
Expand All @@ -552,14 +553,14 @@ export type TypeExtensionNode =
| InputObjectTypeExtensionNode;

export interface ScalarTypeExtensionNode {
readonly kind: 'ScalarTypeExtension';
readonly kind: typeof Kind.SCALAR_TYPE_EXTENSION;
readonly loc?: Location;
readonly name: NameNode;
readonly directives?: ReadonlyArray<DirectiveNode>;
}

export interface ObjectTypeExtensionNode {
readonly kind: 'ObjectTypeExtension';
readonly kind: typeof Kind.OBJECT_TYPE_DEFINITION;
readonly loc?: Location;
readonly name: NameNode;
readonly interfaces?: ReadonlyArray<NamedTypeNode>;
Expand All @@ -568,7 +569,7 @@ export interface ObjectTypeExtensionNode {
}

export interface InterfaceTypeExtensionNode {
readonly kind: 'InterfaceTypeExtension';
readonly kind: typeof Kind.INTERFACE_TYPE_DEFINITION;
readonly loc?: Location;
readonly name: NameNode;
readonly interfaces?: ReadonlyArray<NamedTypeNode>;
Expand All @@ -577,23 +578,23 @@ export interface InterfaceTypeExtensionNode {
}

export interface UnionTypeExtensionNode {
readonly kind: 'UnionTypeExtension';
readonly kind: typeof Kind.UNION_TYPE_DEFINITION;
readonly loc?: Location;
readonly name: NameNode;
readonly directives?: ReadonlyArray<DirectiveNode>;
readonly types?: ReadonlyArray<NamedTypeNode>;
}

export interface EnumTypeExtensionNode {
readonly kind: 'EnumTypeExtension';
readonly kind: typeof Kind.ENUM_TYPE_DEFINITION;
readonly loc?: Location;
readonly name: NameNode;
readonly directives?: ReadonlyArray<DirectiveNode>;
readonly values?: ReadonlyArray<EnumValueDefinitionNode>;
}

export interface InputObjectTypeExtensionNode {
readonly kind: 'InputObjectTypeExtension';
readonly kind: typeof Kind.INPUT_OBJECT_TYPE_DEFINITION;
readonly loc?: Location;
readonly name: NameNode;
readonly directives?: ReadonlyArray<DirectiveNode>;
Expand Down

0 comments on commit 10a8570

Please sign in to comment.