From c1fe84f4c062bcaf7fbcf8998c9a735d0e0e3a14 Mon Sep 17 00:00:00 2001 From: Lee Byron Date: Wed, 26 May 2021 22:23:48 -0700 Subject: [PATCH] TS: Fix strict issues in src/error --- src/__tests__/starWarsSchema.ts | 2 +- src/error/GraphQLError.ts | 9 --------- src/error/__tests__/formatError-test.ts | 2 ++ src/error/locatedError.ts | 17 ++++++++--------- 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/__tests__/starWarsSchema.ts b/src/__tests__/starWarsSchema.ts index 16a80fcee76..e915c98f39e 100644 --- a/src/__tests__/starWarsSchema.ts +++ b/src/__tests__/starWarsSchema.ts @@ -98,7 +98,7 @@ const episodeEnum = new GraphQLEnumType({ * secretBackstory: String * } */ -const characterInterface = new GraphQLInterfaceType({ +const characterInterface: GraphQLInterfaceType = new GraphQLInterfaceType({ name: 'Character', description: 'A character in the Star Wars Trilogy', fields: () => ({ diff --git a/src/error/GraphQLError.ts b/src/error/GraphQLError.ts index 68ddeda7029..89a82eef298 100644 --- a/src/error/GraphQLError.ts +++ b/src/error/GraphQLError.ts @@ -14,15 +14,6 @@ import { printLocation, printSourceLocation } from '../language/printLocation'; * GraphQL document and/or execution result that correspond to the Error. */ export class GraphQLError extends Error { - /** - * A message describing the Error for debugging purposes. - * - * Enumerable, and appears in the result of JSON.stringify(). - * - * Note: should be treated as readonly, despite invariant usage. - */ - message: string; - /** * An array of { line, column } locations within the source GraphQL document * which correspond to this error. diff --git a/src/error/__tests__/formatError-test.ts b/src/error/__tests__/formatError-test.ts index d618f8d2d03..9ea5e946ef4 100644 --- a/src/error/__tests__/formatError-test.ts +++ b/src/error/__tests__/formatError-test.ts @@ -45,10 +45,12 @@ describe('formatError: default error formatter', () => { }); it('rejects null and undefined errors', () => { + // TODO ts-expect-error (formatError expects a value) expect(() => formatError(undefined)).to.throw( 'Received null or undefined error.', ); + // TODO ts-expect-error (formatError expects a value) expect(() => formatError(null)).to.throw( 'Received null or undefined error.', ); diff --git a/src/error/locatedError.ts b/src/error/locatedError.ts index 286408f792f..fb5df58ec7f 100644 --- a/src/error/locatedError.ts +++ b/src/error/locatedError.ts @@ -22,21 +22,20 @@ 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 + if (isLocatedGraphQLError(originalError)) { return originalError; } return new GraphQLError( originalError.message, - // @ts-expect-error FIXME - originalError.nodes ?? nodes, - // @ts-expect-error FIXME - originalError.source, - // @ts-expect-error FIXME - originalError.positions, + (originalError as GraphQLError).nodes ?? nodes, + (originalError as GraphQLError).source, + (originalError as GraphQLError).positions, path, originalError, ); } + +function isLocatedGraphQLError(error: any): error is GraphQLError { + return Array.isArray(error.path); +}