diff --git a/src/error/GraphQLError.ts b/src/error/GraphQLError.ts index 77a5e78779..6901c40b99 100644 --- a/src/error/GraphQLError.ts +++ b/src/error/GraphQLError.ts @@ -33,29 +33,29 @@ export interface GraphQLFormattedErrorExtensions { [attributeName: string]: unknown; } -export interface GraphQLErrorOptions { +export interface GraphQLErrorOptions { nodes?: ReadonlyArray | ASTNode | null; source?: Maybe; positions?: Maybe>; path?: Maybe>; originalError?: Maybe; - extensions?: Maybe; + extensions?: Maybe; } -type BackwardsCompatibleArgs = - | [options?: GraphQLErrorOptions] +type BackwardsCompatibleArgs = + | [options?: GraphQLErrorOptions] | [ - nodes?: GraphQLErrorOptions['nodes'], - source?: GraphQLErrorOptions['source'], - positions?: GraphQLErrorOptions['positions'], - path?: GraphQLErrorOptions['path'], - originalError?: GraphQLErrorOptions['originalError'], - extensions?: GraphQLErrorOptions['extensions'], + nodes?: GraphQLErrorOptions['nodes'], + source?: GraphQLErrorOptions['source'], + positions?: GraphQLErrorOptions['positions'], + path?: GraphQLErrorOptions['path'], + originalError?: GraphQLErrorOptions['originalError'], + extensions?: GraphQLErrorOptions['extensions'], ]; -function toNormalizedOptions( - args: BackwardsCompatibleArgs, -): GraphQLErrorOptions { +function toNormalizedOptions( + args: BackwardsCompatibleArgs, +): GraphQLErrorOptions { const firstArg = args[0]; if (firstArg == null || 'kind' in firstArg || 'length' in firstArg) { return { @@ -76,7 +76,7 @@ function toNormalizedOptions( * and stack trace, it also includes information about the locations in a * GraphQL document and/or execution result that correspond to the Error. */ -export class GraphQLError extends Error { +export class GraphQLError extends Error { /** * An array of `{ line, column }` locations within the source GraphQL document * which correspond to this error. @@ -124,9 +124,9 @@ export class GraphQLError extends Error { /** * Extension fields to add to the formatted error. */ - readonly extensions: GraphQLErrorExtensions; + readonly extensions: TErrorExtensions; - constructor(message: string, options?: GraphQLErrorOptions); + constructor(message: string, options?: GraphQLErrorOptions); /** * @deprecated Please use the `GraphQLErrorOptions` constructor overload instead. */ @@ -137,11 +137,11 @@ export class GraphQLError extends Error { positions?: Maybe>, path?: Maybe>, originalError?: Maybe, - extensions?: Maybe, + extensions?: Maybe, ); - constructor(message: string, ...rawArgs: BackwardsCompatibleArgs) { + constructor(message: string, ...rawArgs: BackwardsCompatibleArgs) { const { nodes, source, positions, path, originalError, extensions } = - toNormalizedOptions(rawArgs); + toNormalizedOptions(rawArgs); super(message); this.name = 'GraphQLError'; @@ -231,9 +231,9 @@ export class GraphQLError extends Error { return output; } - toJSON(): GraphQLFormattedError { + toJSON(): GraphQLFormattedError { type WritableFormattedError = { - -readonly [P in keyof GraphQLFormattedError]: GraphQLFormattedError[P]; + -readonly [P in keyof GraphQLFormattedError]: GraphQLFormattedError[P]; }; const formattedError: WritableFormattedError = { @@ -265,7 +265,7 @@ function undefinedIfEmpty( /** * See: https://spec.graphql.org/draft/#sec-Errors */ -export interface GraphQLFormattedError { +export interface GraphQLFormattedError { /** * A short, human-readable summary of the problem that **SHOULD NOT** change * from occurrence to occurrence of the problem, except for purposes of @@ -288,7 +288,7 @@ export interface GraphQLFormattedError { * Reserved for implementors to extend the protocol however they see fit, * and hence there are no additional restrictions on its contents. */ - readonly extensions?: GraphQLFormattedErrorExtensions; + readonly extensions?: TErrorExtensions; } /** diff --git a/src/execution/execute.ts b/src/execution/execute.ts index 3021354e28..31fb96cd02 100644 --- a/src/execution/execute.ts +++ b/src/execution/execute.ts @@ -127,8 +127,9 @@ export interface ExecutionContext { export interface ExecutionResult< TData = ObjMap, TExtensions = ObjMap, + TErrorExtensions = ObjMap, > { - errors?: ReadonlyArray; + errors?: ReadonlyArray>; data?: TData | null; extensions?: TExtensions; }