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 Jun 30, 2021
1 parent 4493ca3 commit 796211c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 44 deletions.
87 changes: 44 additions & 43 deletions src/language/ast.ts
@@ -1,5 +1,6 @@
import type { Source } from './source';
import type { TokenKindEnum } from './tokenKind';
import type { Kind } from './kinds';

/**
* Contains a range of UTF-8 character offsets and token references that
Expand Down Expand Up @@ -238,15 +239,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 @@ -261,7 +262,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 @@ -273,7 +274,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 @@ -282,21 +283,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 @@ -306,7 +307,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 @@ -322,22 +323,22 @@ export interface ConstArgumentNode {
/** 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;
/** @deprecated variableDefinitions will be removed in v17.0.0 */
Expand Down Expand Up @@ -371,43 +372,43 @@ export type ConstValueNode =
| ConstObjectValueNode;

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>;
}
Expand All @@ -419,7 +420,7 @@ export interface ConstListValueNode {
}

export interface ObjectValueNode {
readonly kind: 'ObjectValue';
readonly kind: typeof Kind.OBJECT;
readonly loc?: Location;
readonly fields: ReadonlyArray<ObjectFieldNode>;
}
Expand All @@ -431,7 +432,7 @@ export interface ConstObjectValueNode {
}

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

export interface DirectiveNode {
readonly kind: 'Directive';
readonly kind: typeof Kind.DIRECTIVE;
readonly loc?: Location;
readonly name: NameNode;
readonly arguments?: ReadonlyArray<ArgumentNode>;
Expand All @@ -465,19 +466,19 @@ export interface ConstDirectiveNode {
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 @@ -490,15 +491,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<ConstDirectiveNode>;
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 @@ -515,15 +516,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<ConstDirectiveNode>;
}

export interface ObjectTypeDefinitionNode {
readonly kind: 'ObjectTypeDefinition';
readonly kind: typeof Kind.OBJECT_TYPE_DEFINITION;
readonly loc?: Location;
readonly description?: StringValueNode;
readonly name: NameNode;
Expand All @@ -533,7 +534,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 @@ -543,7 +544,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 @@ -553,7 +554,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 @@ -563,7 +564,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 @@ -572,7 +573,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 @@ -581,15 +582,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<ConstDirectiveNode>;
}

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 @@ -600,7 +601,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 @@ -614,7 +615,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<ConstDirectiveNode>;
readonly operationTypes?: ReadonlyArray<OperationTypeDefinitionNode>;
Expand All @@ -631,14 +632,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<ConstDirectiveNode>;
}

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 @@ -647,7 +648,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 @@ -656,23 +657,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<ConstDirectiveNode>;
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<ConstDirectiveNode>;
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<ConstDirectiveNode>;
Expand Down
2 changes: 1 addition & 1 deletion src/language/kinds.ts
Expand Up @@ -71,4 +71,4 @@ export const Kind = Object.freeze({
/**
* The enum type representing the possible kind values of AST nodes.
*/
export type KindEnum = typeof Kind[keyof typeof Kind];
export type KindEnum = typeof Kind[keyof typeof Kind];

0 comments on commit 796211c

Please sign in to comment.