Skip to content

Commit 854e106

Browse files
authored
refactor: move errorPropagation to ValidatedExecutionArgs (#4531)
appropriate exposes the error propagation mode as part of the execution arguments, as the context (besides the reference to args) should only store mutable data
1 parent 946711a commit 854e106

2 files changed

Lines changed: 14 additions & 16 deletions

File tree

src/execution/entrypoints.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
} from '../language/ast.js';
1515
import { Kind } from '../language/kinds.js';
1616

17+
import { GraphQLDisableErrorPropagationDirective } from '../type/directives.js';
1718
import type {
1819
GraphQLFieldResolver,
1920
GraphQLTypeResolver,
@@ -378,6 +379,12 @@ export function validateExecutionArgs(
378379
return variableValuesOrErrors.errors;
379380
}
380381

382+
const errorPropagation =
383+
operation.directives?.find(
384+
(directive) =>
385+
directive.name.value === GraphQLDisableErrorPropagationDirective.name,
386+
) === undefined;
387+
381388
return {
382389
schema,
383390
fragmentDefinitions,
@@ -392,6 +399,7 @@ export function validateExecutionArgs(
392399
perEventExecutor: perEventExecutor ?? executeSubscriptionEvent,
393400
enableEarlyExecution: enableEarlyExecution === true,
394401
hideSuggestions,
402+
errorPropagation,
395403
abortSignal: args.abortSignal ?? undefined,
396404
};
397405
}

src/execution/execute.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ import {
3939
isNonNullType,
4040
isObjectType,
4141
} from '../type/definition.js';
42-
import {
43-
GraphQLDisableErrorPropagationDirective,
44-
GraphQLStreamDirective,
45-
} from '../type/directives.js';
42+
import { GraphQLStreamDirective } from '../type/directives.js';
4643
import type { GraphQLSchema } from '../type/schema.js';
4744

4845
import {
@@ -153,6 +150,7 @@ export interface ValidatedExecutionArgs {
153150
) => PromiseOrValue<ExecutionResult>;
154151
enableEarlyExecution: boolean;
155152
hideSuggestions: boolean;
153+
errorPropagation: boolean;
156154
abortSignal: AbortSignal | undefined;
157155
}
158156

@@ -162,7 +160,6 @@ export interface ExecutionContext {
162160
abortSignalListener: AbortSignalListener | undefined;
163161
completed: boolean;
164162
earlyReturns: Map<StreamRecord, () => Promise<unknown>> | undefined;
165-
errorPropagation: boolean;
166163
}
167164

168165
interface IncrementalContext {
@@ -183,15 +180,6 @@ interface GraphQLWrappedResult<T> {
183180
incrementalDataRecords: Array<IncrementalDataRecord> | undefined;
184181
}
185182

186-
function errorPropagation(operation: OperationDefinitionNode): boolean {
187-
const directiveNode = operation.directives?.find(
188-
(directive) =>
189-
directive.name.value === GraphQLDisableErrorPropagationDirective.name,
190-
);
191-
192-
return directiveNode === undefined;
193-
}
194-
195183
export function experimentalExecuteQueryOrMutationOrSubscriptionEvent(
196184
validatedExecutionArgs: ValidatedExecutionArgs,
197185
): PromiseOrValue<ExecutionResult | ExperimentalIncrementalExecutionResults> {
@@ -204,7 +192,6 @@ export function experimentalExecuteQueryOrMutationOrSubscriptionEvent(
204192
: undefined,
205193
completed: false,
206194
earlyReturns: undefined,
207-
errorPropagation: errorPropagation(validatedExecutionArgs.operation),
208195
};
209196
try {
210197
const {
@@ -763,7 +750,10 @@ function handleFieldError(
763750

764751
// If the field type is non-nullable, then it is resolved without any
765752
// protection from errors, however it still properly locates the error.
766-
if (exeContext.errorPropagation && isNonNullType(returnType)) {
753+
if (
754+
exeContext.validatedExecutionArgs.errorPropagation &&
755+
isNonNullType(returnType)
756+
) {
767757
throw error;
768758
}
769759

0 commit comments

Comments
 (0)