Disable Error Propagation Directive
At a glanceβ
- Identifier: DisableErrorPropagationDirective
- Stage: RFC0: Strawman
- Champion: -
- PR: -
- Related:
- #1050 (Directive proposal for opting out of null bubbling)
Timelineβ
- RFC document created on 2025-03-19 by Alex Reilly
RFC: Disable Error Propagation Directive
Proposed by: Martin Bonnin
See also: Original proposal/spec edits by Benjie
Implementation PR: https://github.com/graphql/graphql-js/pull/4348
This RFC proposes adding a new directive
@disableErrorPropagationthat allows clients to disable error propagation for specific operations in their GraphQL queries.π Problem Statementβ
In GraphQL, nullability serves two distinct purposes:
- Semantic null: Indicating that a field can have a legitimate "null" value (e.g., a user without an avatar)
- Error handling: Allowing errors to propagate up through nullable parent fields
This coupling of nullability and errors makes it difficult for clients to distinguish between semantic nulls and error states by looking at the schema. When a field resolver throws an error and the field is non-nullable, the error propagates up through parent fields until it reaches a nullable field, potentially nullifying a large portion of the response.
While this behavior helps maintain data consistency guarantees, there are cases where clients may want more granular control over error propagation, particularly when partial data is preferable to no data.
Current Behaviorβ
Consider this schema:
type User {
id: ID!
name: String
posts: [Post!]!
optionalPosts: [Post!]
}
type Post {
id: ID!
title: String!
content: String
}If a resolver for
Post.titlethrows an error:
- The error is added to the
errorsarray in the response- Since
titleis non-nullable (String!), its parentPostobject must be null- Since the array items are non-nullable (
[Post!]), the entirepostsarray must be null- Since
postsis non-nullable ([Post!]!), its parentUserobject must be null- This continues up the response tree until reaching a nullable field
For the
optionalPostsfield, which is nullable ([Post!]), the propagation would stop at that field, setting it to null.This behavior ensures type safety but can lead to situations where a single error in a deeply nested non-nullable field causes a large portion of the response to be nullified, even when the remaining data might still be useful to the client.
Use Cases