Skip to content

Commit

Permalink
Rename to @experimental_disableErrorPropagation
Browse files Browse the repository at this point in the history
  • Loading branch information
martinbonnin committed Feb 21, 2025
1 parent 6409cf6 commit f96492c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 142 deletions.
93 changes: 0 additions & 93 deletions src/execution/__tests__/onerror-test.ts

This file was deleted.

10 changes: 6 additions & 4 deletions src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ import {
isObjectType,
} from '../type/definition.js';
import {
ErrorAction,
GraphQLOnErrorDirective,
GraphQLDisableErrorPropagationDirective,
GraphQLStreamDirective,
} from '../type/directives.js';
import type { GraphQLSchema } from '../type/schema.js';
Expand Down Expand Up @@ -320,9 +319,12 @@ export function executeQueryOrMutationOrSubscriptionEvent(
}

function errorPropagation(operation: OperationDefinitionNode): boolean {
const value = getDirectiveValues(GraphQLOnErrorDirective, operation);
const directiveNode = operation.directives?.find(
(directive) =>
directive.name.value === GraphQLDisableErrorPropagationDirective.name,
);

return value?.action !== ErrorAction.NULL;
return directiveNode === undefined;
}

export function experimentalExecuteQueryOrMutationOrSubscriptionEvent(
Expand Down
50 changes: 5 additions & 45 deletions src/type/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,14 @@ import { toObjMapWithSymbols } from '../jsutils/toObjMap.js';

import type { DirectiveDefinitionNode } from '../language/ast.js';
import { DirectiveLocation } from '../language/directiveLocation.js';
import { Kind } from '../language/kinds.js';

import { assertName } from './assertName.js';
import type {
GraphQLArgumentConfig,
GraphQLFieldNormalizedConfigArgumentMap,
GraphQLSchemaElement,
} from './definition.js';
import {
GraphQLArgument,
GraphQLEnumType,
GraphQLNonNull,
} from './definition.js';
import { GraphQLArgument, GraphQLNonNull } from './definition.js';
import { GraphQLBoolean, GraphQLInt, GraphQLString } from './scalars.js';

/**
Expand Down Expand Up @@ -282,51 +277,16 @@ export const GraphQLOneOfDirective: GraphQLDirective = new GraphQLDirective({
});

/**
* Possible error handling actions.
* Disables error propagation (experimental).
*/
export const ErrorAction = {
PROPAGATE: 'PROPAGATE' as const,
NULL: 'NULL' as const,
} as const;

// eslint-disable-next-line @typescript-eslint/no-redeclare
export type ErrorAction = (typeof ErrorAction)[keyof typeof ErrorAction];

export const _ErrorAction = new GraphQLEnumType({
name: '_ErrorAction',
description: 'Possible error handling actions.',
values: {
PROPAGATE: {
value: ErrorAction.PROPAGATE,
description:
'Non-nullable positions that error cause the error to propagate to the nearest nullable ancestor position. The error is added to the "errors" list.',
},
NULL: {
value: ErrorAction.NULL,
description:
'Positions that error are replaced with a `null` and an error is added to the "errors" list.',
},
},
});

/**
* Controls how the executor handles errors.
*/
export const GraphQLOnErrorDirective = new GraphQLDirective({
name: 'onError',
description: 'Controls how the executor handles errors.',
export const GraphQLDisableErrorPropagationDirective = new GraphQLDirective({
name: 'experimental_disableErrorPropagation',
description: 'Disables error propagation.',
locations: [
DirectiveLocation.QUERY,
DirectiveLocation.MUTATION,
DirectiveLocation.SUBSCRIPTION,
],
args: {
action: {
type: new GraphQLNonNull(_ErrorAction),
description: 'The action to execute when a field error is encountered.',
default: { literal: { kind: Kind.ENUM, value: 'PROPAGATE' } },
},
},
});

/**
Expand Down

0 comments on commit f96492c

Please sign in to comment.