From be5ebb9b843ac2b51eed77e70ef22a9fe45db6ad Mon Sep 17 00:00:00 2001 From: jdecroock Date: Tue, 29 Oct 2024 12:30:12 +0100 Subject: [PATCH] Allow for tree-shaking the Kind enum --- src/language/_kinds.ts | 65 +++++++++++++++++ src/language/kinds.ts | 161 ++++++++++++++++++++++++----------------- 2 files changed, 158 insertions(+), 68 deletions(-) create mode 100644 src/language/_kinds.ts diff --git a/src/language/_kinds.ts b/src/language/_kinds.ts new file mode 100644 index 0000000000..c4e860a628 --- /dev/null +++ b/src/language/_kinds.ts @@ -0,0 +1,65 @@ +/** Name */ +export const NAME = 'Name' as const; + +/** Document */ +export const DOCUMENT = 'Document' as const; +export const OPERATION_DEFINITION = 'OperationDefinition' as const; +export const VARIABLE_DEFINITION = 'VariableDefinition' as const; +export const SELECTION_SET = 'SelectionSet' as const; +export const FIELD = 'Field' as const; +export const ARGUMENT = 'Argument' as const; +export const FRAGMENT_ARGUMENT = 'FragmentArgument' as const; + +/** Fragments */ +export const FRAGMENT_SPREAD = 'FragmentSpread' as const; +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; diff --git a/src/language/kinds.ts b/src/language/kinds.ts index d41eccecfc..715ff70085 100644 --- a/src/language/kinds.ts +++ b/src/language/kinds.ts @@ -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;