Skip to content

Commit 2113676

Browse files
committed
Rename errorBehavior to onError and NULL to NO_PROPAGATE
1 parent f464644 commit 2113676

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

src/execution/execute.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export interface ExecutionContext {
116116
typeResolver: GraphQLTypeResolver<any, any>;
117117
subscribeFieldResolver: GraphQLFieldResolver<any, any>;
118118
errors: Array<GraphQLError>;
119-
errorBehavior: 'PROPAGATE' | 'NULL' | 'ABORT';
119+
errorBehavior: 'PROPAGATE' | 'NO_PROPAGATE' | 'ABORT';
120120
}
121121

122122
/**
@@ -155,14 +155,14 @@ export interface ExecutionArgs {
155155
typeResolver?: Maybe<GraphQLTypeResolver<any, any>>;
156156
subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
157157
/**
158-
* Experimental. Set to NULL to prevent error propagation. Set to ABORT to
158+
* Experimental. Set to NO_PROPAGATE to prevent error propagation. Set to ABORT to
159159
* abort a request when any error occurs.
160160
*
161161
* Default: PROPAGATE
162162
*
163163
* @experimental
164164
*/
165-
errorBehavior?: 'PROPAGATE' | 'NULL' | 'ABORT';
165+
onError?: 'PROPAGATE' | 'NO_PROPAGATE' | 'ABORT';
166166
}
167167

168168
/**
@@ -297,9 +297,22 @@ export function buildExecutionContext(
297297
fieldResolver,
298298
typeResolver,
299299
subscribeFieldResolver,
300-
errorBehavior,
300+
onError,
301301
} = args;
302302

303+
if (
304+
onError != null &&
305+
onError !== 'PROPAGATE' &&
306+
onError !== 'NO_PROPAGATE' &&
307+
onError !== 'ABORT'
308+
) {
309+
return [
310+
new GraphQLError(
311+
'Unsupported `onError` value; supported values are `PROPAGATE`, `NO_PROPAGATE` and `ABORT`.',
312+
),
313+
];
314+
}
315+
303316
let operation: OperationDefinitionNode | undefined;
304317
const fragments: ObjMap<FragmentDefinitionNode> = Object.create(null);
305318
for (const definition of document.definitions) {
@@ -359,7 +372,7 @@ export function buildExecutionContext(
359372
typeResolver: typeResolver ?? defaultTypeResolver,
360373
subscribeFieldResolver: subscribeFieldResolver ?? defaultFieldResolver,
361374
errors: [],
362-
errorBehavior: errorBehavior ?? 'PROPAGATE',
375+
errorBehavior: onError ?? 'PROPAGATE',
363376
};
364377
}
365378

@@ -618,7 +631,7 @@ function handleFieldError(
618631
} else if (exeContext.errorBehavior === 'ABORT') {
619632
// In this mode, any error aborts the request
620633
throw error;
621-
} else if (exeContext.errorBehavior === 'NULL') {
634+
} else if (exeContext.errorBehavior === 'NO_PROPAGATE') {
622635
// In this mode, the client takes responsibility for error handling, so we
623636
// treat the field as if it were nullable.
624637
} else {

src/graphql.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ export interface GraphQLArgs {
6767
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
6868
typeResolver?: Maybe<GraphQLTypeResolver<any, any>>;
6969
/**
70-
* Experimental. Set to NULL to prevent error propagation. Set to ABORT to
70+
* Experimental. Set to NO_PROPAGATE to prevent error propagation. Set to ABORT to
7171
* abort a request when any error occurs.
7272
*
7373
* Default: PROPAGATE
7474
*
7575
* @experimental
7676
*/
77-
errorBehavior?: 'PROPAGATE' | 'NULL' | 'ABORT';
77+
onError?: 'PROPAGATE' | 'NO_PROPAGATE' | 'ABORT';
7878
}
7979

8080
export function graphql(args: GraphQLArgs): Promise<ExecutionResult> {
@@ -115,7 +115,7 @@ function graphqlImpl(args: GraphQLArgs): PromiseOrValue<ExecutionResult> {
115115
operationName,
116116
fieldResolver,
117117
typeResolver,
118-
errorBehavior,
118+
onError,
119119
} = args;
120120

121121
// Validate Schema
@@ -148,6 +148,6 @@ function graphqlImpl(args: GraphQLArgs): PromiseOrValue<ExecutionResult> {
148148
operationName,
149149
fieldResolver,
150150
typeResolver,
151-
errorBehavior,
151+
onError,
152152
});
153153
}

src/type/definition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ export interface GraphQLResolveInfo {
10971097
readonly operation: OperationDefinitionNode;
10981098
readonly variableValues: { [variable: string]: unknown };
10991099
/** @experimental */
1100-
readonly errorBehavior: 'PROPAGATE' | 'NULL' | 'ABORT';
1100+
readonly errorBehavior: 'PROPAGATE' | 'NO_PROPAGATE' | 'ABORT';
11011101
}
11021102

11031103
/**

0 commit comments

Comments
 (0)