Skip to content

Commit fa81898

Browse files
committed
Expose GraphQLErrorOptions type (graphql#3554)
1 parent 23dba4e commit fa81898

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

src/error/GraphQLError.ts

+14-12
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface GraphQLErrorExtensions {
2020
[attributeName: string]: unknown;
2121
}
2222

23-
export interface GraphQLErrorArgs {
23+
export interface GraphQLErrorOptions {
2424
nodes?: ReadonlyArray<ASTNode> | ASTNode | null;
2525
source?: Maybe<Source>;
2626
positions?: Maybe<ReadonlyArray<number>>;
@@ -30,17 +30,19 @@ export interface GraphQLErrorArgs {
3030
}
3131

3232
type BackwardsCompatibleArgs =
33-
| [args?: GraphQLErrorArgs]
33+
| [options?: GraphQLErrorOptions]
3434
| [
35-
nodes?: GraphQLErrorArgs['nodes'],
36-
source?: GraphQLErrorArgs['source'],
37-
positions?: GraphQLErrorArgs['positions'],
38-
path?: GraphQLErrorArgs['path'],
39-
originalError?: GraphQLErrorArgs['originalError'],
40-
extensions?: GraphQLErrorArgs['extensions'],
35+
nodes?: GraphQLErrorOptions['nodes'],
36+
source?: GraphQLErrorOptions['source'],
37+
positions?: GraphQLErrorOptions['positions'],
38+
path?: GraphQLErrorOptions['path'],
39+
originalError?: GraphQLErrorOptions['originalError'],
40+
extensions?: GraphQLErrorOptions['extensions'],
4141
];
4242

43-
function toNormalizedArgs(args: BackwardsCompatibleArgs): GraphQLErrorArgs {
43+
function toNormalizedOptions(
44+
args: BackwardsCompatibleArgs,
45+
): GraphQLErrorOptions {
4446
const firstArg = args[0];
4547
if (firstArg == null || 'kind' in firstArg || 'length' in firstArg) {
4648
return {
@@ -111,9 +113,9 @@ export class GraphQLError extends Error {
111113
*/
112114
readonly extensions: GraphQLErrorExtensions;
113115

114-
constructor(message: string, args?: GraphQLErrorArgs);
116+
constructor(message: string, options?: GraphQLErrorOptions);
115117
/**
116-
* @deprecated Please use the `GraphQLErrorArgs` constructor overload instead.
118+
* @deprecated Please use the `GraphQLErrorOptions` constructor overload instead.
117119
*/
118120
constructor(
119121
message: string,
@@ -126,7 +128,7 @@ export class GraphQLError extends Error {
126128
);
127129
constructor(message: string, ...rawArgs: BackwardsCompatibleArgs) {
128130
const { nodes, source, positions, path, originalError, extensions } =
129-
toNormalizedArgs(rawArgs);
131+
toNormalizedOptions(rawArgs);
130132
super(message);
131133

132134
this.name = 'GraphQLError';

src/error/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export { GraphQLError, printError, formatError } from './GraphQLError';
22
export type {
3+
GraphQLErrorOptions,
34
GraphQLFormattedError,
45
GraphQLErrorExtensions,
56
} from './GraphQLError';

src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ export {
392392
} from './error/index';
393393

394394
export type {
395+
GraphQLErrorOptions,
395396
GraphQLFormattedError,
396397
GraphQLErrorExtensions,
397398
} from './error/index';

0 commit comments

Comments
 (0)