Skip to content

Commit

Permalink
TS: Fix strict issues in src/error
Browse files Browse the repository at this point in the history
  • Loading branch information
leebyron committed May 27, 2021
1 parent 111a481 commit 25bd31c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/starWarsSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => ({
Expand Down
9 changes: 0 additions & 9 deletions src/error/GraphQLError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/error/__tests__/formatError-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
);
Expand Down
17 changes: 8 additions & 9 deletions src/error/locatedError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 25bd31c

Please sign in to comment.