Skip to content

Commit

Permalink
Expose GraphQLErrorOptions type (#3554)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed May 3, 2022
1 parent ea1c347 commit c8aceb5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/error/GraphQLError.ts
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
@@ -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
Expand Up @@ -392,6 +392,7 @@ export {
} from './error/index';

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

0 comments on commit c8aceb5

Please sign in to comment.