From 9271b3282d0946bb31b0079f508057aa0f92852a Mon Sep 17 00:00:00 2001 From: Saihajpreet Singh Date: Sun, 16 May 2021 11:47:58 -0400 Subject: [PATCH] Fix TSC errors --- src/error/GraphQLError.ts | 8 +- src/error/__tests__/formatError-test.ts | 2 - src/error/locatedError.ts | 1 + src/execution/execute.ts | 5 +- src/jsutils/__tests__/identityFunc-test.ts | 1 + src/jsutils/__tests__/inspect-test.ts | 3 +- .../__tests__/isIterableObject-test.ts | 2 +- src/jsutils/inspect.ts | 2 + src/jsutils/isPromise.ts | 3 +- src/language/__tests__/printer-test.ts | 5 +- src/language/__tests__/schema-printer-test.ts | 2 +- src/language/__tests__/toJSONDeep.ts | 1 - src/language/__tests__/visitor-test.ts | 7 +- src/language/ast.ts | 3 +- src/language/parser.ts | 96 +++++++++++++++++-- src/language/printLocation.ts | 5 +- src/language/source.ts | 1 - .../__tests__/mapAsyncIterator-test.ts | 12 ++- src/subscription/__tests__/subscribe-test.ts | 14 ++- src/subscription/mapAsyncIterator.ts | 1 + src/subscription/subscribe.ts | 2 +- src/type/__tests__/definition-test.ts | 23 ++--- src/type/__tests__/introspection-test.ts | 4 +- src/type/__tests__/validation-test.ts | 5 - src/type/definition.ts | 18 ++-- src/type/directives.ts | 1 - src/type/introspection.ts | 4 + src/type/scalars.ts | 1 - src/type/schema.ts | 1 - src/type/validate.ts | 16 +++- .../__tests__/buildASTSchema-test.ts | 1 - .../__tests__/buildClientSchema-test.ts | 1 - .../__tests__/coerceInputValue-test.ts | 5 +- src/utilities/__tests__/extendSchema-test.ts | 1 - .../__tests__/getOperationRootType-test.ts | 8 +- src/utilities/extendSchema.ts | 5 +- src/utilities/introspectionFromSchema.ts | 3 +- src/utilities/lexicographicSortSchema.ts | 3 +- src/utilities/separateOperations.ts | 2 +- src/utilities/typeFromAST.ts | 4 + src/validation/ValidationContext.ts | 2 + src/validation/__tests__/validation-test.ts | 1 - src/validation/rules/KnownDirectivesRule.ts | 3 + src/validation/rules/KnownTypeNamesRule.ts | 1 + .../rules/ProvidedRequiredArgumentsRule.ts | 6 +- .../rules/UniqueDirectivesPerLocationRule.ts | 2 + 46 files changed, 199 insertions(+), 98 deletions(-) diff --git a/src/error/GraphQLError.ts b/src/error/GraphQLError.ts index 8f050294e5d..68ddeda7029 100644 --- a/src/error/GraphQLError.ts +++ b/src/error/GraphQLError.ts @@ -98,8 +98,10 @@ export class GraphQLError extends Error { _source = _nodes[0].loc?.source; } - let _positions = positions; - if (!_positions && _nodes) { + let _positions; + if (positions) { + _positions = positions; + } else if (_nodes) { _positions = []; for (const node of _nodes) { if (node.loc) { @@ -131,7 +133,6 @@ export class GraphQLError extends Error { } } - // @ts-expect-error FIXME Object.defineProperties(this, { name: { value: 'GraphQLError' }, message: { @@ -210,7 +211,6 @@ export class GraphQLError extends Error { } // FIXME: workaround to not break chai comparisons, should be remove in v16 - // @ts-expect-error Flow doesn't support computed properties yet get [Symbol.toStringTag](): string { return 'Object'; } diff --git a/src/error/__tests__/formatError-test.ts b/src/error/__tests__/formatError-test.ts index 49f79d05d68..d618f8d2d03 100644 --- a/src/error/__tests__/formatError-test.ts +++ b/src/error/__tests__/formatError-test.ts @@ -45,12 +45,10 @@ describe('formatError: default error formatter', () => { }); it('rejects null and undefined errors', () => { - // @ts-expect-error expect(() => formatError(undefined)).to.throw( 'Received null or undefined error.', ); - // @ts-expect-error expect(() => formatError(null)).to.throw( 'Received null or undefined error.', ); diff --git a/src/error/locatedError.ts b/src/error/locatedError.ts index c081f464e06..286408f792f 100644 --- a/src/error/locatedError.ts +++ b/src/error/locatedError.ts @@ -22,6 +22,7 @@ export function locatedError( : new Error('Unexpected error value: ' + inspect(rawOriginalError)); // Note: this uses a brand-check to support GraphQL errors originating from other contexts. + // @ts-expect-error FIXME: TS Conversion if (Array.isArray(originalError.path)) { // @ts-expect-error return originalError; diff --git a/src/execution/execute.ts b/src/execution/execute.ts index 2b66dfe6c5c..923d018d1ad 100644 --- a/src/execution/execute.ts +++ b/src/execution/execute.ts @@ -191,7 +191,9 @@ export function execute(args: ExecutionArgs): PromiseOrValue { // field and its descendants will be omitted, and sibling fields will still // be executed. An execution which encounters errors will still result in a // resolved Promise. + // @ts-expect-error FIXME: TS Conversion const data = executeOperation(exeContext, exeContext.operation, rootValue); + // @ts-expect-error FIXME: TS Conversion return buildResponse(exeContext, data); } @@ -313,7 +315,6 @@ export function buildExecutionContext( return coercedVariableValues.errors; } - // @ts-expect-error return { schema, fragments, @@ -1078,7 +1079,7 @@ function _collectSubfields( fieldNodes: ReadonlyArray, ): Map> { let subFieldNodes = new Map(); - const visitedFragmentNames = new Set(); + const visitedFragmentNames = new Set(); for (const node of fieldNodes) { if (node.selectionSet) { subFieldNodes = collectFields( diff --git a/src/jsutils/__tests__/identityFunc-test.ts b/src/jsutils/__tests__/identityFunc-test.ts index 82a6c914d87..3e4683b6655 100644 --- a/src/jsutils/__tests__/identityFunc-test.ts +++ b/src/jsutils/__tests__/identityFunc-test.ts @@ -5,6 +5,7 @@ import { identityFunc } from '../identityFunc'; describe('identityFunc', () => { it('returns the first argument it receives', () => { + // @ts-expect-error expect(identityFunc()).to.equal(undefined); expect(identityFunc(undefined)).to.equal(undefined); expect(identityFunc(null)).to.equal(null); diff --git a/src/jsutils/__tests__/inspect-test.ts b/src/jsutils/__tests__/inspect-test.ts index a59fe476967..a4f17177acf 100644 --- a/src/jsutils/__tests__/inspect-test.ts +++ b/src/jsutils/__tests__/inspect-test.ts @@ -124,7 +124,7 @@ describe('inspect', () => { }); it('detect circular objects', () => { - const obj = {}; + const obj: { [name: string]: unknown } = {}; obj.self = obj; obj.deepSelf = { self: obj }; @@ -165,7 +165,6 @@ describe('inspect', () => { expect(inspect([[new Foo()]])).to.equal('[[[Foo]]]'); - // @ts-expect-error Foo.prototype[Symbol.toStringTag] = 'Bar'; expect(inspect([[new Foo()]])).to.equal('[[[Bar]]]'); diff --git a/src/jsutils/__tests__/isIterableObject-test.ts b/src/jsutils/__tests__/isIterableObject-test.ts index 3338638de57..3997a69e09c 100644 --- a/src/jsutils/__tests__/isIterableObject-test.ts +++ b/src/jsutils/__tests__/isIterableObject-test.ts @@ -60,7 +60,7 @@ describe('isIterableObject', () => { }; expect(isIterableObject(invalidIterable)).to.equal(false); - const arrayLike = {}; + const arrayLike: { [key: string]: unknown } = {}; arrayLike[0] = 'Alpha'; arrayLike[1] = 'Bravo'; arrayLike[2] = 'Charlie'; diff --git a/src/jsutils/inspect.ts b/src/jsutils/inspect.ts index f204bbeaf56..4616edc316e 100644 --- a/src/jsutils/inspect.ts +++ b/src/jsutils/inspect.ts @@ -35,7 +35,9 @@ function formatObjectValue( const seenValues = [...previouslySeenValues, value]; + // @ts-expect-error FIXME: TS Conversion if (typeof value.toJSON === 'function') { + // @ts-expect-error FIXME: TS Conversion const jsonValue = (value.toJSON as () => unknown)(); // check for infinite recursion diff --git a/src/jsutils/isPromise.ts b/src/jsutils/isPromise.ts index 94e93e24ec1..69b0a9910e0 100644 --- a/src/jsutils/isPromise.ts +++ b/src/jsutils/isPromise.ts @@ -3,5 +3,6 @@ * otherwise returns false. */ export function isPromise(value: unknown): value is Promise { - return typeof value?.then === 'function'; + // eslint-disable-next-line @typescript-eslint/dot-notation + return typeof value?.['then'] === 'function'; } diff --git a/src/language/__tests__/printer-test.ts b/src/language/__tests__/printer-test.ts index bae12edd21d..cfa1e140523 100644 --- a/src/language/__tests__/printer-test.ts +++ b/src/language/__tests__/printer-test.ts @@ -9,7 +9,10 @@ import { print } from '../printer'; describe('Printer: Query document', () => { it('prints minimal ast', () => { - const ast = { kind: 'Field', name: { kind: 'Name', value: 'foo' } }; + const ast = { + kind: 'Field', + name: { 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 aa85ff2b5ae..9ad03393941 100644 --- a/src/language/__tests__/schema-printer-test.ts +++ b/src/language/__tests__/schema-printer-test.ts @@ -12,7 +12,7 @@ describe('Printer: SDL document', () => { const ast = { kind: 'ScalarTypeDefinition', name: { kind: 'Name', value: 'foo' }, - }; + } as const; expect(print(ast)).to.equal('scalar foo'); }); diff --git a/src/language/__tests__/toJSONDeep.ts b/src/language/__tests__/toJSONDeep.ts index 612ed406412..a82606252aa 100644 --- a/src/language/__tests__/toJSONDeep.ts +++ b/src/language/__tests__/toJSONDeep.ts @@ -11,7 +11,6 @@ export function toJSONDeep(value: unknown): unknown { } if (typeof value.toJSON === 'function') { - // @ts-expect-error return value.toJSON(); } diff --git a/src/language/__tests__/visitor-test.ts b/src/language/__tests__/visitor-test.ts index 80d9029c07f..0565af0f387 100644 --- a/src/language/__tests__/visitor-test.ts +++ b/src/language/__tests__/visitor-test.ts @@ -4,6 +4,7 @@ import { describe, it } from 'mocha'; import { kitchenSinkQuery } from '../../__testUtils__/kitchenSinkQuery'; import type { ASTNode } from '../ast'; +import { isNode } from '../ast'; import { Kind } from '../kinds'; import { parse } from '../parser'; import { visit, visitInParallel, BREAK } from '../visitor'; @@ -50,6 +51,7 @@ function checkVisitorFnArgs(ast: any, args: any, isEdited: boolean = false) { } function getValue(node: ASTNode) { + // @ts-expect-error FIXME return node.value != null ? node.value : undefined; } @@ -263,6 +265,7 @@ describe('Visitor', () => { if (node.kind === 'Field' && node.name.value === 'a') { return { kind: 'Field', + // @ts-expect-error FIXME selectionSet: [addedField].concat(node.selectionSet), }; } @@ -522,7 +525,7 @@ describe('Visitor', () => { 'enter', node.kind, key, - parent?.kind != null ? parent.kind : undefined, + isNode(parent) ? parent.kind : undefined, ]); checkVisitorFnArgs(ast, arguments); @@ -534,7 +537,7 @@ describe('Visitor', () => { 'leave', node.kind, key, - parent?.kind != null ? parent.kind : undefined, + isNode(parent) ? parent.kind : undefined, ]); expect(argsStack.pop()).to.deep.equal([...arguments]); diff --git a/src/language/ast.ts b/src/language/ast.ts index 104424be829..02c73703400 100644 --- a/src/language/ast.ts +++ b/src/language/ast.ts @@ -125,7 +125,8 @@ export class Token { * @internal */ export function isNode(maybeNode: unknown): maybeNode is ASTNode { - return maybeNode != null && typeof maybeNode.kind === 'string'; + // eslint-disable-next-line @typescript-eslint/dot-notation + return typeof maybeNode?.['kind'] === 'string'; } /** diff --git a/src/language/parser.ts b/src/language/parser.ts index 7452edfa680..4d5e33217c4 100644 --- a/src/language/parser.ts +++ b/src/language/parser.ts @@ -187,9 +187,10 @@ export class Parser { */ parseName(): NameNode { const token = this.expectToken(TokenKind.NAME); + // @ts-expect-error FIXME return this.node(token, { - kind: Kind.NAME, // @ts-expect-error FIXME + kind: Kind.NAME, value: token.value, }); } @@ -200,7 +201,9 @@ export class Parser { * Document : Definition+ */ parseDocument(): DocumentNode { + // @ts-expect-error FIXME return this.node(this._lexer.token, { + // @ts-expect-error FIXME kind: Kind.DOCUMENT, definitions: this.many( TokenKind.SOF, @@ -260,7 +263,9 @@ export class Parser { parseOperationDefinition(): OperationDefinitionNode { const start = this._lexer.token; if (this.peek(TokenKind.BRACE_L)) { + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.OPERATION_DEFINITION, operation: 'query', name: undefined, @@ -274,7 +279,9 @@ export class Parser { if (this.peek(TokenKind.NAME)) { name = this.parseName(); } + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.OPERATION_DEFINITION, operation, name, @@ -316,7 +323,9 @@ export class Parser { * VariableDefinition : Variable : Type DefaultValue? Directives[Const]? */ parseVariableDefinition(): VariableDefinitionNode { + // @ts-expect-error FIXME return this.node(this._lexer.token, { + // @ts-expect-error FIXME kind: Kind.VARIABLE_DEFINITION, variable: this.parseVariable(), type: (this.expectToken(TokenKind.COLON), this.parseTypeReference()), @@ -333,7 +342,9 @@ export class Parser { parseVariable(): VariableNode { const start = this._lexer.token; this.expectToken(TokenKind.DOLLAR); + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.VARIABLE, name: this.parseName(), }); @@ -343,7 +354,9 @@ export class Parser { * SelectionSet : { Selection+ } */ parseSelectionSet(): SelectionSetNode { + // @ts-expect-error FIXME return this.node(this._lexer.token, { + // @ts-expect-error FIXME kind: Kind.SELECTION_SET, selections: this.many( TokenKind.BRACE_L, @@ -383,7 +396,9 @@ export class Parser { name = nameOrAlias; } + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.FIELD, alias, name, @@ -415,7 +430,9 @@ export class Parser { const name = this.parseName(); this.expectToken(TokenKind.COLON); + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.ARGUMENT, name, value: this.parseValueLiteral(isConst), @@ -423,7 +440,6 @@ export class Parser { } parseConstArgument(): ConstArgumentNode { - // @ts-expect-error FIXME during TS conversion return this.parseArgument(true); } @@ -442,13 +458,17 @@ export class Parser { const hasTypeCondition = this.expectOptionalKeyword('on'); if (!hasTypeCondition && this.peek(TokenKind.NAME)) { + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.FRAGMENT_SPREAD, name: this.parseFragmentName(), directives: this.parseDirectives(false), }); } + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.INLINE_FRAGMENT, typeCondition: hasTypeCondition ? this.parseNamedType() : undefined, directives: this.parseDirectives(false), @@ -469,7 +489,9 @@ export class Parser { // the grammar of FragmentDefinition: // - fragment FragmentName VariableDefinitions? on TypeCondition Directives? SelectionSet if (this._options?.allowLegacyFragmentVariables === true) { + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.FRAGMENT_DEFINITION, name: this.parseFragmentName(), variableDefinitions: this.parseVariableDefinitions(), @@ -478,7 +500,9 @@ export class Parser { selectionSet: this.parseSelectionSet(), }); } + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.FRAGMENT_DEFINITION, name: this.parseFragmentName(), typeCondition: (this.expectKeyword('on'), this.parseNamedType()), @@ -528,16 +552,18 @@ export class Parser { return this.parseObject(isConst); case TokenKind.INT: this._lexer.advance(); + // @ts-expect-error FIXME return this.node(token, { - kind: Kind.INT, // @ts-expect-error FIXME + kind: Kind.INT, value: token.value, }); case TokenKind.FLOAT: this._lexer.advance(); + // @ts-expect-error FIXME return this.node(token, { - kind: Kind.FLOAT, // @ts-expect-error FIXME + kind: Kind.FLOAT, value: token.value, }); case TokenKind.STRING: @@ -547,15 +573,19 @@ export class Parser { this._lexer.advance(); switch (token.value) { case 'true': + // @ts-expect-error FIXME return this.node(token, { kind: Kind.BOOLEAN, value: true }); case 'false': + // @ts-expect-error FIXME return this.node(token, { kind: Kind.BOOLEAN, value: false }); case 'null': + // @ts-expect-error FIXME return this.node(token, { kind: Kind.NULL }); default: + // @ts-expect-error FIXME return this.node(token, { - kind: Kind.ENUM, // @ts-expect-error FIXME + kind: Kind.ENUM, value: token.value, }); } @@ -579,16 +609,16 @@ export class Parser { } parseConstValueLiteral(): ConstValueNode { - // @ts-expect-error FIXME during TS conversion return this.parseValueLiteral(true); } parseStringLiteral(): StringValueNode { const token = this._lexer.token; this._lexer.advance(); + // @ts-expect-error FIXME return this.node(token, { - kind: Kind.STRING, // @ts-expect-error FIXME + kind: Kind.STRING, value: token.value, block: token.kind === TokenKind.BLOCK_STRING, }); @@ -603,7 +633,9 @@ export class Parser { parseList(isConst: boolean): ListValueNode; parseList(isConst: boolean): ListValueNode { const item = () => this.parseValueLiteral(isConst); + // @ts-expect-error FIXME return this.node(this._lexer.token, { + // @ts-expect-error FIXME kind: Kind.LIST, values: this.any(TokenKind.BRACKET_L, item, TokenKind.BRACKET_R), }); @@ -618,7 +650,9 @@ export class Parser { parseObject(isConst: boolean): ObjectValueNode; parseObject(isConst: boolean): ObjectValueNode { const item = () => this.parseObjectField(isConst); + // @ts-expect-error FIXME return this.node(this._lexer.token, { + // @ts-expect-error FIXME kind: Kind.OBJECT, fields: this.any(TokenKind.BRACE_L, item, TokenKind.BRACE_R), }); @@ -634,7 +668,9 @@ export class Parser { const name = this.parseName(); this.expectToken(TokenKind.COLON); + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.OBJECT_FIELD, name, value: this.parseValueLiteral(isConst), @@ -657,7 +693,6 @@ export class Parser { } parseConstDirectives(): Array { - // @ts-expect-error FIXME during TS conversion return this.parseDirectives(true); } @@ -669,7 +704,9 @@ export class Parser { parseDirective(isConst: boolean): DirectiveNode { const start = this._lexer.token; this.expectToken(TokenKind.AT); + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.DIRECTIVE, name: this.parseName(), arguments: this.parseArguments(isConst), @@ -691,6 +728,7 @@ export class Parser { const innerType = this.parseTypeReference(); this.expectToken(TokenKind.BRACKET_R); type = this.node(start, { + // @ts-expect-error FIXME kind: Kind.LIST_TYPE, type: innerType, }); @@ -699,7 +737,9 @@ export class Parser { } if (this.expectOptionalToken(TokenKind.BANG)) { + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.NON_NULL_TYPE, type, }); @@ -711,7 +751,9 @@ export class Parser { * NamedType : Name */ parseNamedType(): NamedTypeNode { + // @ts-expect-error FIXME return this.node(this._lexer.token, { + // @ts-expect-error FIXME kind: Kind.NAMED_TYPE, name: this.parseName(), }); @@ -789,7 +831,9 @@ export class Parser { this.parseOperationTypeDefinition, TokenKind.BRACE_R, ); + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.SCHEMA_DEFINITION, description, directives, @@ -805,7 +849,9 @@ export class Parser { const operation = this.parseOperationType(); this.expectToken(TokenKind.COLON); const type = this.parseNamedType(); + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.OPERATION_TYPE_DEFINITION, operation, type, @@ -821,7 +867,9 @@ export class Parser { this.expectKeyword('scalar'); const name = this.parseName(); const directives = this.parseConstDirectives(); + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.SCALAR_TYPE_DEFINITION, description, name, @@ -842,7 +890,9 @@ export class Parser { const interfaces = this.parseImplementsInterfaces(); const directives = this.parseConstDirectives(); const fields = this.parseFieldsDefinition(); + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.OBJECT_TYPE_DEFINITION, description, name, @@ -886,7 +936,9 @@ export class Parser { this.expectToken(TokenKind.COLON); const type = this.parseTypeReference(); const directives = this.parseConstDirectives(); + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.FIELD_DEFINITION, description, name, @@ -922,7 +974,9 @@ export class Parser { defaultValue = this.parseConstValueLiteral(); } const directives = this.parseConstDirectives(); + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.INPUT_VALUE_DEFINITION, description, name, @@ -944,7 +998,9 @@ export class Parser { const interfaces = this.parseImplementsInterfaces(); const directives = this.parseConstDirectives(); const fields = this.parseFieldsDefinition(); + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.INTERFACE_TYPE_DEFINITION, description, name, @@ -965,7 +1021,9 @@ export class Parser { const name = this.parseName(); const directives = this.parseConstDirectives(); const types = this.parseUnionMemberTypes(); + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.UNION_TYPE_DEFINITION, description, name, @@ -996,7 +1054,9 @@ export class Parser { const name = this.parseName(); const directives = this.parseConstDirectives(); const values = this.parseEnumValuesDefinition(); + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.ENUM_TYPE_DEFINITION, description, name, @@ -1026,7 +1086,9 @@ export class Parser { const description = this.parseDescription(); const name = this.parseName(); const directives = this.parseConstDirectives(); + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.ENUM_VALUE_DEFINITION, description, name, @@ -1045,7 +1107,9 @@ export class Parser { const name = this.parseName(); const directives = this.parseConstDirectives(); const fields = this.parseInputFieldsDefinition(); + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.INPUT_OBJECT_TYPE_DEFINITION, description, name, @@ -1121,7 +1185,9 @@ export class Parser { if (directives.length === 0 && operationTypes.length === 0) { throw this.unexpected(); } + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.SCHEMA_EXTENSION, directives, operationTypes, @@ -1141,7 +1207,9 @@ export class Parser { if (directives.length === 0) { throw this.unexpected(); } + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.SCALAR_TYPE_EXTENSION, name, directives, @@ -1169,7 +1237,9 @@ export class Parser { ) { throw this.unexpected(); } + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.OBJECT_TYPE_EXTENSION, name, interfaces, @@ -1199,7 +1269,9 @@ export class Parser { ) { throw this.unexpected(); } + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.INTERFACE_TYPE_EXTENSION, name, interfaces, @@ -1223,7 +1295,9 @@ export class Parser { if (directives.length === 0 && types.length === 0) { throw this.unexpected(); } + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.UNION_TYPE_EXTENSION, name, directives, @@ -1246,7 +1320,9 @@ export class Parser { if (directives.length === 0 && values.length === 0) { throw this.unexpected(); } + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.ENUM_TYPE_EXTENSION, name, directives, @@ -1269,7 +1345,9 @@ export class Parser { if (directives.length === 0 && fields.length === 0) { throw this.unexpected(); } + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.INPUT_OBJECT_TYPE_EXTENSION, name, directives, @@ -1291,7 +1369,9 @@ export class Parser { const repeatable = this.expectOptionalKeyword('repeatable'); this.expectKeyword('on'); const locations = this.parseDirectiveLocations(); + // @ts-expect-error FIXME return this.node(start, { + // @ts-expect-error FIXME kind: Kind.DIRECTIVE_DEFINITION, description, name, diff --git a/src/language/printLocation.ts b/src/language/printLocation.ts index faa9fda6b23..bcfbda2fca7 100644 --- a/src/language/printLocation.ts +++ b/src/language/printLocation.ts @@ -38,7 +38,7 @@ export function printSourceLocation( if (locationLine.length > 120) { const subLineIndex = Math.floor(columnNum / 80); const subLineColumnNum = columnNum % 80; - const subLines = []; + const subLines: Array = []; for (let i = 0; i < locationLine.length; i += 80) { subLines.push(locationLine.slice(i, i + 80)); } @@ -47,8 +47,11 @@ export function printSourceLocation( locationStr + printPrefixedLines([ [`${lineNum} |`, subLines[0]], + // @ts-expect-error FIXME ...subLines.slice(1, subLineIndex + 1).map((subLine) => ['|', subLine]), + // @ts-expect-error FIXME ['|', '^'.padStart(subLineColumnNum)], + // @ts-expect-error FIXME ['|', subLines[subLineIndex + 1]], ]) ); diff --git a/src/language/source.ts b/src/language/source.ts index 212371e0b77..202d04b33d5 100644 --- a/src/language/source.ts +++ b/src/language/source.ts @@ -42,7 +42,6 @@ export class Source { ); } - // @ts-expect-error Flow doesn't support computed properties yet get [Symbol.toStringTag]() { return 'Source'; } diff --git a/src/subscription/__tests__/mapAsyncIterator-test.ts b/src/subscription/__tests__/mapAsyncIterator-test.ts index a73ea36e5cf..e5e374e2567 100644 --- a/src/subscription/__tests__/mapAsyncIterator-test.ts +++ b/src/subscription/__tests__/mapAsyncIterator-test.ts @@ -105,6 +105,7 @@ describe('mapAsyncIterator', () => { expect(await doubles.next()).to.deep.equal({ value: 4, done: false }); // Early return + // @ts-expect-error FIXME: TS Conversion expect(await doubles.return()).to.deep.equal({ value: 'The End', done: true, @@ -142,6 +143,7 @@ describe('mapAsyncIterator', () => { expect(await doubles.next()).to.deep.equal({ value: 4, done: false }); // Early return + // @ts-expect-error FIXME: TS Conversion expect(await doubles.return()).to.deep.equal({ value: undefined, done: true, @@ -151,11 +153,11 @@ describe('mapAsyncIterator', () => { it('passes through early return from async values', async () => { async function* source() { try { - yield 1; - yield 2; + yield 'a'; + yield 'b'; // istanbul ignore next (Shouldn't be reached) - yield 3; + yield 'c'; } finally { yield 'Done'; yield 'Last'; @@ -164,8 +166,8 @@ describe('mapAsyncIterator', () => { const doubles = mapAsyncIterator(source(), (x) => x + x); - expect(await doubles.next()).to.deep.equal({ value: 2, done: false }); - expect(await doubles.next()).to.deep.equal({ value: 4, done: false }); + expect(await doubles.next()).to.deep.equal({ value: 'aa', done: false }); + expect(await doubles.next()).to.deep.equal({ value: 'bb', done: false }); // Early return expect(await doubles.return()).to.deep.equal({ diff --git a/src/subscription/__tests__/subscribe-test.ts b/src/subscription/__tests__/subscribe-test.ts index 8217d34ad3e..85a0a7e5742 100644 --- a/src/subscription/__tests__/subscribe-test.ts +++ b/src/subscription/__tests__/subscribe-test.ts @@ -312,7 +312,6 @@ describe('Subscription Initialization Phase', () => { }), }); - // @ts-expect-error (await expectPromise(subscribe({ schema: null, document }))).toRejectWith( 'Expected null to be a GraphQL schema.', ); @@ -322,7 +321,6 @@ describe('Subscription Initialization Phase', () => { 'Expected undefined to be a GraphQL schema.', ); - // @ts-expect-error (await expectPromise(subscribe({ schema, document: null }))).toRejectWith( 'Must provide document.', ); @@ -484,7 +482,7 @@ describe('Subscription Initialization Phase', () => { // Once a subscription returns a valid AsyncIterator, it can still yield errors. describe('Subscription Publish Phase', () => { it('produces a payload for multiple subscribe in same subscription', async () => { - const pubsub = new SimplePubSub(); + const pubsub = new SimplePubSub(); const subscription = await createSubscription(pubsub); invariant(isAsyncIterable(subscription)); @@ -527,7 +525,7 @@ describe('Subscription Publish Phase', () => { }); it('produces a payload per subscription event', async () => { - const pubsub = new SimplePubSub(); + const pubsub = new SimplePubSub(); const subscription = await createSubscription(pubsub); invariant(isAsyncIterable(subscription)); @@ -616,7 +614,7 @@ describe('Subscription Publish Phase', () => { }); it('produces a payload when there are multiple events', async () => { - const pubsub = new SimplePubSub(); + const pubsub = new SimplePubSub(); const subscription = await createSubscription(pubsub); invariant(isAsyncIterable(subscription)); @@ -682,7 +680,7 @@ describe('Subscription Publish Phase', () => { }); it('should not trigger when subscription is already done', async () => { - const pubsub = new SimplePubSub(); + const pubsub = new SimplePubSub(); const subscription = await createSubscription(pubsub); invariant(isAsyncIterable(subscription)); @@ -736,7 +734,7 @@ describe('Subscription Publish Phase', () => { }); it('should not trigger when subscription is thrown', async () => { - const pubsub = new SimplePubSub(); + const pubsub = new SimplePubSub(); const subscription = await createSubscription(pubsub); invariant(isAsyncIterable(subscription)); @@ -788,7 +786,7 @@ describe('Subscription Publish Phase', () => { }); it('event order is correct for multiple publishes', async () => { - const pubsub = new SimplePubSub(); + const pubsub = new SimplePubSub(); const subscription = await createSubscription(pubsub); invariant(isAsyncIterable(subscription)); diff --git a/src/subscription/mapAsyncIterator.ts b/src/subscription/mapAsyncIterator.ts index 2419505fb03..099e127cc15 100644 --- a/src/subscription/mapAsyncIterator.ts +++ b/src/subscription/mapAsyncIterator.ts @@ -19,6 +19,7 @@ export function mapAsyncIterator( } try { + // @ts-expect-error FIXME return { value: await callback(result.value), done: false }; } catch (error) { // istanbul ignore else (FIXME: add test case) diff --git a/src/subscription/subscribe.ts b/src/subscription/subscribe.ts index 7e76379f047..29eafd9bb4e 100644 --- a/src/subscription/subscribe.ts +++ b/src/subscription/subscribe.ts @@ -72,7 +72,6 @@ export async function subscribe( subscribeFieldResolver, } = args; - // @ts-expect-error const resultOrStream = await createSourceEventStream( schema, document, @@ -166,6 +165,7 @@ export async function createSourceEventStream( return { errors: exeContext }; } + // @ts-expect-error FIXME const eventStream = await executeSubscription(exeContext); // Assert field returned an event stream, otherwise yield an error. diff --git a/src/type/__tests__/definition-test.ts b/src/type/__tests__/definition-test.ts index 10efce381fb..6b18fe283a5 100644 --- a/src/type/__tests__/definition-test.ts +++ b/src/type/__tests__/definition-test.ts @@ -83,9 +83,11 @@ describe('Type System: Scalars', () => { }, }); + // @ts-expect-error expect(scalar.parseLiteral(parseValue('null'))).to.equal( 'parseValue: null', ); + // @ts-expect-error expect(scalar.parseLiteral(parseValue('{ foo: "bar" }'))).to.equal( 'parseValue: { foo: "bar" }', ); @@ -333,7 +335,6 @@ describe('Type System: Objects', () => { const objType = new GraphQLObjectType({ name: 'SomeObject', fields: { - // @ts-expect-error f: undefined, }, }); @@ -356,8 +357,8 @@ describe('Type System: Objects', () => { it('rejects an Object type with a field function that returns incorrect type', () => { const objType = new GraphQLObjectType({ name: 'SomeObject', + // @ts-expect-error fields() { - // @ts-expect-error return [{ field: ScalarType }]; }, }); @@ -396,8 +397,8 @@ describe('Type System: Objects', () => { const objType = new GraphQLObjectType({ name: 'SomeObject', fields: {}, + // @ts-expect-error interfaces() { - // @ts-expect-error return {}; }, }); @@ -409,8 +410,8 @@ describe('Type System: Objects', () => { it('rejects an empty Object field resolver', () => { const objType = new GraphQLObjectType({ name: 'SomeObject', - // @ts-expect-error fields: { + // @ts-expect-error field: { type: ScalarType, resolve: {} }, }, }); @@ -423,8 +424,8 @@ describe('Type System: Objects', () => { it('rejects a constant scalar value resolver', () => { const objType = new GraphQLObjectType({ name: 'SomeObject', - // @ts-expect-error fields: { + // @ts-expect-error field: { type: ScalarType, resolve: 0 }, }, }); @@ -499,8 +500,8 @@ describe('Type System: Interfaces', () => { const objType = new GraphQLInterfaceType({ name: 'AnotherInterface', fields: {}, + // @ts-expect-error interfaces() { - // @ts-expect-error return {}; }, }); @@ -697,7 +698,6 @@ describe('Type System: Enums', () => { () => new GraphQLEnumType({ name: 'SomeEnum', - // @ts-expect-error values: { FOO: null }, }), ).to.throw( @@ -795,8 +795,8 @@ describe('Type System: Input Objects', () => { it('rejects an Input Object type with resolvers', () => { const inputObjType = new GraphQLInputObjectType({ name: 'SomeInputObject', - // @ts-expect-error fields: { + // @ts-expect-error f: { type: ScalarType, resolve: dummyFunc }, }, }); @@ -808,8 +808,8 @@ describe('Type System: Input Objects', () => { it('rejects an Input Object type with resolver constant', () => { const inputObjType = new GraphQLInputObjectType({ name: 'SomeInputObject', - // @ts-expect-error fields: { + // @ts-expect-error f: { type: ScalarType, resolve: {} }, }, }); @@ -843,9 +843,7 @@ describe('Type System: List', () => { expectList(String).to.throw( 'Expected [function String] to be a GraphQL type.', ); - // @ts-expect-error expectList(null).to.throw('Expected null to be a GraphQL type.'); - // @ts-expect-error expectList(undefined).to.throw('Expected undefined to be a GraphQL type.'); }); }); @@ -867,7 +865,6 @@ describe('Type System: Non-Null', () => { }); it('rejects a non-type as nullable type of non-null', () => { - // @ts-expect-error expectNonNull(NonNullScalarType).to.throw( 'Expected Scalar! to be a GraphQL nullable type.', ); @@ -877,11 +874,9 @@ describe('Type System: Non-Null', () => { expectNonNull(String).to.throw( 'Expected [function String] to be a GraphQL nullable type.', ); - // @ts-expect-error expectNonNull(null).to.throw( 'Expected null to be a GraphQL nullable type.', ); - // @ts-expect-error expectNonNull(undefined).to.throw( 'Expected undefined to be a GraphQL nullable type.', ); diff --git a/src/type/__tests__/introspection-test.ts b/src/type/__tests__/introspection-test.ts index 9db9470e975..3a01af5a527 100644 --- a/src/type/__tests__/introspection-test.ts +++ b/src/type/__tests__/introspection-test.ts @@ -1566,12 +1566,12 @@ describe('Introspection', () => { }); // istanbul ignore next (Called only to fail test) - function fieldResolver(_1, _2, _3, info) { + function fieldResolver(_1, _2, _3, info): never { expect.fail(`Called on ${info.parentType.name}::${info.fieldName}`); } // istanbul ignore next (Called only to fail test) - function typeResolver(_1, _2, info) { + function typeResolver(_1, _2, info): never { expect.fail(`Called on ${info.parentType.name}::${info.fieldName}`); } diff --git a/src/type/__tests__/validation-test.ts b/src/type/__tests__/validation-test.ts index 97d839a95a8..1e2548c047b 100644 --- a/src/type/__tests__/validation-test.ts +++ b/src/type/__tests__/validation-test.ts @@ -1036,7 +1036,6 @@ describe('Type System: Object fields must have output types', () => { } it('rejects an empty Object field type', () => { - // @ts-expect-error const schema = schemaWithObjectField({ type: undefined }); expect(validateSchema(schema)).to.deep.equal([ { @@ -1098,7 +1097,6 @@ describe('Type System: Objects can only implement unique interfaces', () => { const schema = new GraphQLSchema({ query: new GraphQLObjectType({ name: 'BadObject', - // @ts-expect-error interfaces: [undefined], fields: { f: { type: GraphQLString } }, }), @@ -1357,7 +1355,6 @@ describe('Type System: Interface fields must have output types', () => { } it('rejects an empty Interface field type', () => { - // @ts-expect-error const schema = schemaWithInterfaceField({ type: undefined }); expect(validateSchema(schema)).to.deep.equal([ { @@ -1493,7 +1490,6 @@ describe('Type System: Arguments must have input types', () => { } it('rejects an empty field arg type', () => { - // @ts-expect-error const schema = schemaWithArg({ type: undefined }); expect(validateSchema(schema)).to.deep.equal([ { @@ -1631,7 +1627,6 @@ describe('Type System: Input Object fields must have input types', () => { } it('rejects an empty input field type', () => { - // @ts-expect-error const schema = schemaWithInputField({ type: undefined }); expect(validateSchema(schema)).to.deep.equal([ { diff --git a/src/type/definition.ts b/src/type/definition.ts index 8e41fb09b50..3d38a43d5a2 100644 --- a/src/type/definition.ts +++ b/src/type/definition.ts @@ -180,6 +180,15 @@ export function assertListType(type: unknown): GraphQLList { return type; } +export function isNonNullType( + type: GraphQLInputType, +): type is GraphQLNonNull; +export function isNonNullType( + type: GraphQLOutputType, +): type is GraphQLNonNull; +export function isNonNullType( + type: unknown, +): type is GraphQLNonNull; export function isNonNullType( type: unknown, ): type is GraphQLNonNull { @@ -352,7 +361,6 @@ export class GraphQLList { return this.toString(); } - // @ts-expect-error Flow doesn't support computed properties yet get [Symbol.toStringTag]() { return 'GraphQLList'; } @@ -398,7 +406,6 @@ export class GraphQLNonNull { return this.toString(); } - // @ts-expect-error Flow doesn't support computed properties yet get [Symbol.toStringTag]() { return 'GraphQLNonNull'; } @@ -631,7 +638,6 @@ export class GraphQLScalarType { return this.toString(); } - // @ts-expect-error Flow doesn't support computed properties yet get [Symbol.toStringTag]() { return 'GraphQLScalarType'; } @@ -791,7 +797,6 @@ export class GraphQLObjectType { return this.toString(); } - // @ts-expect-error Flow doesn't support computed properties yet get [Symbol.toStringTag]() { return 'GraphQLObjectType'; } @@ -823,6 +828,7 @@ function defineFieldMap( `${config.name} fields must be an object with field names as keys or a function which returns such an object.`, ); + // @ts-expect-error FIXME: TS Conversion return mapValue(fieldMap, (fieldConfig, fieldName) => { devAssert( isPlainObj(fieldConfig), @@ -1157,7 +1163,6 @@ export class GraphQLInterfaceType { return this.toString(); } - // @ts-expect-error Flow doesn't support computed properties yet get [Symbol.toStringTag]() { return 'GraphQLInterfaceType'; } @@ -1277,7 +1282,6 @@ export class GraphQLUnionType { return this.toString(); } - // @ts-expect-error Flow doesn't support computed properties yet get [Symbol.toStringTag]() { return 'GraphQLUnionType'; } @@ -1471,7 +1475,6 @@ export class GraphQLEnumType /* */ { return this.toString(); } - // @ts-expect-error Flow doesn't support computed properties yet get [Symbol.toStringTag]() { return 'GraphQLEnumType'; } @@ -1646,7 +1649,6 @@ export class GraphQLInputObjectType { return this.toString(); } - // @ts-expect-error Flow doesn't support computed properties yet get [Symbol.toStringTag]() { return 'GraphQLInputObjectType'; } diff --git a/src/type/directives.ts b/src/type/directives.ts index c09ac632a63..3dff8298bbb 100644 --- a/src/type/directives.ts +++ b/src/type/directives.ts @@ -105,7 +105,6 @@ export class GraphQLDirective { return this.toString(); } - // @ts-expect-error Flow doesn't support computed properties yet get [Symbol.toStringTag]() { return 'GraphQLDirective'; } diff --git a/src/type/introspection.ts b/src/type/introspection.ts index 3560c8f8124..1a9a655b919 100644 --- a/src/type/introspection.ts +++ b/src/type/introspection.ts @@ -234,16 +234,19 @@ export const __Type: GraphQLObjectType = new GraphQLObjectType({ }, name: { type: GraphQLString, + // @ts-expect-error FIXME: TS Conversion resolve: (type) => (type.name !== undefined ? type.name : undefined), }, description: { type: GraphQLString, resolve: (type) => + // @ts-expect-error FIXME: TS Conversion type.description !== undefined ? type.description : undefined, }, specifiedByURL: { type: GraphQLString, resolve: (obj) => + // @ts-expect-error FIXME: TS Conversion obj.specifiedByURL !== undefined ? obj.specifiedByURL : undefined, }, fields: { @@ -310,6 +313,7 @@ export const __Type: GraphQLObjectType = new GraphQLObjectType({ ofType: { type: __Type, resolve: (type) => + // @ts-expect-error FIXME: TS Conversion type.ofType !== undefined ? type.ofType : undefined, }, } as GraphQLFieldConfigMap), diff --git a/src/type/scalars.ts b/src/type/scalars.ts index 2d590c9e73f..b8a4ee11f49 100644 --- a/src/type/scalars.ts +++ b/src/type/scalars.ts @@ -139,7 +139,6 @@ function serializeObject(outputValue: unknown): unknown { } } if (typeof outputValue.toJSON === 'function') { - // @ts-expect-error return outputValue.toJSON(); } } diff --git a/src/type/schema.ts b/src/type/schema.ts index 9764c93ea12..46015b00200 100644 --- a/src/type/schema.ts +++ b/src/type/schema.ts @@ -344,7 +344,6 @@ export class GraphQLSchema { }; } - // @ts-expect-error Flow doesn't support computed properties yet get [Symbol.toStringTag]() { return 'GraphQLSchema'; } diff --git a/src/type/validate.ts b/src/type/validate.ts index a8c58e899b4..65062401c79 100644 --- a/src/type/validate.ts +++ b/src/type/validate.ts @@ -117,6 +117,7 @@ function validateRootTypes(context: SchemaValidationContext): void { `Query root type must be Object type, it cannot be ${inspect( queryType, )}.`, + // @ts-expect-error FIXME: TS Conversion getOperationTypeNode(schema, 'query') ?? queryType.astNode, ); } @@ -126,6 +127,7 @@ function validateRootTypes(context: SchemaValidationContext): void { context.reportError( 'Mutation root type must be Object type if provided, it cannot be ' + `${inspect(mutationType)}.`, + // @ts-expect-error FIXME: TS Conversion getOperationTypeNode(schema, 'mutation') ?? mutationType.astNode, ); } @@ -135,6 +137,7 @@ function validateRootTypes(context: SchemaValidationContext): void { context.reportError( 'Subscription root type must be Object type if provided, it cannot be ' + `${inspect(subscriptionType)}.`, + // @ts-expect-error FIXME: TS Conversion getOperationTypeNode(schema, 'subscription') ?? subscriptionType.astNode, ); } @@ -145,10 +148,13 @@ function getOperationTypeNode( operation: OperationTypeNode, ): Maybe { // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203') - return [schema.astNode] - .concat(schema.extensionASTNodes) - .flatMap((schemaNode) => schemaNode?.operationTypes ?? []) - .find((operationNode) => operationNode.operation === operation)?.type; + return ( + [schema.astNode] + // @ts-expect-error FIXME: TS Conversion + .concat(schema.extensionASTNodes) + .flatMap((schemaNode) => schemaNode?.operationTypes ?? []) + .find((operationNode) => operationNode.operation === operation)?.type + ); } function validateDirectives(context: SchemaValidationContext): void { @@ -157,6 +163,7 @@ function validateDirectives(context: SchemaValidationContext): void { if (!isDirective(directive)) { context.reportError( `Expected directive but got: ${inspect(directive)}.`, + // @ts-expect-error FIXME: TS Conversion directive?.astNode, ); continue; @@ -211,6 +218,7 @@ function validateTypes(context: SchemaValidationContext): void { if (!isNamedType(type)) { context.reportError( `Expected GraphQL named type but got: ${inspect(type)}.`, + // @ts-expect-error FIXME: TS Conversion type.astNode, ); continue; diff --git a/src/utilities/__tests__/buildASTSchema-test.ts b/src/utilities/__tests__/buildASTSchema-test.ts index c19f2cf1efa..6503f6a02e6 100644 --- a/src/utilities/__tests__/buildASTSchema-test.ts +++ b/src/utilities/__tests__/buildASTSchema-test.ts @@ -1095,7 +1095,6 @@ describe('Schema Builder', () => { }); it('Rejects invalid AST', () => { - // @ts-expect-error expect(() => buildASTSchema(null)).to.throw( 'Must provide valid Document AST', ); diff --git a/src/utilities/__tests__/buildClientSchema-test.ts b/src/utilities/__tests__/buildClientSchema-test.ts index 8bfc8c59949..49c4253b532 100644 --- a/src/utilities/__tests__/buildClientSchema-test.ts +++ b/src/utilities/__tests__/buildClientSchema-test.ts @@ -629,7 +629,6 @@ describe('Type System: build schema from introspection', () => { `); it('throws when introspection is missing __schema property', () => { - // @ts-expect-error expect(() => buildClientSchema(null)).to.throw( 'Invalid or incomplete introspection result. Ensure that you are passing "data" property of introspection response and no "errors" was returned alongside: null.', ); diff --git a/src/utilities/__tests__/coerceInputValue-test.ts b/src/utilities/__tests__/coerceInputValue-test.ts index d587a7547f7..79ee43de234 100644 --- a/src/utilities/__tests__/coerceInputValue-test.ts +++ b/src/utilities/__tests__/coerceInputValue-test.ts @@ -1,8 +1,6 @@ import { expect } from 'chai'; import { describe, it } from 'mocha'; -import { invariant } from '../../jsutils/invariant'; - import type { GraphQLInputType } from '../../type/definition'; import { GraphQLInt } from '../../type/scalars'; import { @@ -84,8 +82,7 @@ describe('coerceInputValue', () => { describe('for GraphQLScalar', () => { const TestScalar = new GraphQLScalarType({ name: 'TestScalar', - parseValue(input) { - invariant(typeof input === 'object' && input !== null); + parseValue(input: { error?: string; value?: unknown }) { if (input.error != null) { throw new Error(input.error); } diff --git a/src/utilities/__tests__/extendSchema-test.ts b/src/utilities/__tests__/extendSchema-test.ts index 48df80aa22c..085752dcc45 100644 --- a/src/utilities/__tests__/extendSchema-test.ts +++ b/src/utilities/__tests__/extendSchema-test.ts @@ -1143,7 +1143,6 @@ describe('extendSchema', () => { it('Rejects invalid AST', () => { const schema = new GraphQLSchema({}); - // @ts-expect-error expect(() => extendSchema(schema, null)).to.throw( 'Must provide valid Document AST', ); diff --git a/src/utilities/__tests__/getOperationRootType-test.ts b/src/utilities/__tests__/getOperationRootType-test.ts index 648b82704d9..f730e7810a5 100644 --- a/src/utilities/__tests__/getOperationRootType-test.ts +++ b/src/utilities/__tests__/getOperationRootType-test.ts @@ -3,7 +3,7 @@ import { describe, it } from 'mocha'; import { invariant } from '../../jsutils/invariant'; -import type { DocumentNode } from '../../language/ast'; +import type { DocumentNode, OperationDefinitionNode } from '../../language/ast'; import { Kind } from '../../language/kinds'; import { parse } from '../../language/parser'; @@ -34,7 +34,7 @@ const subscriptionType = new GraphQLObjectType({ }), }); -function getOperationNode(doc: DocumentNode) { +function getOperationNode(doc: DocumentNode): OperationDefinitionNode { const operationNode = doc.definitions[0]; invariant(operationNode.kind === Kind.OPERATION_DEFINITION); return operationNode; @@ -146,12 +146,12 @@ describe('getOperationRootType', () => { it('Throws when operation not a valid operation kind', () => { const testSchema = new GraphQLSchema({}); const doc = parse('{ field }'); - const operationNode = { + const operationNode: OperationDefinitionNode = { ...getOperationNode(doc), + // @ts-expect-error operation: 'non_existent_operation', }; - // @ts-expect-error expect(() => getOperationRootType(testSchema, operationNode)).to.throw( 'Can only have query, mutation and subscription operations.', ); diff --git a/src/utilities/extendSchema.ts b/src/utilities/extendSchema.ts index d49d530da48..5ad120afb68 100644 --- a/src/utilities/extendSchema.ts +++ b/src/utilities/extendSchema.ts @@ -224,6 +224,7 @@ export function extendSchemaImpl( // @ts-expect-error return new GraphQLNonNull(replaceType(type.ofType)); } + // @ts-expect-error FIXME return replaceNamedType(type); } @@ -378,7 +379,6 @@ export function extendSchemaImpl( return { ...field, type: replaceType(field.type), - // @ts-expect-error args: mapValue(field.args, extendArg), }; } @@ -411,7 +411,6 @@ export function extendSchemaImpl( // typed values below, that would throw immediately while type system // validation with validateSchema() will produce more actionable results. // @ts-expect-error - // @ts-expect-error return opTypes; } @@ -430,7 +429,6 @@ export function extendSchemaImpl( return new GraphQLList(getWrappedType(node.type)); } if (node.kind === Kind.NON_NULL_TYPE) { - // @ts-expect-error return new GraphQLNonNull(getWrappedType(node.type)); } return getNamedType(node); @@ -658,6 +656,7 @@ export function extendSchemaImpl( } const stdTypeMap = keyMap( + // @ts-expect-error FIXME specifiedScalarTypes.concat(introspectionTypes), (type) => type.name, ); diff --git a/src/utilities/introspectionFromSchema.ts b/src/utilities/introspectionFromSchema.ts index 8d30e9bce66..105f5bc0559 100644 --- a/src/utilities/introspectionFromSchema.ts +++ b/src/utilities/introspectionFromSchema.ts @@ -36,7 +36,6 @@ export function introspectionFromSchema( const document = parse(getIntrospectionQuery(optionsWithDefaults)); const result = executeSync({ schema, document }); invariant(!result.errors && result.data); - // $FlowIgnore[incompatible-indexer] - // $FlowIgnore[incompatible-return] + // @ts-expect-error FIXME return result.data; } diff --git a/src/utilities/lexicographicSortSchema.ts b/src/utilities/lexicographicSortSchema.ts index e87106a229c..990ce3727c8 100644 --- a/src/utilities/lexicographicSortSchema.ts +++ b/src/utilities/lexicographicSortSchema.ts @@ -63,7 +63,8 @@ export function lexicographicSortSchema(schema: GraphQLSchema): GraphQLSchema { // @ts-expect-error return new GraphQLNonNull(replaceType(type.ofType)); } - return replaceNamedType(type); + // @ts-expect-error + return replaceNamedType(type); } function replaceNamedType(type: T): T { diff --git a/src/utilities/separateOperations.ts b/src/utilities/separateOperations.ts index 5da3c1d1ea4..6f33d4a2342 100644 --- a/src/utilities/separateOperations.ts +++ b/src/utilities/separateOperations.ts @@ -38,7 +38,7 @@ export function separateOperations( // is necessary for completing that operation. const separatedDocumentASTs = Object.create(null); for (const operation of operations) { - const dependencies = new Set(); + const dependencies = new Set(); for (const fragmentName of collectDependencies(operation.selectionSet)) { collectTransitiveDependencies(dependencies, depGraph, fragmentName); diff --git a/src/utilities/typeFromAST.ts b/src/utilities/typeFromAST.ts index 9c959784f6f..5b3b3f20860 100644 --- a/src/utilities/typeFromAST.ts +++ b/src/utilities/typeFromAST.ts @@ -33,6 +33,10 @@ export function typeFromAST( schema: GraphQLSchema, typeNode: NonNullTypeNode, ): GraphQLNonNull | undefined; +export function typeFromAST( + schema: GraphQLSchema, + typeNode: TypeNode, +): GraphQLType | undefined; export function typeFromAST( schema: GraphQLSchema, typeNode: TypeNode, diff --git a/src/validation/ValidationContext.ts b/src/validation/ValidationContext.ts index fdfd7efd653..fc2e0338f37 100644 --- a/src/validation/ValidationContext.ts +++ b/src/validation/ValidationContext.ts @@ -94,6 +94,7 @@ export class ASTValidationContext { const set = setsToVisit.pop(); for (const selection of set.selections) { if (selection.kind === Kind.FRAGMENT_SPREAD) { + // @ts-expect-error spreads.push(selection); } else if (selection.selectionSet) { setsToVisit.push(selection.selectionSet); @@ -121,6 +122,7 @@ export class ASTValidationContext { collectedNames[fragName] = true; const fragment = this.getFragment(fragName); if (fragment) { + // @ts-expect-error FIXME fragments.push(fragment); nodesToVisit.push(fragment.selectionSet); } diff --git a/src/validation/__tests__/validation-test.ts b/src/validation/__tests__/validation-test.ts index e0322f518a2..a015bb9bd44 100644 --- a/src/validation/__tests__/validation-test.ts +++ b/src/validation/__tests__/validation-test.ts @@ -15,7 +15,6 @@ import { testSchema } from './harness'; describe('Validate: Supports full validation', () => { it('rejects invalid documents', () => { - // @ts-expect-error expect(() => validate(testSchema, null)).to.throw('Must provide document.'); }); diff --git a/src/validation/rules/KnownDirectivesRule.ts b/src/validation/rules/KnownDirectivesRule.ts index 04b98566caf..46bc1a16e79 100644 --- a/src/validation/rules/KnownDirectivesRule.ts +++ b/src/validation/rules/KnownDirectivesRule.ts @@ -73,8 +73,10 @@ function getDirectiveLocationForASTPath( const appliedTo = ancestors[ancestors.length - 1]; invariant(!Array.isArray(appliedTo)); + // @ts-expect-error switch (appliedTo.kind) { case Kind.OPERATION_DEFINITION: + // @ts-expect-error return getDirectiveLocationForOperation(appliedTo.operation); case Kind.FIELD: return DirectiveLocation.FIELD; @@ -113,6 +115,7 @@ function getDirectiveLocationForASTPath( return DirectiveLocation.INPUT_OBJECT; case Kind.INPUT_VALUE_DEFINITION: { const parentNode = ancestors[ancestors.length - 3]; + // @ts-expect-error return parentNode.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION ? DirectiveLocation.INPUT_FIELD_DEFINITION : DirectiveLocation.ARGUMENT_DEFINITION; diff --git a/src/validation/rules/KnownTypeNamesRule.ts b/src/validation/rules/KnownTypeNamesRule.ts index 6d2ec6985b3..ba0fcbf5d95 100644 --- a/src/validation/rules/KnownTypeNamesRule.ts +++ b/src/validation/rules/KnownTypeNamesRule.ts @@ -75,6 +75,7 @@ const standardTypeNames = [...specifiedScalarTypes, ...introspectionTypes].map( function isSDLNode(value: ASTNode | ReadonlyArray): boolean { return ( !Array.isArray(value) && + // @ts-expect-error FIXME (isTypeSystemDefinitionNode(value) || isTypeSystemExtensionNode(value)) ); } diff --git a/src/validation/rules/ProvidedRequiredArgumentsRule.ts b/src/validation/rules/ProvidedRequiredArgumentsRule.ts index 0ddc8f784dc..e5c970d24f8 100644 --- a/src/validation/rules/ProvidedRequiredArgumentsRule.ts +++ b/src/validation/rules/ProvidedRequiredArgumentsRule.ts @@ -1,5 +1,6 @@ import { inspect } from '../../jsutils/inspect'; import { keyMap } from '../../jsutils/keyMap'; +import type { ObjMap } from '../../jsutils/ObjMap'; import { GraphQLError } from '../../error/GraphQLError'; @@ -10,6 +11,7 @@ import { print } from '../../language/printer'; import { specifiedDirectives } from '../../type/directives'; import { isType, isRequiredArgument } from '../../type/definition'; +import type { GraphQLArgument } from '../../type/definition'; import type { ValidationContext, @@ -62,7 +64,9 @@ export function ProvidedRequiredArgumentsRule( export function ProvidedRequiredArgumentsOnDirectivesRule( context: ValidationContext | SDLValidationContext, ): ASTVisitor { - const requiredArgsMap = Object.create(null); + const requiredArgsMap: ObjMap< + ObjMap + > = Object.create(null); const schema = context.getSchema(); const definedDirectives = schema?.getDirectives() ?? specifiedDirectives; diff --git a/src/validation/rules/UniqueDirectivesPerLocationRule.ts b/src/validation/rules/UniqueDirectivesPerLocationRule.ts index a21c0817903..bbe9647500c 100644 --- a/src/validation/rules/UniqueDirectivesPerLocationRule.ts +++ b/src/validation/rules/UniqueDirectivesPerLocationRule.ts @@ -48,6 +48,7 @@ export function UniqueDirectivesPerLocationRule( // them all, just listen for entering any node, and check to see if it // defines any directives. enter(node) { + // @ts-expect-error if (node.directives == null) { return; } @@ -68,6 +69,7 @@ export function UniqueDirectivesPerLocationRule( seenDirectives = Object.create(null); } + // @ts-expect-error for (const directive of node.directives) { const directiveName = directive.name.value;