From 73025aa009039c1e2e74f7bbd088ec6ab6e07e94 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Mon, 18 Oct 2021 12:26:43 +0300 Subject: [PATCH] Convert const "enum-like" maps to TS enums (#3317) --- src/language/__tests__/printer-test.ts | 5 +- src/language/__tests__/schema-printer-test.ts | 5 +- src/language/ast.ts | 104 +++++++++--------- src/language/directiveLocation.ts | 47 ++++---- src/language/kinds.ts | 94 ++++++++-------- src/language/lexer.ts | 5 +- src/language/parser.ts | 23 ++-- src/language/tokenKind.ts | 52 ++++----- src/type/__tests__/directive-test.ts | 20 ++-- src/type/__tests__/predicate-test.ts | 4 +- src/type/__tests__/schema-test.ts | 4 +- src/type/__tests__/validation-test.ts | 3 +- src/type/directives.ts | 5 +- src/type/introspection.ts | 20 ++-- src/utilities/astFromValue.ts | 4 +- src/utilities/concatAST.ts | 3 +- src/utilities/findBreakingChanges.ts | 58 +++++----- src/utilities/getIntrospectionQuery.ts | 4 +- src/utilities/printSchema.ts | 8 +- src/validation/rules/KnownDirectivesRule.ts | 5 +- .../rules/PossibleTypeExtensionsRule.ts | 9 +- 21 files changed, 250 insertions(+), 232 deletions(-) diff --git a/src/language/__tests__/printer-test.ts b/src/language/__tests__/printer-test.ts index 5e6776b8ac..9c2fcf9c5f 100644 --- a/src/language/__tests__/printer-test.ts +++ b/src/language/__tests__/printer-test.ts @@ -4,14 +4,15 @@ import { describe, it } from 'mocha'; import { dedent, dedentString } from '../../__testUtils__/dedent'; import { kitchenSinkQuery } from '../../__testUtils__/kitchenSinkQuery'; +import { Kind } from '../kinds'; import { parse } from '../parser'; import { print } from '../printer'; describe('Printer: Query document', () => { it('prints minimal ast', () => { const ast = { - kind: 'Field', - name: { kind: 'Name', value: 'foo' }, + kind: Kind.FIELD, + name: { kind: Kind.NAME, value: 'foo' }, } as const; expect(print(ast)).to.equal('foo'); }); diff --git a/src/language/__tests__/schema-printer-test.ts b/src/language/__tests__/schema-printer-test.ts index 9ad0339394..49a32693ff 100644 --- a/src/language/__tests__/schema-printer-test.ts +++ b/src/language/__tests__/schema-printer-test.ts @@ -4,14 +4,15 @@ import { describe, it } from 'mocha'; import { dedent } from '../../__testUtils__/dedent'; import { kitchenSinkSDL } from '../../__testUtils__/kitchenSinkSDL'; +import { Kind } from '../kinds'; import { parse } from '../parser'; import { print } from '../printer'; describe('Printer: SDL document', () => { it('prints minimal ast', () => { const ast = { - kind: 'ScalarTypeDefinition', - name: { kind: 'Name', value: 'foo' }, + kind: Kind.SCALAR_TYPE_DEFINITION, + name: { kind: Kind.NAME, value: 'foo' }, } as const; expect(print(ast)).to.equal('scalar foo'); }); diff --git a/src/language/ast.ts b/src/language/ast.ts index 3e658e2883..af2b7fd7ee 100644 --- a/src/language/ast.ts +++ b/src/language/ast.ts @@ -1,6 +1,6 @@ import type { Kind } from './kinds'; import type { Source } from './source'; -import type { TokenKindEnum } from './tokenKind'; +import type { TokenKind } from './tokenKind'; /** * Contains a range of UTF-8 character offsets and token references that @@ -57,7 +57,7 @@ export class Token { /** * The kind of Token. */ - readonly kind: TokenKindEnum; + readonly kind: TokenKind; /** * The character offset at which this Node begins. @@ -96,7 +96,7 @@ export class Token { readonly next: Token | null; constructor( - kind: TokenKindEnum, + kind: TokenKind, start: number, end: number, line: number, @@ -115,7 +115,7 @@ export class Token { } toJSON(): { - kind: TokenKindEnum; + kind: TokenKind; value?: string; line: number; column: number; @@ -333,7 +333,7 @@ export function isNode(maybeNode: any): maybeNode is ASTNode { /** Name */ export interface NameNode { - readonly kind: typeof Kind.NAME; + readonly kind: Kind.NAME; readonly loc?: Location; readonly value: string; } @@ -341,7 +341,7 @@ export interface NameNode { /** Document */ export interface DocumentNode { - readonly kind: typeof Kind.DOCUMENT; + readonly kind: Kind.DOCUMENT; readonly loc?: Location; readonly definitions: ReadonlyArray; } @@ -356,7 +356,7 @@ export type ExecutableDefinitionNode = | FragmentDefinitionNode; export interface OperationDefinitionNode { - readonly kind: typeof Kind.OPERATION_DEFINITION; + readonly kind: Kind.OPERATION_DEFINITION; readonly loc?: Location; readonly operation: OperationTypeNode; readonly name?: NameNode; @@ -372,7 +372,7 @@ export enum OperationTypeNode { } export interface VariableDefinitionNode { - readonly kind: typeof Kind.VARIABLE_DEFINITION; + readonly kind: Kind.VARIABLE_DEFINITION; readonly loc?: Location; readonly variable: VariableNode; readonly type: TypeNode; @@ -381,13 +381,13 @@ export interface VariableDefinitionNode { } export interface VariableNode { - readonly kind: typeof Kind.VARIABLE; + readonly kind: Kind.VARIABLE; readonly loc?: Location; readonly name: NameNode; } export interface SelectionSetNode { - kind: typeof Kind.SELECTION_SET; + kind: Kind.SELECTION_SET; loc?: Location; selections: ReadonlyArray; } @@ -395,7 +395,7 @@ export interface SelectionSetNode { export type SelectionNode = FieldNode | FragmentSpreadNode | InlineFragmentNode; export interface FieldNode { - readonly kind: typeof Kind.FIELD; + readonly kind: Kind.FIELD; readonly loc?: Location; readonly alias?: NameNode; readonly name: NameNode; @@ -405,14 +405,14 @@ export interface FieldNode { } export interface ArgumentNode { - readonly kind: typeof Kind.ARGUMENT; + readonly kind: Kind.ARGUMENT; readonly loc?: Location; readonly name: NameNode; readonly value: ValueNode; } export interface ConstArgumentNode { - readonly kind: 'Argument'; + readonly kind: Kind.ARGUMENT; readonly loc?: Location; readonly name: NameNode; readonly value: ConstValueNode; @@ -421,14 +421,14 @@ export interface ConstArgumentNode { /** Fragments */ export interface FragmentSpreadNode { - readonly kind: typeof Kind.FRAGMENT_SPREAD; + readonly kind: Kind.FRAGMENT_SPREAD; readonly loc?: Location; readonly name: NameNode; readonly directives?: ReadonlyArray; } export interface InlineFragmentNode { - readonly kind: typeof Kind.INLINE_FRAGMENT; + readonly kind: Kind.INLINE_FRAGMENT; readonly loc?: Location; readonly typeCondition?: NamedTypeNode; readonly directives?: ReadonlyArray; @@ -436,7 +436,7 @@ export interface InlineFragmentNode { } export interface FragmentDefinitionNode { - readonly kind: typeof Kind.FRAGMENT_DEFINITION; + readonly kind: Kind.FRAGMENT_DEFINITION; readonly loc?: Location; readonly name: NameNode; /** @deprecated variableDefinitions will be removed in v17.0.0 */ @@ -470,74 +470,74 @@ export type ConstValueNode = | ConstObjectValueNode; export interface IntValueNode { - readonly kind: typeof Kind.INT; + readonly kind: Kind.INT; readonly loc?: Location; readonly value: string; } export interface FloatValueNode { - readonly kind: typeof Kind.FLOAT; + readonly kind: Kind.FLOAT; readonly loc?: Location; readonly value: string; } export interface StringValueNode { - readonly kind: typeof Kind.STRING; + readonly kind: Kind.STRING; readonly loc?: Location; readonly value: string; readonly block?: boolean; } export interface BooleanValueNode { - readonly kind: typeof Kind.BOOLEAN; + readonly kind: Kind.BOOLEAN; readonly loc?: Location; readonly value: boolean; } export interface NullValueNode { - readonly kind: typeof Kind.NULL; + readonly kind: Kind.NULL; readonly loc?: Location; } export interface EnumValueNode { - readonly kind: typeof Kind.ENUM; + readonly kind: Kind.ENUM; readonly loc?: Location; readonly value: string; } export interface ListValueNode { - readonly kind: typeof Kind.LIST; + readonly kind: Kind.LIST; readonly loc?: Location; readonly values: ReadonlyArray; } export interface ConstListValueNode { - readonly kind: 'ListValue'; + readonly kind: Kind.LIST; readonly loc?: Location; readonly values: ReadonlyArray; } export interface ObjectValueNode { - readonly kind: typeof Kind.OBJECT; + readonly kind: Kind.OBJECT; readonly loc?: Location; readonly fields: ReadonlyArray; } export interface ConstObjectValueNode { - readonly kind: 'ObjectValue'; + readonly kind: Kind.OBJECT; readonly loc?: Location; readonly fields: ReadonlyArray; } export interface ObjectFieldNode { - readonly kind: typeof Kind.OBJECT_FIELD; + readonly kind: Kind.OBJECT_FIELD; readonly loc?: Location; readonly name: NameNode; readonly value: ValueNode; } export interface ConstObjectFieldNode { - readonly kind: 'ObjectField'; + readonly kind: Kind.OBJECT_FIELD; readonly loc?: Location; readonly name: NameNode; readonly value: ConstValueNode; @@ -546,14 +546,14 @@ export interface ConstObjectFieldNode { /** Directives */ export interface DirectiveNode { - readonly kind: typeof Kind.DIRECTIVE; + readonly kind: Kind.DIRECTIVE; readonly loc?: Location; readonly name: NameNode; readonly arguments?: ReadonlyArray; } export interface ConstDirectiveNode { - readonly kind: 'Directive'; + readonly kind: Kind.DIRECTIVE; readonly loc?: Location; readonly name: NameNode; readonly arguments?: ReadonlyArray; @@ -564,19 +564,19 @@ export interface ConstDirectiveNode { export type TypeNode = NamedTypeNode | ListTypeNode | NonNullTypeNode; export interface NamedTypeNode { - readonly kind: typeof Kind.NAMED_TYPE; + readonly kind: Kind.NAMED_TYPE; readonly loc?: Location; readonly name: NameNode; } export interface ListTypeNode { - readonly kind: typeof Kind.LIST_TYPE; + readonly kind: Kind.LIST_TYPE; readonly loc?: Location; readonly type: TypeNode; } export interface NonNullTypeNode { - readonly kind: typeof Kind.NON_NULL_TYPE; + readonly kind: Kind.NON_NULL_TYPE; readonly loc?: Location; readonly type: NamedTypeNode | ListTypeNode; } @@ -589,7 +589,7 @@ export type TypeSystemDefinitionNode = | DirectiveDefinitionNode; export interface SchemaDefinitionNode { - readonly kind: typeof Kind.SCHEMA_DEFINITION; + readonly kind: Kind.SCHEMA_DEFINITION; readonly loc?: Location; readonly description?: StringValueNode; readonly directives?: ReadonlyArray; @@ -597,7 +597,7 @@ export interface SchemaDefinitionNode { } export interface OperationTypeDefinitionNode { - readonly kind: typeof Kind.OPERATION_TYPE_DEFINITION; + readonly kind: Kind.OPERATION_TYPE_DEFINITION; readonly loc?: Location; readonly operation: OperationTypeNode; readonly type: NamedTypeNode; @@ -614,7 +614,7 @@ export type TypeDefinitionNode = | InputObjectTypeDefinitionNode; export interface ScalarTypeDefinitionNode { - readonly kind: typeof Kind.SCALAR_TYPE_DEFINITION; + readonly kind: Kind.SCALAR_TYPE_DEFINITION; readonly loc?: Location; readonly description?: StringValueNode; readonly name: NameNode; @@ -622,7 +622,7 @@ export interface ScalarTypeDefinitionNode { } export interface ObjectTypeDefinitionNode { - readonly kind: typeof Kind.OBJECT_TYPE_DEFINITION; + readonly kind: Kind.OBJECT_TYPE_DEFINITION; readonly loc?: Location; readonly description?: StringValueNode; readonly name: NameNode; @@ -632,7 +632,7 @@ export interface ObjectTypeDefinitionNode { } export interface FieldDefinitionNode { - readonly kind: typeof Kind.FIELD_DEFINITION; + readonly kind: Kind.FIELD_DEFINITION; readonly loc?: Location; readonly description?: StringValueNode; readonly name: NameNode; @@ -642,7 +642,7 @@ export interface FieldDefinitionNode { } export interface InputValueDefinitionNode { - readonly kind: typeof Kind.INPUT_VALUE_DEFINITION; + readonly kind: Kind.INPUT_VALUE_DEFINITION; readonly loc?: Location; readonly description?: StringValueNode; readonly name: NameNode; @@ -652,7 +652,7 @@ export interface InputValueDefinitionNode { } export interface InterfaceTypeDefinitionNode { - readonly kind: typeof Kind.INTERFACE_TYPE_DEFINITION; + readonly kind: Kind.INTERFACE_TYPE_DEFINITION; readonly loc?: Location; readonly description?: StringValueNode; readonly name: NameNode; @@ -662,7 +662,7 @@ export interface InterfaceTypeDefinitionNode { } export interface UnionTypeDefinitionNode { - readonly kind: typeof Kind.UNION_TYPE_DEFINITION; + readonly kind: Kind.UNION_TYPE_DEFINITION; readonly loc?: Location; readonly description?: StringValueNode; readonly name: NameNode; @@ -671,7 +671,7 @@ export interface UnionTypeDefinitionNode { } export interface EnumTypeDefinitionNode { - readonly kind: typeof Kind.ENUM_TYPE_DEFINITION; + readonly kind: Kind.ENUM_TYPE_DEFINITION; readonly loc?: Location; readonly description?: StringValueNode; readonly name: NameNode; @@ -680,7 +680,7 @@ export interface EnumTypeDefinitionNode { } export interface EnumValueDefinitionNode { - readonly kind: typeof Kind.ENUM_VALUE_DEFINITION; + readonly kind: Kind.ENUM_VALUE_DEFINITION; readonly loc?: Location; readonly description?: StringValueNode; readonly name: NameNode; @@ -688,7 +688,7 @@ export interface EnumValueDefinitionNode { } export interface InputObjectTypeDefinitionNode { - readonly kind: typeof Kind.INPUT_OBJECT_TYPE_DEFINITION; + readonly kind: Kind.INPUT_OBJECT_TYPE_DEFINITION; readonly loc?: Location; readonly description?: StringValueNode; readonly name: NameNode; @@ -699,7 +699,7 @@ export interface InputObjectTypeDefinitionNode { /** Directive Definitions */ export interface DirectiveDefinitionNode { - readonly kind: typeof Kind.DIRECTIVE_DEFINITION; + readonly kind: Kind.DIRECTIVE_DEFINITION; readonly loc?: Location; readonly description?: StringValueNode; readonly name: NameNode; @@ -713,7 +713,7 @@ export interface DirectiveDefinitionNode { export type TypeSystemExtensionNode = SchemaExtensionNode | TypeExtensionNode; export interface SchemaExtensionNode { - readonly kind: typeof Kind.SCHEMA_EXTENSION; + readonly kind: Kind.SCHEMA_EXTENSION; readonly loc?: Location; readonly directives?: ReadonlyArray; readonly operationTypes?: ReadonlyArray; @@ -730,14 +730,14 @@ export type TypeExtensionNode = | InputObjectTypeExtensionNode; export interface ScalarTypeExtensionNode { - readonly kind: typeof Kind.SCALAR_TYPE_EXTENSION; + readonly kind: Kind.SCALAR_TYPE_EXTENSION; readonly loc?: Location; readonly name: NameNode; readonly directives?: ReadonlyArray; } export interface ObjectTypeExtensionNode { - readonly kind: typeof Kind.OBJECT_TYPE_EXTENSION; + readonly kind: Kind.OBJECT_TYPE_EXTENSION; readonly loc?: Location; readonly name: NameNode; readonly interfaces?: ReadonlyArray; @@ -746,7 +746,7 @@ export interface ObjectTypeExtensionNode { } export interface InterfaceTypeExtensionNode { - readonly kind: typeof Kind.INTERFACE_TYPE_EXTENSION; + readonly kind: Kind.INTERFACE_TYPE_EXTENSION; readonly loc?: Location; readonly name: NameNode; readonly interfaces?: ReadonlyArray; @@ -755,7 +755,7 @@ export interface InterfaceTypeExtensionNode { } export interface UnionTypeExtensionNode { - readonly kind: typeof Kind.UNION_TYPE_EXTENSION; + readonly kind: Kind.UNION_TYPE_EXTENSION; readonly loc?: Location; readonly name: NameNode; readonly directives?: ReadonlyArray; @@ -763,7 +763,7 @@ export interface UnionTypeExtensionNode { } export interface EnumTypeExtensionNode { - readonly kind: typeof Kind.ENUM_TYPE_EXTENSION; + readonly kind: Kind.ENUM_TYPE_EXTENSION; readonly loc?: Location; readonly name: NameNode; readonly directives?: ReadonlyArray; @@ -771,7 +771,7 @@ export interface EnumTypeExtensionNode { } export interface InputObjectTypeExtensionNode { - readonly kind: typeof Kind.INPUT_OBJECT_TYPE_EXTENSION; + readonly kind: Kind.INPUT_OBJECT_TYPE_EXTENSION; readonly loc?: Location; readonly name: NameNode; readonly directives?: ReadonlyArray; diff --git a/src/language/directiveLocation.ts b/src/language/directiveLocation.ts index 702b459102..e98ddf6d75 100644 --- a/src/language/directiveLocation.ts +++ b/src/language/directiveLocation.ts @@ -1,32 +1,33 @@ /** * The set of allowed directive location values. */ -export const DirectiveLocation = Object.freeze({ +export enum 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', + MUTATION = 'MUTATION', + SUBSCRIPTION = 'SUBSCRIPTION', + FIELD = 'FIELD', + FRAGMENT_DEFINITION = 'FRAGMENT_DEFINITION', + FRAGMENT_SPREAD = 'FRAGMENT_SPREAD', + INLINE_FRAGMENT = 'INLINE_FRAGMENT', + VARIABLE_DEFINITION = 'VARIABLE_DEFINITION', /** 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', -} as const); + 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', +} /** * The enum type representing the directive location values. + * + * @deprecated Please use `DirectiveLocation`. Will be remove in v17. */ -export type DirectiveLocationEnum = - typeof DirectiveLocation[keyof typeof DirectiveLocation]; +export type DirectiveLocationEnum = typeof DirectiveLocation; diff --git a/src/language/kinds.ts b/src/language/kinds.ts index b5c0058827..39b2a8e675 100644 --- a/src/language/kinds.ts +++ b/src/language/kinds.ts @@ -1,74 +1,76 @@ /** * The set of allowed kind values for AST nodes. */ -export const Kind = Object.freeze({ +export enum Kind { /** Name */ - NAME: 'Name', + NAME = 'Name', /** Document */ - DOCUMENT: 'Document', - OPERATION_DEFINITION: 'OperationDefinition', - VARIABLE_DEFINITION: 'VariableDefinition', - SELECTION_SET: 'SelectionSet', - FIELD: 'Field', - ARGUMENT: 'Argument', + DOCUMENT = 'Document', + OPERATION_DEFINITION = 'OperationDefinition', + VARIABLE_DEFINITION = 'VariableDefinition', + SELECTION_SET = 'SelectionSet', + FIELD = 'Field', + ARGUMENT = 'Argument', /** Fragments */ - FRAGMENT_SPREAD: 'FragmentSpread', - INLINE_FRAGMENT: 'InlineFragment', - FRAGMENT_DEFINITION: 'FragmentDefinition', + FRAGMENT_SPREAD = 'FragmentSpread', + INLINE_FRAGMENT = 'InlineFragment', + FRAGMENT_DEFINITION = 'FragmentDefinition', /** Values */ - VARIABLE: 'Variable', - INT: 'IntValue', - FLOAT: 'FloatValue', - STRING: 'StringValue', - BOOLEAN: 'BooleanValue', - NULL: 'NullValue', - ENUM: 'EnumValue', - LIST: 'ListValue', - OBJECT: 'ObjectValue', - OBJECT_FIELD: 'ObjectField', + VARIABLE = 'Variable', + INT = 'IntValue', + FLOAT = 'FloatValue', + STRING = 'StringValue', + BOOLEAN = 'BooleanValue', + NULL = 'NullValue', + ENUM = 'EnumValue', + LIST = 'ListValue', + OBJECT = 'ObjectValue', + OBJECT_FIELD = 'ObjectField', /** Directives */ - DIRECTIVE: 'Directive', + DIRECTIVE = 'Directive', /** Types */ - NAMED_TYPE: 'NamedType', - LIST_TYPE: 'ListType', - NON_NULL_TYPE: 'NonNullType', + NAMED_TYPE = 'NamedType', + LIST_TYPE = 'ListType', + NON_NULL_TYPE = 'NonNullType', /** Type System Definitions */ - SCHEMA_DEFINITION: 'SchemaDefinition', - OPERATION_TYPE_DEFINITION: 'OperationTypeDefinition', + SCHEMA_DEFINITION = 'SchemaDefinition', + OPERATION_TYPE_DEFINITION = 'OperationTypeDefinition', /** 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', + 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', /** Directive Definitions */ - DIRECTIVE_DEFINITION: 'DirectiveDefinition', + DIRECTIVE_DEFINITION = 'DirectiveDefinition', /** Type System Extensions */ - SCHEMA_EXTENSION: 'SchemaExtension', + SCHEMA_EXTENSION = 'SchemaExtension', /** 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', -} as const); + 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', +} /** * The enum type representing the possible kind values of AST nodes. + * + * @deprecated Please use `Kind`. Will be remove in v17. */ -export type KindEnum = typeof Kind[keyof typeof Kind]; +export type KindEnum = typeof Kind; diff --git a/src/language/lexer.ts b/src/language/lexer.ts index 1f201d0d46..83ef54523a 100644 --- a/src/language/lexer.ts +++ b/src/language/lexer.ts @@ -1,7 +1,6 @@ import { syntaxError } from '../error/syntaxError'; import type { Source } from './source'; -import type { TokenKindEnum } from './tokenKind'; import { Token } from './ast'; import { TokenKind } from './tokenKind'; import { dedentBlockStringValue } from './blockString'; @@ -89,7 +88,7 @@ export class Lexer { /** * @internal */ -export function isPunctuatorTokenKind(kind: TokenKindEnum): boolean { +export function isPunctuatorTokenKind(kind: TokenKind): boolean { return ( kind === TokenKind.BANG || kind === TokenKind.DOLLAR || @@ -187,7 +186,7 @@ function printCodePointAt(lexer: Lexer, location: number): string { */ function createToken( lexer: Lexer, - kind: TokenKindEnum, + kind: TokenKind, start: number, end: number, value?: string, diff --git a/src/language/parser.ts b/src/language/parser.ts index 4284ae61e6..1b0bc75f92 100644 --- a/src/language/parser.ts +++ b/src/language/parser.ts @@ -3,7 +3,6 @@ import type { Maybe } from '../jsutils/Maybe'; import type { GraphQLError } from '../error/GraphQLError'; import { syntaxError } from '../error/syntaxError'; -import type { TokenKindEnum } from './tokenKind'; import type { Token, NameNode, @@ -1400,7 +1399,7 @@ export class Parser { /** * Determines if the next token is of a given kind */ - peek(kind: TokenKindEnum): boolean { + peek(kind: TokenKind): boolean { return this._lexer.token.kind === kind; } @@ -1408,7 +1407,7 @@ export class Parser { * If the next token is of the given kind, return that token after advancing the lexer. * Otherwise, do not change the parser state and throw an error. */ - expectToken(kind: TokenKindEnum): Token { + expectToken(kind: TokenKind): Token { const token = this._lexer.token; if (token.kind === kind) { this._lexer.advance(); @@ -1426,7 +1425,7 @@ export class Parser { * If the next token is of the given kind, return "true" after advancing the lexer. * Otherwise, do not change the parser state and return "false". */ - expectOptionalToken(kind: TokenKindEnum): boolean { + expectOptionalToken(kind: TokenKind): boolean { const token = this._lexer.token; if (token.kind === kind) { this._lexer.advance(); @@ -1483,9 +1482,9 @@ export class Parser { * Advances the parser to the next lex token after the closing token. */ any( - openKind: TokenKindEnum, + openKind: TokenKind, parseFn: () => T, - closeKind: TokenKindEnum, + closeKind: TokenKind, ): Array { this.expectToken(openKind); const nodes = []; @@ -1502,9 +1501,9 @@ export class Parser { * Advances the parser to the next lex token after the closing token. */ optionalMany( - openKind: TokenKindEnum, + openKind: TokenKind, parseFn: () => T, - closeKind: TokenKindEnum, + closeKind: TokenKind, ): Array { if (this.expectOptionalToken(openKind)) { const nodes = []; @@ -1522,9 +1521,9 @@ export class Parser { * Advances the parser to the next lex token after the closing token. */ many( - openKind: TokenKindEnum, + openKind: TokenKind, parseFn: () => T, - closeKind: TokenKindEnum, + closeKind: TokenKind, ): Array { this.expectToken(openKind); const nodes = []; @@ -1539,7 +1538,7 @@ export class Parser { * This list may begin with a lex token of delimiterKind followed by items separated by lex tokens of tokenKind. * Advances the parser to the next lex token after last item in the list. */ - delimitedMany(delimiterKind: TokenKindEnum, parseFn: () => T): Array { + delimitedMany(delimiterKind: TokenKind, parseFn: () => T): Array { this.expectOptionalToken(delimiterKind); const nodes = []; @@ -1561,6 +1560,6 @@ function getTokenDesc(token: Token): string { /** * A helper function to describe a token kind as a string for debugging. */ -function getTokenKindDesc(kind: TokenKindEnum): string { +function getTokenKindDesc(kind: TokenKind): string { return isPunctuatorTokenKind(kind) ? `"${kind}"` : kind; } diff --git a/src/language/tokenKind.ts b/src/language/tokenKind.ts index 10e1e66a80..4878d697b0 100644 --- a/src/language/tokenKind.ts +++ b/src/language/tokenKind.ts @@ -2,32 +2,34 @@ * An exported enum describing the different kinds of tokens that the * lexer emits. */ -export const TokenKind = Object.freeze({ - 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', -} as const); +export 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', +} /** * The enum type representing the token kinds values. + * + * @deprecated Please use `TokenKind`. Will be remove in v17. */ -export type TokenKindEnum = typeof TokenKind[keyof typeof TokenKind]; +export type TokenKindEnum = typeof TokenKind; diff --git a/src/type/__tests__/directive-test.ts b/src/type/__tests__/directive-test.ts index 9496d57ddd..b614474acf 100644 --- a/src/type/__tests__/directive-test.ts +++ b/src/type/__tests__/directive-test.ts @@ -1,6 +1,8 @@ import { expect } from 'chai'; import { describe, it } from 'mocha'; +import { DirectiveLocation } from '../../language/directiveLocation'; + import { GraphQLDirective } from '../directives'; import { GraphQLString, GraphQLInt } from '../scalars'; @@ -8,7 +10,7 @@ describe('Type System: Directive', () => { it('defines a directive with no args', () => { const directive = new GraphQLDirective({ name: 'Foo', - locations: ['QUERY'], + locations: [DirectiveLocation.QUERY], }); expect(directive).to.deep.include({ @@ -26,7 +28,7 @@ describe('Type System: Directive', () => { foo: { type: GraphQLString }, bar: { type: GraphQLInt }, }, - locations: ['QUERY'], + locations: [DirectiveLocation.QUERY], }); expect(directive).to.deep.include({ @@ -60,7 +62,7 @@ describe('Type System: Directive', () => { const directive = new GraphQLDirective({ name: 'Foo', isRepeatable: true, - locations: ['QUERY'], + locations: [DirectiveLocation.QUERY], }); expect(directive).to.deep.include({ @@ -74,7 +76,7 @@ describe('Type System: Directive', () => { it('can be stringified, JSON.stringified and Object.toStringified', () => { const directive = new GraphQLDirective({ name: 'Foo', - locations: ['QUERY'], + locations: [DirectiveLocation.QUERY], }); expect(String(directive)).to.equal('@Foo'); @@ -86,7 +88,11 @@ describe('Type System: Directive', () => { it('rejects a directive with invalid name', () => { expect( - () => new GraphQLDirective({ name: 'bad-name', locations: ['QUERY'] }), + () => + new GraphQLDirective({ + name: 'bad-name', + locations: [DirectiveLocation.QUERY], + }), ).to.throw('Names must only contain [_a-zA-Z0-9] but "bad-name" does not.'); }); @@ -95,7 +101,7 @@ describe('Type System: Directive', () => { () => new GraphQLDirective({ name: 'Foo', - locations: ['QUERY'], + locations: [DirectiveLocation.QUERY], // @ts-expect-error args: [], }), @@ -107,7 +113,7 @@ describe('Type System: Directive', () => { () => new GraphQLDirective({ name: 'Foo', - locations: ['QUERY'], + locations: [DirectiveLocation.QUERY], args: { 'bad-name': { type: GraphQLString }, }, diff --git a/src/type/__tests__/predicate-test.ts b/src/type/__tests__/predicate-test.ts index 0323be4365..6afd9b45f4 100644 --- a/src/type/__tests__/predicate-test.ts +++ b/src/type/__tests__/predicate-test.ts @@ -1,6 +1,8 @@ import { expect } from 'chai'; import { describe, it } from 'mocha'; +import { DirectiveLocation } from '../../language/directiveLocation'; + import type { GraphQLArgument, GraphQLInputField, @@ -86,7 +88,7 @@ const InputObjectType = new GraphQLInputObjectType({ const ScalarType = new GraphQLScalarType({ name: 'Scalar' }); const Directive = new GraphQLDirective({ name: 'Directive', - locations: ['QUERY'], + locations: [DirectiveLocation.QUERY], }); describe('Type predicates', () => { diff --git a/src/type/__tests__/schema-test.ts b/src/type/__tests__/schema-test.ts index 6b1c4c4061..ab2ef11236 100644 --- a/src/type/__tests__/schema-test.ts +++ b/src/type/__tests__/schema-test.ts @@ -3,6 +3,8 @@ import { describe, it } from 'mocha'; import { dedent } from '../../__testUtils__/dedent'; +import { DirectiveLocation } from '../../language/directiveLocation'; + import { printSchema } from '../../utilities/printSchema'; import { GraphQLSchema } from '../schema'; @@ -240,7 +242,7 @@ describe('Type System: Schema', () => { it('includes input types only used in directives', () => { const directive = new GraphQLDirective({ name: 'dir', - locations: ['OBJECT'], + locations: [DirectiveLocation.OBJECT], args: { arg: { type: new GraphQLInputObjectType({ name: 'Foo', fields: {} }), diff --git a/src/type/__tests__/validation-test.ts b/src/type/__tests__/validation-test.ts index 0febc5a04e..0dd9137ae4 100644 --- a/src/type/__tests__/validation-test.ts +++ b/src/type/__tests__/validation-test.ts @@ -7,6 +7,7 @@ import { expectJSON } from '../../__testUtils__/expectJSON'; import { inspect } from '../../jsutils/inspect'; import { parse } from '../../language/parser'; +import { DirectiveLocation } from '../../language/directiveLocation'; import { extendSchema } from '../../utilities/extendSchema'; import { buildSchema } from '../../utilities/buildASTSchema'; @@ -1448,7 +1449,7 @@ describe('Type System: Arguments must have input types', () => { args: { badArg: argConfig, }, - locations: ['QUERY'], + locations: [DirectiveLocation.QUERY], }), ], }); diff --git a/src/type/directives.ts b/src/type/directives.ts index 5375746d0c..fd4a639cc7 100644 --- a/src/type/directives.ts +++ b/src/type/directives.ts @@ -6,7 +6,6 @@ import { isObjectLike } from '../jsutils/isObjectLike'; import type { Maybe } from '../jsutils/Maybe'; import type { DirectiveDefinitionNode } from '../language/ast'; -import type { DirectiveLocationEnum } from '../language/directiveLocation'; import { DirectiveLocation } from '../language/directiveLocation'; import type { @@ -57,7 +56,7 @@ export interface GraphQLDirectiveExtensions { export class GraphQLDirective { name: string; description: Maybe; - locations: ReadonlyArray; + locations: ReadonlyArray; args: ReadonlyArray; isRepeatable: boolean; extensions: Readonly; @@ -113,7 +112,7 @@ export class GraphQLDirective { export interface GraphQLDirectiveConfig { name: string; description?: Maybe; - locations: ReadonlyArray; + locations: ReadonlyArray; args?: Maybe; isRepeatable?: Maybe; extensions?: Maybe>; diff --git a/src/type/introspection.ts b/src/type/introspection.ts index 2e50bb5f0d..c6a54b1a22 100644 --- a/src/type/introspection.ts +++ b/src/type/introspection.ts @@ -434,16 +434,16 @@ export const __EnumValue: GraphQLObjectType = new GraphQLObjectType({ } as GraphQLFieldConfigMap), }); -export const TypeKind = Object.freeze({ - SCALAR: 'SCALAR', - OBJECT: 'OBJECT', - INTERFACE: 'INTERFACE', - UNION: 'UNION', - ENUM: 'ENUM', - INPUT_OBJECT: 'INPUT_OBJECT', - LIST: 'LIST', - NON_NULL: 'NON_NULL', -} as const); +export enum TypeKind { + SCALAR = 'SCALAR', + OBJECT = 'OBJECT', + INTERFACE = 'INTERFACE', + UNION = 'UNION', + ENUM = 'ENUM', + INPUT_OBJECT = 'INPUT_OBJECT', + LIST = 'LIST', + NON_NULL = 'NON_NULL', +} export const __TypeKind: GraphQLEnumType = new GraphQLEnumType({ name: '__TypeKind', diff --git a/src/utilities/astFromValue.ts b/src/utilities/astFromValue.ts index 6ba9cff68e..f38d099061 100644 --- a/src/utilities/astFromValue.ts +++ b/src/utilities/astFromValue.ts @@ -4,7 +4,7 @@ import { isObjectLike } from '../jsutils/isObjectLike'; import { isIterableObject } from '../jsutils/isIterableObject'; import type { Maybe } from '../jsutils/Maybe'; -import type { ValueNode } from '../language/ast'; +import type { ValueNode, ObjectFieldNode } from '../language/ast'; import { Kind } from '../language/kinds'; import type { GraphQLInputType } from '../type/definition'; @@ -83,7 +83,7 @@ export function astFromValue( if (!isObjectLike(value)) { return null; } - const fieldNodes = []; + const fieldNodes: Array = []; for (const field of Object.values(type.getFields())) { const fieldValue = astFromValue(value[field.name], field.type); if (fieldValue) { diff --git a/src/utilities/concatAST.ts b/src/utilities/concatAST.ts index 07cf7367b0..4437510079 100644 --- a/src/utilities/concatAST.ts +++ b/src/utilities/concatAST.ts @@ -1,4 +1,5 @@ import type { DocumentNode, DefinitionNode } from '../language/ast'; +import { Kind } from '../language/kinds'; /** * Provided a collection of ASTs, presumably each from different files, @@ -12,5 +13,5 @@ export function concatAST( for (const doc of documents) { definitions.push(...doc.definitions); } - return { kind: 'Document', definitions }; + return { kind: Kind.DOCUMENT, definitions }; } diff --git a/src/utilities/findBreakingChanges.ts b/src/utilities/findBreakingChanges.ts index 7aa0760481..833fdd04eb 100644 --- a/src/utilities/findBreakingChanges.ts +++ b/src/utilities/findBreakingChanges.ts @@ -35,41 +35,41 @@ import { import { astFromValue } from './astFromValue'; -export const BreakingChangeType = Object.freeze({ - 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', -} as const); - -export const DangerousChangeType = Object.freeze({ - 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', -} as const); +export 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 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 interface BreakingChange { - type: keyof typeof BreakingChangeType; + type: BreakingChangeType; description: string; } export interface DangerousChange { - type: keyof typeof DangerousChangeType; + type: DangerousChangeType; description: string; } diff --git a/src/utilities/getIntrospectionQuery.ts b/src/utilities/getIntrospectionQuery.ts index 15caee5ff4..bb9be0680a 100644 --- a/src/utilities/getIntrospectionQuery.ts +++ b/src/utilities/getIntrospectionQuery.ts @@ -1,5 +1,5 @@ import type { Maybe } from '../jsutils/Maybe'; -import type { DirectiveLocationEnum } from '../language/directiveLocation'; +import type { DirectiveLocation } from '../language/directiveLocation'; export interface IntrospectionOptions { /** @@ -321,6 +321,6 @@ export interface IntrospectionDirective { readonly name: string; readonly description?: Maybe; readonly isRepeatable?: boolean; - readonly locations: ReadonlyArray; + readonly locations: ReadonlyArray; readonly args: ReadonlyArray; } diff --git a/src/utilities/printSchema.ts b/src/utilities/printSchema.ts index b9b6565587..16b93e7b1a 100644 --- a/src/utilities/printSchema.ts +++ b/src/utilities/printSchema.ts @@ -2,6 +2,7 @@ import { inspect } from '../jsutils/inspect'; import { invariant } from '../jsutils/invariant'; import type { Maybe } from '../jsutils/Maybe'; +import { Kind } from '../language/kinds'; import { print } from '../language/printer'; import { printBlockString } from '../language/blockString'; @@ -286,7 +287,7 @@ function printDeprecated(reason: Maybe): string { return ''; } if (reason !== DEFAULT_DEPRECATION_REASON) { - const astValue = print({ kind: 'StringValue', value: reason }); + const astValue = print({ kind: Kind.STRING, value: reason }); return ` @deprecated(reason: ${astValue})`; } return ' @deprecated'; @@ -296,7 +297,10 @@ function printSpecifiedByURL(scalar: GraphQLScalarType): string { if (scalar.specifiedByURL == null) { return ''; } - const astValue = print({ kind: 'StringValue', value: scalar.specifiedByURL }); + const astValue = print({ + kind: Kind.STRING, + value: scalar.specifiedByURL, + }); return ` @specifiedBy(url: ${astValue})`; } diff --git a/src/validation/rules/KnownDirectivesRule.ts b/src/validation/rules/KnownDirectivesRule.ts index ab1c0915f0..53c98db3a8 100644 --- a/src/validation/rules/KnownDirectivesRule.ts +++ b/src/validation/rules/KnownDirectivesRule.ts @@ -5,7 +5,6 @@ import { GraphQLError } from '../../error/GraphQLError'; import type { ASTVisitor } from '../../language/visitor'; import type { ASTNode } from '../../language/ast'; -import type { DirectiveLocationEnum } from '../../language/directiveLocation'; import { Kind } from '../../language/kinds'; import { OperationTypeNode } from '../../language/ast'; import { DirectiveLocation } from '../../language/directiveLocation'; @@ -72,7 +71,7 @@ export function KnownDirectivesRule( function getDirectiveLocationForASTPath( ancestors: ReadonlyArray>, -): DirectiveLocationEnum | undefined { +): DirectiveLocation | undefined { const appliedTo = ancestors[ancestors.length - 1]; invariant('kind' in appliedTo); @@ -126,7 +125,7 @@ function getDirectiveLocationForASTPath( function getDirectiveLocationForOperation( operation: OperationTypeNode, -): DirectiveLocationEnum { +): DirectiveLocation { switch (operation) { case OperationTypeNode.QUERY: return DirectiveLocation.QUERY; diff --git a/src/validation/rules/PossibleTypeExtensionsRule.ts b/src/validation/rules/PossibleTypeExtensionsRule.ts index 11c55eff84..27016fffd8 100644 --- a/src/validation/rules/PossibleTypeExtensionsRule.ts +++ b/src/validation/rules/PossibleTypeExtensionsRule.ts @@ -6,7 +6,6 @@ import { suggestionList } from '../../jsutils/suggestionList'; import { GraphQLError } from '../../error/GraphQLError'; -import type { KindEnum } from '../../language/kinds'; import type { ASTVisitor } from '../../language/visitor'; import type { DefinitionNode, TypeExtensionNode } from '../../language/ast'; import { Kind } from '../../language/kinds'; @@ -55,7 +54,7 @@ export function PossibleTypeExtensionsRule( const defNode = definedTypes[typeName]; const existingType = schema?.getType(typeName); - let expectedKind: KindEnum | undefined; + let expectedKind: Kind | undefined; if (defNode) { expectedKind = defKindToExtKind[defNode.kind]; } else if (existingType) { @@ -90,7 +89,7 @@ export function PossibleTypeExtensionsRule( } } -const defKindToExtKind: ObjMap = { +const defKindToExtKind: ObjMap = { [Kind.SCALAR_TYPE_DEFINITION]: Kind.SCALAR_TYPE_EXTENSION, [Kind.OBJECT_TYPE_DEFINITION]: Kind.OBJECT_TYPE_EXTENSION, [Kind.INTERFACE_TYPE_DEFINITION]: Kind.INTERFACE_TYPE_EXTENSION, @@ -99,7 +98,7 @@ const defKindToExtKind: ObjMap = { [Kind.INPUT_OBJECT_TYPE_DEFINITION]: Kind.INPUT_OBJECT_TYPE_EXTENSION, }; -function typeToExtKind(type: GraphQLNamedType): KindEnum { +function typeToExtKind(type: GraphQLNamedType): Kind { if (isScalarType(type)) { return Kind.SCALAR_TYPE_EXTENSION; } @@ -124,7 +123,7 @@ function typeToExtKind(type: GraphQLNamedType): KindEnum { invariant(false, 'Unexpected type: ' + inspect(type)); } -function extensionKindToTypeName(kind: KindEnum): string { +function extensionKindToTypeName(kind: Kind): string { switch (kind) { case Kind.SCALAR_TYPE_EXTENSION: return 'scalar';