From 915349728541cf2919e07811d33bc1426d4c9e78 Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Fri, 25 Oct 2024 07:04:01 +0200 Subject: [PATCH] Get rid of enums in favor off plain JS usage --- src/language/ast.ts | 112 +++++++++++++------------ src/language/directiveLocation.ts | 49 +++++------ src/language/kinds.ts | 96 ++++++++++----------- src/language/tokenKind.ts | 52 ++++++------ src/type/introspection.ts | 24 +++--- src/utilities/findSchemaChanges.ts | 94 +++++++++++---------- src/utilities/getIntrospectionQuery.ts | 16 ++-- 7 files changed, 227 insertions(+), 216 deletions(-) diff --git a/src/language/ast.ts b/src/language/ast.ts index e7ea84fd79..73f702bbd4 100644 --- a/src/language/ast.ts +++ b/src/language/ast.ts @@ -301,7 +301,7 @@ export function isNode(maybeNode: any): maybeNode is ASTNode { /** Name */ export interface NameNode { - readonly kind: Kind.NAME; + readonly kind: typeof Kind.NAME; readonly loc?: Location | undefined; readonly value: string; } @@ -309,7 +309,7 @@ export interface NameNode { /** Document */ export interface DocumentNode { - readonly kind: Kind.DOCUMENT; + readonly kind: typeof Kind.DOCUMENT; readonly loc?: Location | undefined; readonly definitions: ReadonlyArray; } @@ -324,7 +324,7 @@ export type ExecutableDefinitionNode = | FragmentDefinitionNode; export interface OperationDefinitionNode { - readonly kind: Kind.OPERATION_DEFINITION; + readonly kind: typeof Kind.OPERATION_DEFINITION; readonly loc?: Location | undefined; readonly operation: OperationTypeNode; readonly name?: NameNode | undefined; @@ -335,15 +335,17 @@ export interface OperationDefinitionNode { readonly selectionSet: SelectionSetNode; } -enum OperationTypeNode { - QUERY = 'query', - MUTATION = 'mutation', - SUBSCRIPTION = 'subscription', -} -export { OperationTypeNode }; +export const OperationTypeNode = { + QUERY: 'query' as const, + MUTATION: 'mutation' as const, + SUBSCRIPTION: 'subscription' as const, +} as const; +// eslint-disable-next-line @typescript-eslint/no-redeclare +export type OperationTypeNode = + (typeof OperationTypeNode)[keyof typeof OperationTypeNode]; export interface VariableDefinitionNode { - readonly kind: Kind.VARIABLE_DEFINITION; + readonly kind: typeof Kind.VARIABLE_DEFINITION; readonly loc?: Location | undefined; readonly variable: VariableNode; readonly type: TypeNode; @@ -352,13 +354,13 @@ export interface VariableDefinitionNode { } export interface VariableNode { - readonly kind: Kind.VARIABLE; + readonly kind: typeof Kind.VARIABLE; readonly loc?: Location | undefined; readonly name: NameNode; } export interface SelectionSetNode { - kind: Kind.SELECTION_SET; + kind: typeof Kind.SELECTION_SET; loc?: Location | undefined; selections: ReadonlyArray; } @@ -366,7 +368,7 @@ export interface SelectionSetNode { export type SelectionNode = FieldNode | FragmentSpreadNode | InlineFragmentNode; export interface FieldNode { - readonly kind: Kind.FIELD; + readonly kind: typeof Kind.FIELD; readonly loc?: Location | undefined; readonly alias?: NameNode | undefined; readonly name: NameNode; @@ -376,21 +378,21 @@ export interface FieldNode { } export interface ArgumentNode { - readonly kind: Kind.ARGUMENT; + readonly kind: typeof Kind.ARGUMENT; readonly loc?: Location | undefined; readonly name: NameNode; readonly value: ValueNode; } export interface ConstArgumentNode { - readonly kind: Kind.ARGUMENT; + readonly kind: typeof Kind.ARGUMENT; readonly loc?: Location | undefined; readonly name: NameNode; readonly value: ConstValueNode; } export interface FragmentArgumentNode { - readonly kind: Kind.FRAGMENT_ARGUMENT; + readonly kind: typeof Kind.FRAGMENT_ARGUMENT; readonly loc?: Location | undefined; readonly name: NameNode; readonly value: ValueNode; @@ -399,7 +401,7 @@ export interface FragmentArgumentNode { /** Fragments */ export interface FragmentSpreadNode { - readonly kind: Kind.FRAGMENT_SPREAD; + readonly kind: typeof Kind.FRAGMENT_SPREAD; readonly loc?: Location | undefined; readonly name: NameNode; readonly arguments?: ReadonlyArray | undefined; @@ -407,7 +409,7 @@ export interface FragmentSpreadNode { } export interface InlineFragmentNode { - readonly kind: Kind.INLINE_FRAGMENT; + readonly kind: typeof Kind.INLINE_FRAGMENT; readonly loc?: Location | undefined; readonly typeCondition?: NamedTypeNode | undefined; readonly directives?: ReadonlyArray | undefined; @@ -415,7 +417,7 @@ export interface InlineFragmentNode { } export interface FragmentDefinitionNode { - readonly kind: Kind.FRAGMENT_DEFINITION; + readonly kind: typeof Kind.FRAGMENT_DEFINITION; readonly loc?: Location | undefined; readonly name: NameNode; readonly variableDefinitions?: @@ -450,74 +452,74 @@ export type ConstValueNode = | ConstObjectValueNode; export interface IntValueNode { - readonly kind: Kind.INT; + readonly kind: typeof Kind.INT; readonly loc?: Location | undefined; readonly value: string; } export interface FloatValueNode { - readonly kind: Kind.FLOAT; + readonly kind: typeof Kind.FLOAT; readonly loc?: Location | undefined; readonly value: string; } export interface StringValueNode { - readonly kind: Kind.STRING; + readonly kind: typeof Kind.STRING; readonly loc?: Location | undefined; readonly value: string; readonly block?: boolean | undefined; } export interface BooleanValueNode { - readonly kind: Kind.BOOLEAN; + readonly kind: typeof Kind.BOOLEAN; readonly loc?: Location | undefined; readonly value: boolean; } export interface NullValueNode { - readonly kind: Kind.NULL; + readonly kind: typeof Kind.NULL; readonly loc?: Location | undefined; } export interface EnumValueNode { - readonly kind: Kind.ENUM; + readonly kind: typeof Kind.ENUM; readonly loc?: Location | undefined; readonly value: string; } export interface ListValueNode { - readonly kind: Kind.LIST; + readonly kind: typeof Kind.LIST; readonly loc?: Location | undefined; readonly values: ReadonlyArray; } export interface ConstListValueNode { - readonly kind: Kind.LIST; + readonly kind: typeof Kind.LIST; readonly loc?: Location | undefined; readonly values: ReadonlyArray; } export interface ObjectValueNode { - readonly kind: Kind.OBJECT; + readonly kind: typeof Kind.OBJECT; readonly loc?: Location | undefined; readonly fields: ReadonlyArray; } export interface ConstObjectValueNode { - readonly kind: Kind.OBJECT; + readonly kind: typeof Kind.OBJECT; readonly loc?: Location | undefined; readonly fields: ReadonlyArray; } export interface ObjectFieldNode { - readonly kind: Kind.OBJECT_FIELD; + readonly kind: typeof Kind.OBJECT_FIELD; readonly loc?: Location | undefined; readonly name: NameNode; readonly value: ValueNode; } export interface ConstObjectFieldNode { - readonly kind: Kind.OBJECT_FIELD; + readonly kind: typeof Kind.OBJECT_FIELD; readonly loc?: Location | undefined; readonly name: NameNode; readonly value: ConstValueNode; @@ -526,14 +528,14 @@ export interface ConstObjectFieldNode { /** Directives */ export interface DirectiveNode { - readonly kind: Kind.DIRECTIVE; + readonly kind: typeof Kind.DIRECTIVE; readonly loc?: Location | undefined; readonly name: NameNode; readonly arguments?: ReadonlyArray | undefined; } export interface ConstDirectiveNode { - readonly kind: Kind.DIRECTIVE; + readonly kind: typeof Kind.DIRECTIVE; readonly loc?: Location | undefined; readonly name: NameNode; readonly arguments?: ReadonlyArray | undefined; @@ -544,19 +546,19 @@ export interface ConstDirectiveNode { export type TypeNode = NamedTypeNode | ListTypeNode | NonNullTypeNode; export interface NamedTypeNode { - readonly kind: Kind.NAMED_TYPE; + readonly kind: typeof Kind.NAMED_TYPE; readonly loc?: Location | undefined; readonly name: NameNode; } export interface ListTypeNode { - readonly kind: Kind.LIST_TYPE; + readonly kind: typeof Kind.LIST_TYPE; readonly loc?: Location | undefined; readonly type: TypeNode; } export interface NonNullTypeNode { - readonly kind: Kind.NON_NULL_TYPE; + readonly kind: typeof Kind.NON_NULL_TYPE; readonly loc?: Location | undefined; readonly type: NamedTypeNode | ListTypeNode; } @@ -569,7 +571,7 @@ export type TypeSystemDefinitionNode = | DirectiveDefinitionNode; export interface SchemaDefinitionNode { - readonly kind: Kind.SCHEMA_DEFINITION; + readonly kind: typeof Kind.SCHEMA_DEFINITION; readonly loc?: Location | undefined; readonly description?: StringValueNode | undefined; readonly directives?: ReadonlyArray | undefined; @@ -577,7 +579,7 @@ export interface SchemaDefinitionNode { } export interface OperationTypeDefinitionNode { - readonly kind: Kind.OPERATION_TYPE_DEFINITION; + readonly kind: typeof Kind.OPERATION_TYPE_DEFINITION; readonly loc?: Location | undefined; readonly operation: OperationTypeNode; readonly type: NamedTypeNode; @@ -594,7 +596,7 @@ export type TypeDefinitionNode = | InputObjectTypeDefinitionNode; export interface ScalarTypeDefinitionNode { - readonly kind: Kind.SCALAR_TYPE_DEFINITION; + readonly kind: typeof Kind.SCALAR_TYPE_DEFINITION; readonly loc?: Location | undefined; readonly description?: StringValueNode | undefined; readonly name: NameNode; @@ -602,7 +604,7 @@ export interface ScalarTypeDefinitionNode { } export interface ObjectTypeDefinitionNode { - readonly kind: Kind.OBJECT_TYPE_DEFINITION; + readonly kind: typeof Kind.OBJECT_TYPE_DEFINITION; readonly loc?: Location | undefined; readonly description?: StringValueNode | undefined; readonly name: NameNode; @@ -612,7 +614,7 @@ export interface ObjectTypeDefinitionNode { } export interface FieldDefinitionNode { - readonly kind: Kind.FIELD_DEFINITION; + readonly kind: typeof Kind.FIELD_DEFINITION; readonly loc?: Location | undefined; readonly description?: StringValueNode | undefined; readonly name: NameNode; @@ -622,7 +624,7 @@ export interface FieldDefinitionNode { } export interface InputValueDefinitionNode { - readonly kind: Kind.INPUT_VALUE_DEFINITION; + readonly kind: typeof Kind.INPUT_VALUE_DEFINITION; readonly loc?: Location | undefined; readonly description?: StringValueNode | undefined; readonly name: NameNode; @@ -632,7 +634,7 @@ export interface InputValueDefinitionNode { } export interface InterfaceTypeDefinitionNode { - readonly kind: Kind.INTERFACE_TYPE_DEFINITION; + readonly kind: typeof Kind.INTERFACE_TYPE_DEFINITION; readonly loc?: Location | undefined; readonly description?: StringValueNode | undefined; readonly name: NameNode; @@ -642,7 +644,7 @@ export interface InterfaceTypeDefinitionNode { } export interface UnionTypeDefinitionNode { - readonly kind: Kind.UNION_TYPE_DEFINITION; + readonly kind: typeof Kind.UNION_TYPE_DEFINITION; readonly loc?: Location | undefined; readonly description?: StringValueNode | undefined; readonly name: NameNode; @@ -651,7 +653,7 @@ export interface UnionTypeDefinitionNode { } export interface EnumTypeDefinitionNode { - readonly kind: Kind.ENUM_TYPE_DEFINITION; + readonly kind: typeof Kind.ENUM_TYPE_DEFINITION; readonly loc?: Location | undefined; readonly description?: StringValueNode | undefined; readonly name: NameNode; @@ -660,7 +662,7 @@ export interface EnumTypeDefinitionNode { } export interface EnumValueDefinitionNode { - readonly kind: Kind.ENUM_VALUE_DEFINITION; + readonly kind: typeof Kind.ENUM_VALUE_DEFINITION; readonly loc?: Location | undefined; readonly description?: StringValueNode | undefined; readonly name: NameNode; @@ -668,7 +670,7 @@ export interface EnumValueDefinitionNode { } export interface InputObjectTypeDefinitionNode { - readonly kind: Kind.INPUT_OBJECT_TYPE_DEFINITION; + readonly kind: typeof Kind.INPUT_OBJECT_TYPE_DEFINITION; readonly loc?: Location | undefined; readonly description?: StringValueNode | undefined; readonly name: NameNode; @@ -679,7 +681,7 @@ export interface InputObjectTypeDefinitionNode { /** Directive Definitions */ export interface DirectiveDefinitionNode { - readonly kind: Kind.DIRECTIVE_DEFINITION; + readonly kind: typeof Kind.DIRECTIVE_DEFINITION; readonly loc?: Location | undefined; readonly description?: StringValueNode | undefined; readonly name: NameNode; @@ -693,7 +695,7 @@ export interface DirectiveDefinitionNode { export type TypeSystemExtensionNode = SchemaExtensionNode | TypeExtensionNode; export interface SchemaExtensionNode { - readonly kind: Kind.SCHEMA_EXTENSION; + readonly kind: typeof Kind.SCHEMA_EXTENSION; readonly loc?: Location | undefined; readonly directives?: ReadonlyArray | undefined; readonly operationTypes?: @@ -712,14 +714,14 @@ export type TypeExtensionNode = | InputObjectTypeExtensionNode; export interface ScalarTypeExtensionNode { - readonly kind: Kind.SCALAR_TYPE_EXTENSION; + readonly kind: typeof Kind.SCALAR_TYPE_EXTENSION; readonly loc?: Location | undefined; readonly name: NameNode; readonly directives?: ReadonlyArray | undefined; } export interface ObjectTypeExtensionNode { - readonly kind: Kind.OBJECT_TYPE_EXTENSION; + readonly kind: typeof Kind.OBJECT_TYPE_EXTENSION; readonly loc?: Location | undefined; readonly name: NameNode; readonly interfaces?: ReadonlyArray | undefined; @@ -728,7 +730,7 @@ export interface ObjectTypeExtensionNode { } export interface InterfaceTypeExtensionNode { - readonly kind: Kind.INTERFACE_TYPE_EXTENSION; + readonly kind: typeof Kind.INTERFACE_TYPE_EXTENSION; readonly loc?: Location | undefined; readonly name: NameNode; readonly interfaces?: ReadonlyArray | undefined; @@ -737,7 +739,7 @@ export interface InterfaceTypeExtensionNode { } export interface UnionTypeExtensionNode { - readonly kind: Kind.UNION_TYPE_EXTENSION; + readonly kind: typeof Kind.UNION_TYPE_EXTENSION; readonly loc?: Location | undefined; readonly name: NameNode; readonly directives?: ReadonlyArray | undefined; @@ -745,7 +747,7 @@ export interface UnionTypeExtensionNode { } export interface EnumTypeExtensionNode { - readonly kind: Kind.ENUM_TYPE_EXTENSION; + readonly kind: typeof Kind.ENUM_TYPE_EXTENSION; readonly loc?: Location | undefined; readonly name: NameNode; readonly directives?: ReadonlyArray | undefined; @@ -753,7 +755,7 @@ export interface EnumTypeExtensionNode { } export interface InputObjectTypeExtensionNode { - readonly kind: Kind.INPUT_OBJECT_TYPE_EXTENSION; + readonly kind: typeof Kind.INPUT_OBJECT_TYPE_EXTENSION; readonly loc?: Location | undefined; readonly name: NameNode; readonly directives?: ReadonlyArray | undefined; diff --git a/src/language/directiveLocation.ts b/src/language/directiveLocation.ts index 0d90c80b29..fd4871826d 100644 --- a/src/language/directiveLocation.ts +++ b/src/language/directiveLocation.ts @@ -1,29 +1,30 @@ /** * The set of allowed directive location values. */ -enum DirectiveLocation { +export const DirectiveLocation = { /** Request Definitions */ - QUERY = 'QUERY', - MUTATION = 'MUTATION', - SUBSCRIPTION = 'SUBSCRIPTION', - FIELD = 'FIELD', - FRAGMENT_DEFINITION = 'FRAGMENT_DEFINITION', - FRAGMENT_SPREAD = 'FRAGMENT_SPREAD', - INLINE_FRAGMENT = 'INLINE_FRAGMENT', - VARIABLE_DEFINITION = 'VARIABLE_DEFINITION', + QUERY: 'QUERY' as const, + MUTATION: 'MUTATION' as const, + SUBSCRIPTION: 'SUBSCRIPTION' as const, + FIELD: 'FIELD' as const, + FRAGMENT_DEFINITION: 'FRAGMENT_DEFINITION' as const, + FRAGMENT_SPREAD: 'FRAGMENT_SPREAD' as const, + INLINE_FRAGMENT: 'INLINE_FRAGMENT' as const, + VARIABLE_DEFINITION: 'VARIABLE_DEFINITION' as const, /** Type System Definitions */ - SCHEMA = 'SCHEMA', - SCALAR = 'SCALAR', - OBJECT = 'OBJECT', - FIELD_DEFINITION = 'FIELD_DEFINITION', - ARGUMENT_DEFINITION = 'ARGUMENT_DEFINITION', - INTERFACE = 'INTERFACE', - UNION = 'UNION', - ENUM = 'ENUM', - ENUM_VALUE = 'ENUM_VALUE', - INPUT_OBJECT = 'INPUT_OBJECT', - INPUT_FIELD_DEFINITION = 'INPUT_FIELD_DEFINITION', - FRAGMENT_VARIABLE_DEFINITION = 'FRAGMENT_VARIABLE_DEFINITION', -} - -export { DirectiveLocation }; + SCHEMA: 'SCHEMA' as const, + SCALAR: 'SCALAR' as const, + OBJECT: 'OBJECT' as const, + FIELD_DEFINITION: 'FIELD_DEFINITION' as const, + ARGUMENT_DEFINITION: 'ARGUMENT_DEFINITION' as const, + INTERFACE: 'INTERFACE' as const, + UNION: 'UNION' as const, + ENUM: 'ENUM' as const, + ENUM_VALUE: 'ENUM_VALUE' as const, + INPUT_OBJECT: 'INPUT_OBJECT' as const, + INPUT_FIELD_DEFINITION: 'INPUT_FIELD_DEFINITION' as const, + FRAGMENT_VARIABLE_DEFINITION: 'FRAGMENT_VARIABLE_DEFINITION' as const, +} as const; +// eslint-disable-next-line @typescript-eslint/no-redeclare +export type DirectiveLocation = + (typeof DirectiveLocation)[keyof typeof DirectiveLocation]; diff --git a/src/language/kinds.ts b/src/language/kinds.ts index 52aa7c167a..d41eccecfc 100644 --- a/src/language/kinds.ts +++ b/src/language/kinds.ts @@ -1,72 +1,72 @@ /** * The set of allowed kind values for AST nodes. */ -enum Kind { +export const Kind = { /** Name */ - NAME = 'Name', + NAME: 'Name' as const, /** Document */ - DOCUMENT = 'Document', - OPERATION_DEFINITION = 'OperationDefinition', - VARIABLE_DEFINITION = 'VariableDefinition', - SELECTION_SET = 'SelectionSet', - FIELD = 'Field', - ARGUMENT = 'Argument', - FRAGMENT_ARGUMENT = 'FragmentArgument', + 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', - INLINE_FRAGMENT = 'InlineFragment', - FRAGMENT_DEFINITION = 'FragmentDefinition', + FRAGMENT_SPREAD: 'FragmentSpread' as const, + INLINE_FRAGMENT: 'InlineFragment' as const, + FRAGMENT_DEFINITION: 'FragmentDefinition' as const, /** Values */ - VARIABLE = 'Variable', - INT = 'IntValue', - FLOAT = 'FloatValue', - STRING = 'StringValue', - BOOLEAN = 'BooleanValue', - NULL = 'NullValue', - ENUM = 'EnumValue', - LIST = 'ListValue', - OBJECT = 'ObjectValue', - OBJECT_FIELD = 'ObjectField', + 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', + DIRECTIVE: 'Directive' as const, /** Types */ - NAMED_TYPE = 'NamedType', - LIST_TYPE = 'ListType', - NON_NULL_TYPE = 'NonNullType', + NAMED_TYPE: 'NamedType' as const, + LIST_TYPE: 'ListType' as const, + NON_NULL_TYPE: 'NonNullType' as const, /** Type System Definitions */ - SCHEMA_DEFINITION = 'SchemaDefinition', - OPERATION_TYPE_DEFINITION = 'OperationTypeDefinition', + SCHEMA_DEFINITION: 'SchemaDefinition' as const, + OPERATION_TYPE_DEFINITION: 'OperationTypeDefinition' as const, /** Type Definitions */ - SCALAR_TYPE_DEFINITION = 'ScalarTypeDefinition', - OBJECT_TYPE_DEFINITION = 'ObjectTypeDefinition', - FIELD_DEFINITION = 'FieldDefinition', - INPUT_VALUE_DEFINITION = 'InputValueDefinition', - INTERFACE_TYPE_DEFINITION = 'InterfaceTypeDefinition', - UNION_TYPE_DEFINITION = 'UnionTypeDefinition', - ENUM_TYPE_DEFINITION = 'EnumTypeDefinition', - ENUM_VALUE_DEFINITION = 'EnumValueDefinition', - INPUT_OBJECT_TYPE_DEFINITION = 'InputObjectTypeDefinition', + 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', + DIRECTIVE_DEFINITION: 'DirectiveDefinition' as const, /** Type System Extensions */ - SCHEMA_EXTENSION = 'SchemaExtension', + SCHEMA_EXTENSION: 'SchemaExtension' as const, /** Type Extensions */ - SCALAR_TYPE_EXTENSION = 'ScalarTypeExtension', - OBJECT_TYPE_EXTENSION = 'ObjectTypeExtension', - INTERFACE_TYPE_EXTENSION = 'InterfaceTypeExtension', - UNION_TYPE_EXTENSION = 'UnionTypeExtension', - ENUM_TYPE_EXTENSION = 'EnumTypeExtension', - INPUT_OBJECT_TYPE_EXTENSION = 'InputObjectTypeExtension', -} - -export { Kind }; + 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]; diff --git a/src/language/tokenKind.ts b/src/language/tokenKind.ts index 37f307aba6..d1c7129b04 100644 --- a/src/language/tokenKind.ts +++ b/src/language/tokenKind.ts @@ -2,29 +2,29 @@ * An exported enum describing the different kinds of tokens that the * lexer emits. */ -enum TokenKind { - SOF = '', - EOF = '', - BANG = '!', - DOLLAR = '$', - AMP = '&', - PAREN_L = '(', - PAREN_R = ')', - SPREAD = '...', - COLON = ':', - EQUALS = '=', - AT = '@', - BRACKET_L = '[', - BRACKET_R = ']', - BRACE_L = '{', - PIPE = '|', - BRACE_R = '}', - NAME = 'Name', - INT = 'Int', - FLOAT = 'Float', - STRING = 'String', - BLOCK_STRING = 'BlockString', - COMMENT = 'Comment', -} - -export { TokenKind }; +export const TokenKind = { + SOF: '' as const, + EOF: '' as const, + BANG: '!' as const, + DOLLAR: '$' as const, + AMP: '&' as const, + PAREN_L: '(' as const, + PAREN_R: ')' as const, + SPREAD: '...' as const, + COLON: ':' as const, + EQUALS: '=' as const, + AT: '@' as const, + BRACKET_L: '[' as const, + BRACKET_R: ']' as const, + BRACE_L: '{' as const, + PIPE: '|' as const, + BRACE_R: '}' as const, + NAME: 'Name' as const, + INT: 'Int' as const, + FLOAT: 'Float' as const, + STRING: 'String' as const, + BLOCK_STRING: 'BlockString' as const, + COMMENT: 'Comment' as const, +} as const; +// eslint-disable-next-line @typescript-eslint/no-redeclare +export type TokenKind = (typeof TokenKind)[keyof typeof TokenKind]; diff --git a/src/type/introspection.ts b/src/type/introspection.ts index b72b162cbb..97739183d8 100644 --- a/src/type/introspection.ts +++ b/src/type/introspection.ts @@ -452,17 +452,19 @@ export const __EnumValue: GraphQLObjectType = new GraphQLObjectType({ }) as GraphQLFieldConfigMap, }); -enum TypeKind { - SCALAR = 'SCALAR', - OBJECT = 'OBJECT', - INTERFACE = 'INTERFACE', - UNION = 'UNION', - ENUM = 'ENUM', - INPUT_OBJECT = 'INPUT_OBJECT', - LIST = 'LIST', - NON_NULL = 'NON_NULL', -} -export { TypeKind }; +export const TypeKind = { + SCALAR: 'SCALAR' as const, + OBJECT: 'OBJECT' as const, + INTERFACE: 'INTERFACE' as const, + UNION: 'UNION' as const, + ENUM: 'ENUM' as const, + INPUT_OBJECT: 'INPUT_OBJECT' as const, + LIST: 'LIST' as const, + NON_NULL: 'NON_NULL' as const, +} as const; + +// eslint-disable-next-line @typescript-eslint/no-redeclare +export type TypeKind = (typeof TypeKind)[keyof typeof TypeKind]; export const __TypeKind: GraphQLEnumType = new GraphQLEnumType({ name: '__TypeKind', diff --git a/src/utilities/findSchemaChanges.ts b/src/utilities/findSchemaChanges.ts index 909e3161e6..c47a39aa3e 100644 --- a/src/utilities/findSchemaChanges.ts +++ b/src/utilities/findSchemaChanges.ts @@ -35,50 +35,56 @@ import type { GraphQLSchema } from '../type/schema.js'; import { astFromValue } from './astFromValue.js'; import { sortValueNode } from './sortValueNode.js'; -enum BreakingChangeType { - TYPE_REMOVED = 'TYPE_REMOVED', - TYPE_CHANGED_KIND = 'TYPE_CHANGED_KIND', - TYPE_REMOVED_FROM_UNION = 'TYPE_REMOVED_FROM_UNION', - VALUE_REMOVED_FROM_ENUM = 'VALUE_REMOVED_FROM_ENUM', - REQUIRED_INPUT_FIELD_ADDED = 'REQUIRED_INPUT_FIELD_ADDED', - IMPLEMENTED_INTERFACE_REMOVED = 'IMPLEMENTED_INTERFACE_REMOVED', - FIELD_REMOVED = 'FIELD_REMOVED', - FIELD_CHANGED_KIND = 'FIELD_CHANGED_KIND', - REQUIRED_ARG_ADDED = 'REQUIRED_ARG_ADDED', - ARG_REMOVED = 'ARG_REMOVED', - ARG_CHANGED_KIND = 'ARG_CHANGED_KIND', - DIRECTIVE_REMOVED = 'DIRECTIVE_REMOVED', - DIRECTIVE_ARG_REMOVED = 'DIRECTIVE_ARG_REMOVED', - REQUIRED_DIRECTIVE_ARG_ADDED = 'REQUIRED_DIRECTIVE_ARG_ADDED', - DIRECTIVE_REPEATABLE_REMOVED = 'DIRECTIVE_REPEATABLE_REMOVED', - DIRECTIVE_LOCATION_REMOVED = 'DIRECTIVE_LOCATION_REMOVED', -} -export { BreakingChangeType }; - -enum DangerousChangeType { - VALUE_ADDED_TO_ENUM = 'VALUE_ADDED_TO_ENUM', - TYPE_ADDED_TO_UNION = 'TYPE_ADDED_TO_UNION', - OPTIONAL_INPUT_FIELD_ADDED = 'OPTIONAL_INPUT_FIELD_ADDED', - OPTIONAL_ARG_ADDED = 'OPTIONAL_ARG_ADDED', - IMPLEMENTED_INTERFACE_ADDED = 'IMPLEMENTED_INTERFACE_ADDED', - ARG_DEFAULT_VALUE_CHANGE = 'ARG_DEFAULT_VALUE_CHANGE', -} -export { DangerousChangeType }; - -enum SafeChangeType { - TYPE_ADDED = 'TYPE_ADDED', - OPTIONAL_INPUT_FIELD_ADDED = 'OPTIONAL_INPUT_FIELD_ADDED', - OPTIONAL_ARG_ADDED = 'OPTIONAL_ARG_ADDED', - DIRECTIVE_ADDED = 'DIRECTIVE_ADDED', - FIELD_ADDED = 'FIELD_ADDED', - DIRECTIVE_REPEATABLE_ADDED = 'DIRECTIVE_REPEATABLE_ADDED', - DIRECTIVE_LOCATION_ADDED = 'DIRECTIVE_LOCATION_ADDED', - OPTIONAL_DIRECTIVE_ARG_ADDED = 'OPTIONAL_DIRECTIVE_ARG_ADDED', - FIELD_CHANGED_KIND_SAFE = 'FIELD_CHANGED_KIND_SAFE', - ARG_CHANGED_KIND_SAFE = 'ARG_CHANGED_KIND_SAFE', - ARG_DEFAULT_VALUE_ADDED = 'ARG_DEFAULT_VALUE_ADDED', -} -export { SafeChangeType }; +export const BreakingChangeType = { + TYPE_REMOVED: 'TYPE_REMOVED' as const, + TYPE_CHANGED_KIND: 'TYPE_CHANGED_KIND' as const, + TYPE_REMOVED_FROM_UNION: 'TYPE_REMOVED_FROM_UNION' as const, + VALUE_REMOVED_FROM_ENUM: 'VALUE_REMOVED_FROM_ENUM' as const, + REQUIRED_INPUT_FIELD_ADDED: 'REQUIRED_INPUT_FIELD_ADDED' as const, + IMPLEMENTED_INTERFACE_REMOVED: 'IMPLEMENTED_INTERFACE_REMOVED' as const, + FIELD_REMOVED: 'FIELD_REMOVED' as const, + FIELD_CHANGED_KIND: 'FIELD_CHANGED_KIND' as const, + REQUIRED_ARG_ADDED: 'REQUIRED_ARG_ADDED' as const, + ARG_REMOVED: 'ARG_REMOVED' as const, + ARG_CHANGED_KIND: 'ARG_CHANGED_KIND' as const, + DIRECTIVE_REMOVED: 'DIRECTIVE_REMOVED' as const, + DIRECTIVE_ARG_REMOVED: 'DIRECTIVE_ARG_REMOVED' as const, + REQUIRED_DIRECTIVE_ARG_ADDED: 'REQUIRED_DIRECTIVE_ARG_ADDED' as const, + DIRECTIVE_REPEATABLE_REMOVED: 'DIRECTIVE_REPEATABLE_REMOVED' as const, + DIRECTIVE_LOCATION_REMOVED: 'DIRECTIVE_LOCATION_REMOVED' as const, +} as const; +// eslint-disable-next-line @typescript-eslint/no-redeclare +export type BreakingChangeType = + (typeof BreakingChangeType)[keyof typeof BreakingChangeType]; + +export const DangerousChangeType = { + VALUE_ADDED_TO_ENUM: 'VALUE_ADDED_TO_ENUM' as const, + TYPE_ADDED_TO_UNION: 'TYPE_ADDED_TO_UNION' as const, + OPTIONAL_INPUT_FIELD_ADDED: 'OPTIONAL_INPUT_FIELD_ADDED' as const, + OPTIONAL_ARG_ADDED: 'OPTIONAL_ARG_ADDED' as const, + IMPLEMENTED_INTERFACE_ADDED: 'IMPLEMENTED_INTERFACE_ADDED' as const, + ARG_DEFAULT_VALUE_CHANGE: 'ARG_DEFAULT_VALUE_CHANGE' as const, +}; +// eslint-disable-next-line @typescript-eslint/no-redeclare +export type DangerousChangeType = + (typeof DangerousChangeType)[keyof typeof DangerousChangeType]; + +export const SafeChangeType = { + TYPE_ADDED: 'TYPE_ADDED' as const, + OPTIONAL_INPUT_FIELD_ADDED: 'OPTIONAL_INPUT_FIELD_ADDED' as const, + OPTIONAL_ARG_ADDED: 'OPTIONAL_ARG_ADDED' as const, + DIRECTIVE_ADDED: 'DIRECTIVE_ADDED' as const, + FIELD_ADDED: 'FIELD_ADDED' as const, + DIRECTIVE_REPEATABLE_ADDED: 'DIRECTIVE_REPEATABLE_ADDED' as const, + DIRECTIVE_LOCATION_ADDED: 'DIRECTIVE_LOCATION_ADDED' as const, + OPTIONAL_DIRECTIVE_ARG_ADDED: 'OPTIONAL_DIRECTIVE_ARG_ADDED' as const, + FIELD_CHANGED_KIND_SAFE: 'FIELD_CHANGED_KIND_SAFE' as const, + ARG_CHANGED_KIND_SAFE: 'ARG_CHANGED_KIND_SAFE' as const, + ARG_DEFAULT_VALUE_ADDED: 'ARG_DEFAULT_VALUE_ADDED' as const, +}; +// eslint-disable-next-line @typescript-eslint/no-redeclare +export type SafeChangeType = + (typeof SafeChangeType)[keyof typeof SafeChangeType]; export interface BreakingChange { type: BreakingChangeType; diff --git a/src/utilities/getIntrospectionQuery.ts b/src/utilities/getIntrospectionQuery.ts index b516dda39e..94fdfe59d7 100644 --- a/src/utilities/getIntrospectionQuery.ts +++ b/src/utilities/getIntrospectionQuery.ts @@ -220,14 +220,14 @@ export type IntrospectionInputType = | IntrospectionInputObjectType; export interface IntrospectionScalarType { - readonly kind: TypeKind.SCALAR; + readonly kind: typeof TypeKind.SCALAR; readonly name: string; readonly description?: Maybe; readonly specifiedByURL?: Maybe; } export interface IntrospectionObjectType { - readonly kind: TypeKind.OBJECT; + readonly kind: typeof TypeKind.OBJECT; readonly name: string; readonly description?: Maybe; readonly fields: ReadonlyArray; @@ -237,7 +237,7 @@ export interface IntrospectionObjectType { } export interface IntrospectionInterfaceType { - readonly kind: TypeKind.INTERFACE; + readonly kind: typeof TypeKind.INTERFACE; readonly name: string; readonly description?: Maybe; readonly fields: ReadonlyArray; @@ -250,7 +250,7 @@ export interface IntrospectionInterfaceType { } export interface IntrospectionUnionType { - readonly kind: TypeKind.UNION; + readonly kind: typeof TypeKind.UNION; readonly name: string; readonly description?: Maybe; readonly possibleTypes: ReadonlyArray< @@ -259,14 +259,14 @@ export interface IntrospectionUnionType { } export interface IntrospectionEnumType { - readonly kind: TypeKind.ENUM; + readonly kind: typeof TypeKind.ENUM; readonly name: string; readonly description?: Maybe; readonly enumValues: ReadonlyArray; } export interface IntrospectionInputObjectType { - readonly kind: TypeKind.INPUT_OBJECT; + readonly kind: typeof TypeKind.INPUT_OBJECT; readonly name: string; readonly description?: Maybe; readonly inputFields: ReadonlyArray; @@ -276,14 +276,14 @@ export interface IntrospectionInputObjectType { export interface IntrospectionListTypeRef< T extends IntrospectionTypeRef = IntrospectionTypeRef, > { - readonly kind: TypeKind.LIST; + readonly kind: typeof TypeKind.LIST; readonly ofType: T; } export interface IntrospectionNonNullTypeRef< T extends IntrospectionTypeRef = IntrospectionTypeRef, > { - readonly kind: TypeKind.NON_NULL; + readonly kind: typeof TypeKind.NON_NULL; readonly ofType: T; }