Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose GraphQLErrorOptions type (#3554) #3565

Merged
merged 1 commit into from May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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