Skip to content

Commit 726b4ba

Browse files
committed
Elevate ErrorBehavior to be a specified enum
1 parent 0f0a31c commit 726b4ba

23 files changed

+131
-68
lines changed

src/__tests__/starWarsIntrospection-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('Star Wars Introspection Tests', () => {
3737
{ name: 'Droid' },
3838
{ name: 'Query' },
3939
{ name: 'Boolean' },
40-
{ name: '__ErrorBehavior' },
40+
{ name: 'ErrorBehavior' },
4141
{ name: '__Schema' },
4242
{ name: '__Type' },
4343
{ name: '__TypeKind' },

src/error/ErrorBehavior.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
export type GraphQLErrorBehavior = 'NO_PROPAGATE' | 'PROPAGATE' | 'ABORT';
1+
export type ErrorBehavior = 'NO_PROPAGATE' | 'PROPAGATE' | 'ABORT';
22

3-
export function isErrorBehavior(
4-
onError: unknown,
5-
): onError is GraphQLErrorBehavior {
3+
export function isErrorBehavior(onError: unknown): onError is ErrorBehavior {
64
return (
75
onError === 'NO_PROPAGATE' || onError === 'PROPAGATE' || onError === 'ABORT'
86
);

src/error/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ export type {
99
export { syntaxError } from './syntaxError';
1010

1111
export { locatedError } from './locatedError';
12-
export type { GraphQLErrorBehavior } from './ErrorBehavior';
12+
export type { ErrorBehavior } from './ErrorBehavior';

src/execution/execute.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { promiseForObject } from '../jsutils/promiseForObject';
1313
import type { PromiseOrValue } from '../jsutils/PromiseOrValue';
1414
import { promiseReduce } from '../jsutils/promiseReduce';
1515

16-
import type { GraphQLErrorBehavior } from '../error/ErrorBehavior';
16+
import type { ErrorBehavior } from '../error/ErrorBehavior';
1717
import { isErrorBehavior } from '../error/ErrorBehavior';
1818
import type { GraphQLFormattedError } from '../error/GraphQLError';
1919
import { GraphQLError } from '../error/GraphQLError';
@@ -117,7 +117,7 @@ export interface ExecutionContext {
117117
typeResolver: GraphQLTypeResolver<any, any>;
118118
subscribeFieldResolver: GraphQLFieldResolver<any, any>;
119119
errors: Array<GraphQLError>;
120-
errorBehavior: GraphQLErrorBehavior;
120+
errorBehavior: ErrorBehavior;
121121
}
122122

123123
/**
@@ -133,7 +133,6 @@ export interface ExecutionResult<
133133
> {
134134
errors?: ReadonlyArray<GraphQLError>;
135135
data?: TData | null;
136-
onError?: GraphQLErrorBehavior;
137136
extensions?: TExtensions;
138137
}
139138

@@ -164,7 +163,7 @@ export interface ExecutionArgs {
164163
*
165164
* @experimental
166165
*/
167-
onError?: GraphQLErrorBehavior;
166+
onError?: ErrorBehavior;
168167
/** Additional execution options. */
169168
options?: {
170169
/** Set the maximum number of errors allowed for coercing (defaults to 50). */

src/graphql.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { isPromise } from './jsutils/isPromise';
33
import type { Maybe } from './jsutils/Maybe';
44
import type { PromiseOrValue } from './jsutils/PromiseOrValue';
55

6-
import type { GraphQLErrorBehavior } from './error/ErrorBehavior';
6+
import type { ErrorBehavior } from './error/ErrorBehavior';
77

88
import { parse } from './language/parser';
99
import type { Source } from './language/source';
@@ -76,7 +76,7 @@ export interface GraphQLArgs {
7676
*
7777
* @experimental
7878
*/
79-
onError?: GraphQLErrorBehavior;
79+
onError?: ErrorBehavior;
8080
}
8181

8282
export function graphql(args: GraphQLArgs): Promise<ExecutionResult> {

src/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ export {
5555
GraphQLString,
5656
GraphQLBoolean,
5757
GraphQLID,
58+
// Standard GraphQL Enums
59+
specifiedEnumTypes,
60+
GraphQLErrorBehavior,
5861
// Int boundaries constants
5962
GRAPHQL_MAX_INT,
6063
GRAPHQL_MIN_INT,
@@ -79,7 +82,6 @@ export {
7982
__InputValue,
8083
__EnumValue,
8184
__TypeKind,
82-
__ErrorBehavior,
8385
// Meta-field definitions.
8486
SchemaMetaFieldDef,
8587
TypeMetaFieldDef,
@@ -107,6 +109,7 @@ export {
107109
isRequiredArgument,
108110
isRequiredInputField,
109111
isSpecifiedScalarType,
112+
isSpecifiedEnumType,
110113
isIntrospectionType,
111114
isSpecifiedDirective,
112115
// Assertions
@@ -396,7 +399,7 @@ export {
396399
} from './error/index';
397400

398401
export type {
399-
GraphQLErrorBehavior,
402+
ErrorBehavior,
400403
GraphQLErrorOptions,
401404
GraphQLFormattedError,
402405
GraphQLErrorExtensions,

src/type/__tests__/introspection-test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ describe('Introspection', () => {
102102
inputFields: null,
103103
interfaces: null,
104104
kind: 'ENUM',
105-
name: '__ErrorBehavior',
105+
name: 'ErrorBehavior',
106106
possibleTypes: null,
107107
specifiedByURL: null,
108108
},
@@ -213,7 +213,7 @@ describe('Introspection', () => {
213213
name: null,
214214
ofType: {
215215
kind: 'ENUM',
216-
name: '__ErrorBehavior',
216+
name: 'ErrorBehavior',
217217
ofType: null,
218218
},
219219
},
@@ -1059,7 +1059,7 @@ describe('Introspection', () => {
10591059
name: null,
10601060
ofType: {
10611061
kind: 'ENUM',
1062-
name: '__ErrorBehavior',
1062+
name: 'ErrorBehavior',
10631063
ofType: null,
10641064
},
10651065
},

src/type/__tests__/predicate-test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import {
6565
isDirective,
6666
isSpecifiedDirective,
6767
} from '../directives';
68+
import { GraphQLErrorBehavior, isSpecifiedEnumType } from '../enums';
6869
import {
6970
GraphQLBoolean,
7071
GraphQLFloat,
@@ -166,6 +167,16 @@ describe('Type predicates', () => {
166167
});
167168
});
168169

170+
describe('isSpecifiedEnumType', () => {
171+
it('returns true for specified enums', () => {
172+
expect(isSpecifiedEnumType(GraphQLErrorBehavior)).to.equal(true);
173+
});
174+
175+
it('returns false for custom scalar', () => {
176+
expect(isSpecifiedEnumType(EnumType)).to.equal(false);
177+
});
178+
});
179+
169180
describe('isObjectType', () => {
170181
it('returns true for object type', () => {
171182
expect(isObjectType(ObjectType)).to.equal(true);

src/type/__tests__/schema-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ describe('Type System: Schema', () => {
296296
'ASub',
297297
'Boolean',
298298
'String',
299-
'__ErrorBehavior',
299+
'ErrorBehavior',
300300
'__Schema',
301301
'__Type',
302302
'__TypeKind',

src/type/definition.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type { PromiseOrValue } from '../jsutils/PromiseOrValue';
1414
import { suggestionList } from '../jsutils/suggestionList';
1515
import { toObjMap } from '../jsutils/toObjMap';
1616

17-
import type { GraphQLErrorBehavior } from '../error/ErrorBehavior';
17+
import type { ErrorBehavior } from '../error/ErrorBehavior';
1818
import { GraphQLError } from '../error/GraphQLError';
1919

2020
import type {
@@ -990,7 +990,7 @@ export interface GraphQLResolveInfo {
990990
readonly operation: OperationDefinitionNode;
991991
readonly variableValues: { [variable: string]: unknown };
992992
/** @experimental */
993-
readonly errorBehavior: GraphQLErrorBehavior;
993+
readonly errorBehavior: ErrorBehavior;
994994
}
995995

996996
/**

0 commit comments

Comments
 (0)