Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions src/error/GraphQLError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface GraphQLErrorExtensions {
[attributeName: string]: unknown;
}

export interface GraphQLErrorArgs {
export interface GraphQLErrorOptions {
nodes?: ReadonlyArray<ASTNode> | ASTNode | null;
source?: Maybe<Source>;
positions?: Maybe<ReadonlyArray<number>>;
Expand All @@ -30,17 +30,19 @@ export interface GraphQLErrorArgs {
}

type BackwardsCompatibleArgs =
| [args?: GraphQLErrorArgs]
| [options?: GraphQLErrorOptions]
| [
nodes?: GraphQLErrorArgs['nodes'],
source?: GraphQLErrorArgs['source'],
positions?: GraphQLErrorArgs['positions'],
path?: GraphQLErrorArgs['path'],
originalError?: GraphQLErrorArgs['originalError'],
extensions?: GraphQLErrorArgs['extensions'],
nodes?: GraphQLErrorOptions['nodes'],
source?: GraphQLErrorOptions['source'],
positions?: GraphQLErrorOptions['positions'],
path?: GraphQLErrorOptions['path'],
originalError?: GraphQLErrorOptions['originalError'],
extensions?: GraphQLErrorOptions['extensions'],
];

function toNormalizedArgs(args: BackwardsCompatibleArgs): GraphQLErrorArgs {
function toNormalizedOptions(
args: BackwardsCompatibleArgs,
): GraphQLErrorOptions {
const firstArg = args[0];
if (firstArg == null || 'kind' in firstArg || 'length' in firstArg) {
return {
Expand Down Expand Up @@ -111,9 +113,9 @@ export class GraphQLError extends Error {
*/
readonly extensions: GraphQLErrorExtensions;

constructor(message: string, args?: GraphQLErrorArgs);
constructor(message: string, options?: GraphQLErrorOptions);
/**
* @deprecated Please use the `GraphQLErrorArgs` constructor overload instead.
* @deprecated Please use the `GraphQLErrorOptions` constructor overload instead.
*/
constructor(
message: string,
Expand All @@ -126,7 +128,7 @@ export class GraphQLError extends Error {
);
constructor(message: string, ...rawArgs: BackwardsCompatibleArgs) {
const { nodes, source, positions, path, originalError, extensions } =
toNormalizedArgs(rawArgs);
toNormalizedOptions(rawArgs);
super(message);

this.name = 'GraphQLError';
Expand Down
1 change: 1 addition & 0 deletions src/error/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { GraphQLError, printError, formatError } from './GraphQLError';
export type {
GraphQLErrorOptions,
GraphQLFormattedError,
GraphQLErrorExtensions,
} from './GraphQLError';
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ export {
} from './error/index';

export type {
GraphQLErrorOptions,
GraphQLFormattedError,
GraphQLErrorExtensions,
} from './error/index';
Expand Down