Skip to content

Commit

Permalink
Allow for tree-shaking the Kind enum
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Oct 29, 2024
1 parent 9153497 commit be5ebb9
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 68 deletions.
65 changes: 65 additions & 0 deletions src/language/_kinds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/** Name */
export const NAME = 'Name' as const;

Check failure on line 2 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression

Check failure on line 2 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression

/** Document */
export const DOCUMENT = 'Document' as const;

Check failure on line 5 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression

Check failure on line 5 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression
export const OPERATION_DEFINITION = 'OperationDefinition' as const;

Check failure on line 6 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression

Check failure on line 6 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression
export const VARIABLE_DEFINITION = 'VariableDefinition' as const;

Check failure on line 7 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression

Check failure on line 7 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression
export const SELECTION_SET = 'SelectionSet' as const;

Check failure on line 8 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression

Check failure on line 8 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression
export const FIELD = 'Field' as const;

Check failure on line 9 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression

Check failure on line 9 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression
export const ARGUMENT = 'Argument' as const;

Check failure on line 10 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression

Check failure on line 10 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression
export const FRAGMENT_ARGUMENT = 'FragmentArgument' as const;

Check failure on line 11 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression

Check failure on line 11 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression

/** Fragments */
export const FRAGMENT_SPREAD = 'FragmentSpread' as const;

Check failure on line 14 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression

Check failure on line 14 in src/language/_kinds.ts

View workflow job for this annotation

GitHub Actions / ci / Lint source files

This assertion is unnecessary since it does not change the type of the expression
export const INLINE_FRAGMENT = 'InlineFragment' as const;
export const FRAGMENT_DEFINITION = 'FragmentDefinition' as const;

/** Values */
export const VARIABLE = 'Variable' as const;
export const INT = 'IntValue' as const;
export const FLOAT = 'FloatValue' as const;
export const STRING = 'StringValue' as const;
export const BOOLEAN = 'BooleanValue' as const;
export const NULL = 'NullValue' as const;
export const ENUM = 'EnumValue' as const;
export const LIST = 'ListValue' as const;
export const OBJECT = 'ObjectValue' as const;
export const OBJECT_FIELD = 'ObjectField' as const;

/** Directives */
export const DIRECTIVE = 'Directive' as const;

/** Types */
export const NAMED_TYPE = 'NamedType' as const;
export const LIST_TYPE = 'ListType' as const;
export const NON_NULL_TYPE = 'NonNullType' as const;

/** Type System Definitions */
export const SCHEMA_DEFINITION = 'SchemaDefinition' as const;
export const OPERATION_TYPE_DEFINITION = 'OperationTypeDefinition' as const;

/** Type Definitions */
export const SCALAR_TYPE_DEFINITION = 'ScalarTypeDefinition' as const;
export const OBJECT_TYPE_DEFINITION = 'ObjectTypeDefinition' as const;
export const FIELD_DEFINITION = 'FieldDefinition' as const;
export const INPUT_VALUE_DEFINITION = 'InputValueDefinition' as const;
export const INTERFACE_TYPE_DEFINITION = 'InterfaceTypeDefinition' as const;
export const UNION_TYPE_DEFINITION = 'UnionTypeDefinition' as const;
export const ENUM_TYPE_DEFINITION = 'EnumTypeDefinition' as const;
export const ENUM_VALUE_DEFINITION = 'EnumValueDefinition' as const;
export const INPUT_OBJECT_TYPE_DEFINITION = 'InputObjectTypeDefinition' as const;

/** Directive Definitions */
export const DIRECTIVE_DEFINITION = 'DirectiveDefinition' as const;

/** Type System Extensions */
export const SCHEMA_EXTENSION = 'SchemaExtension' as const;

/** Type Extensions */
export const SCALAR_TYPE_EXTENSION = 'ScalarTypeExtension' as const;
export const OBJECT_TYPE_EXTENSION = 'ObjectTypeExtension' as const;
export const INTERFACE_TYPE_EXTENSION = 'InterfaceTypeExtension' as const;
export const UNION_TYPE_EXTENSION = 'UnionTypeExtension' as const;
export const ENUM_TYPE_EXTENSION = 'EnumTypeExtension' as const;
export const INPUT_OBJECT_TYPE_EXTENSION = 'InputObjectTypeExtension' as const;
161 changes: 93 additions & 68 deletions src/language/kinds.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,97 @@
import type {
ARGUMENT,
BOOLEAN,
DIRECTIVE,
DIRECTIVE_DEFINITION,
DOCUMENT,
ENUM,
ENUM_TYPE_DEFINITION,
ENUM_TYPE_EXTENSION,
ENUM_VALUE_DEFINITION,
FIELD,
FIELD_DEFINITION,
FLOAT,
FRAGMENT_ARGUMENT,
FRAGMENT_DEFINITION,
FRAGMENT_SPREAD,
INLINE_FRAGMENT,
INPUT_OBJECT_TYPE_DEFINITION,
INPUT_OBJECT_TYPE_EXTENSION,
INPUT_VALUE_DEFINITION,
INT,
INTERFACE_TYPE_DEFINITION,
INTERFACE_TYPE_EXTENSION,
LIST,
LIST_TYPE,
NAME,
NAMED_TYPE,
NON_NULL_TYPE,
NULL,
OBJECT,
OBJECT_FIELD,
OBJECT_TYPE_DEFINITION,
OBJECT_TYPE_EXTENSION,
OPERATION_DEFINITION,
OPERATION_TYPE_DEFINITION,
SCALAR_TYPE_DEFINITION,
SCALAR_TYPE_EXTENSION,
SCHEMA_DEFINITION,
SCHEMA_EXTENSION,
SELECTION_SET,
STRING,
UNION_TYPE_DEFINITION,
UNION_TYPE_EXTENSION,
VARIABLE,
VARIABLE_DEFINITION,
} from './_kinds.js';

/**
* The set of allowed kind values for AST nodes.
*/
export const Kind = {
/** Name */
NAME: 'Name' as const,

/** Document */
DOCUMENT: 'Document' as const,
OPERATION_DEFINITION: 'OperationDefinition' as const,
VARIABLE_DEFINITION: 'VariableDefinition' as const,
SELECTION_SET: 'SelectionSet' as const,
FIELD: 'Field' as const,
ARGUMENT: 'Argument' as const,
FRAGMENT_ARGUMENT: 'FragmentArgument' as const,

/** Fragments */
FRAGMENT_SPREAD: 'FragmentSpread' as const,
INLINE_FRAGMENT: 'InlineFragment' as const,
FRAGMENT_DEFINITION: 'FragmentDefinition' as const,

/** Values */
VARIABLE: 'Variable' as const,
INT: 'IntValue' as const,
FLOAT: 'FloatValue' as const,
STRING: 'StringValue' as const,
BOOLEAN: 'BooleanValue' as const,
NULL: 'NullValue' as const,
ENUM: 'EnumValue' as const,
LIST: 'ListValue' as const,
OBJECT: 'ObjectValue' as const,
OBJECT_FIELD: 'ObjectField' as const,

/** Directives */
DIRECTIVE: 'Directive' as const,

/** Types */
NAMED_TYPE: 'NamedType' as const,
LIST_TYPE: 'ListType' as const,
NON_NULL_TYPE: 'NonNullType' as const,

/** Type System Definitions */
SCHEMA_DEFINITION: 'SchemaDefinition' as const,
OPERATION_TYPE_DEFINITION: 'OperationTypeDefinition' as const,

/** Type Definitions */
SCALAR_TYPE_DEFINITION: 'ScalarTypeDefinition' as const,
OBJECT_TYPE_DEFINITION: 'ObjectTypeDefinition' as const,
FIELD_DEFINITION: 'FieldDefinition' as const,
INPUT_VALUE_DEFINITION: 'InputValueDefinition' as const,
INTERFACE_TYPE_DEFINITION: 'InterfaceTypeDefinition' as const,
UNION_TYPE_DEFINITION: 'UnionTypeDefinition' as const,
ENUM_TYPE_DEFINITION: 'EnumTypeDefinition' as const,
ENUM_VALUE_DEFINITION: 'EnumValueDefinition' as const,
INPUT_OBJECT_TYPE_DEFINITION: 'InputObjectTypeDefinition' as const,

/** Directive Definitions */
DIRECTIVE_DEFINITION: 'DirectiveDefinition' as const,

/** Type System Extensions */
SCHEMA_EXTENSION: 'SchemaExtension' as const,
export * as Kind from './_kinds.js';

/** Type Extensions */
SCALAR_TYPE_EXTENSION: 'ScalarTypeExtension' as const,
OBJECT_TYPE_EXTENSION: 'ObjectTypeExtension' as const,
INTERFACE_TYPE_EXTENSION: 'InterfaceTypeExtension' as const,
UNION_TYPE_EXTENSION: 'UnionTypeExtension' as const,
ENUM_TYPE_EXTENSION: 'EnumTypeExtension' as const,
INPUT_OBJECT_TYPE_EXTENSION: 'InputObjectTypeExtension' as const,
};
// eslint-disable-next-line @typescript-eslint/no-redeclare
export type Kind = (typeof Kind)[keyof typeof Kind];
export type Kind =
| typeof NAME
| typeof DOCUMENT
| typeof OPERATION_DEFINITION
| typeof VARIABLE_DEFINITION
| typeof SELECTION_SET
| typeof FIELD
| typeof ARGUMENT
| typeof FRAGMENT_ARGUMENT
| typeof FRAGMENT_SPREAD
| typeof INLINE_FRAGMENT
| typeof FRAGMENT_DEFINITION
| typeof VARIABLE
| typeof INT
| typeof FLOAT
| typeof STRING
| typeof BOOLEAN
| typeof NULL
| typeof ENUM
| typeof LIST
| typeof OBJECT
| typeof OBJECT_FIELD
| typeof DIRECTIVE
| typeof NAMED_TYPE
| typeof LIST_TYPE
| typeof NON_NULL_TYPE
| typeof SCHEMA_DEFINITION
| typeof OPERATION_TYPE_DEFINITION
| typeof SCALAR_TYPE_DEFINITION
| typeof OBJECT_TYPE_DEFINITION
| typeof FIELD_DEFINITION
| typeof INPUT_VALUE_DEFINITION
| typeof INTERFACE_TYPE_DEFINITION
| typeof UNION_TYPE_DEFINITION
| typeof ENUM_TYPE_DEFINITION
| typeof ENUM_VALUE_DEFINITION
| typeof INPUT_OBJECT_TYPE_DEFINITION
| typeof DIRECTIVE_DEFINITION
| typeof SCHEMA_EXTENSION
| typeof SCALAR_TYPE_EXTENSION
| typeof OBJECT_TYPE_EXTENSION
| typeof INTERFACE_TYPE_EXTENSION
| typeof UNION_TYPE_EXTENSION
| typeof ENUM_TYPE_EXTENSION
| typeof INPUT_OBJECT_TYPE_EXTENSION;

0 comments on commit be5ebb9

Please sign in to comment.