RFC 0 / Strawman

SemanticNonNull type (null only on error)

Opened on
Updated on

At a glance

Project
GraphQL Spec
Identifier
#1065
Stage
RFC 0 / Strawman
Champion
@benjie
Updated
2026-03-19
Latest activity
Marked as Stale on
Source
Related RFCs

Pull request description

TL;DR: Introduces a new type wrapper, Semantic-Non-Null, which represents that a value will not be null unless an error happens, and if an error does happen then this null does not bubble.

GraphQL.js implementation: https://github.com/graphql/graphql-js/pull/4192

The problem

GraphQL schema designers must use non-nullable types sparingly because if a non-nullable type were to raise an error then the entire selection set it is within will be destroyed, leading to clients receiving less usable data and making writing the results to a normalized cache a dangerous action. Because of this, nullable-by-default is a best practice in GraphQL, and non-null type wrappers should only be used for fields that the schema designer is confident will never raise an error - not just in the current schema, but in all future schemas.

Many GraphQL consumers choose to ignore the entire response from the server when any error happens, one reason for this is because the null bubbling behavior makes writing to normalized caches dangerous. For these users, when an error doesn't happen, the nullable fields they are dealing with can be frustrating because their type generation requires them to handle the null case even if it may never happen in practice, which can lead to a lot of unnecessary code that will never execute. There is currently no way for the type generators to know that a field will never be null unless there's an associated error.

The solution

We can categorise that there are effectively two types of null:

  • Error null: where a position is null and there's a related error (with matching or prefixed path) in the errors list - indicates that something went wrong.
  • Semantic null: where a position is null and there is no related error - this data truly is null (e.g. a user having not yet set their avatar may have avatar: null; this is not an error).

This PR introduces a new wrapper type in addition to List and Non-Null, called Semantic-Non-Null. The Semantic-Non-Null type indicates that the field will never be a semantic null - it will not be null in the normal course of business, but can be null only if accompanied by an error in the errors list (i.e. an "error null"). Thus a client that throws out all responses with errors will never see a null in this position. Also, critically, any null raised by this field will not bubble and thus if an error is found with the exact path to this null then it is safe to store the result (including the error) into a normalized cache.

In SDL the Semantic-Non-Null wrapper is currently represented by an asterisk (*) suffix (as opposed to the ! suffix for a strict Non-Null).

Thus we have the following:

#Type descriptionSyntaxResult values
1Unadorned StringStringstring, or error null, or semantic null
2Semantic-Non-Null StringString*string, or error null
3(Strict-)Non-Null StringString!string

Note that 1 and 3 above are exactly the same as in the current GraphQL specification, this PR introduces 2 which sits in the middle.

Backwards compatibility

All existing schemas are automatically supported because the meaning of String and String! is unchanged.

To ensure that all existing clients are automatically supported, this PR introduces the includeSemanticNonNull argument on __Field.type which defaults to false. Clients that do not pass includeSemanticNonNull: true will see all Semantic-Non-Null types stripped, which will have the effect of making them appear as if they were the unadorned types. This is safe, since it means these clients will need to handle both error nulls and semantic nulls (as they traditionally would have) even though we know that a semantic null will never happen in practice.

All existing GraphQL documentation, tutorials, examples, and everything else we've built over the last 8 years remains valid since the meaning of String and String! are unchanged.

History

This PR is almost identical to #1048, but it changes the name of the new type wrapper from Null-Only-On-Error to Semantic-Non-Null. It addresses the True Nullability Schema discussion raised by @captbaritone and incorporates/adapts some of the terminology from @leebyron's Strict Semantic Nullability proposal.

Timeline

March 2026

May 2025

April 2025

  • Discussed in GraphQL WG

    The GraphQL working group meeting focused on the importance of the membership agreement, participation and contribution guidelines, and code of conduct, with a round of introductions and an extensive agenda. The group discussed changes to the GraphQL specification regarding terminology and error handling, refactoring the execution algorithms, and the nullability working group's consensus on disabling null propagation. They also considered various approaches to handling nullability and error management in GraphQL schemas, with a preference for directive-based solutions over syntax changes.

    Zoom summary · GraphQL WG · 2025-04-03
    Next Steps

    All attendees to review and provide feedback on the nullability proposals (solutions 1, 6, and 7) presented by Alex.

    Zoom summary · GraphQL WG · 2025-04-03
    Next Steps

    Nullability working group to develop user stories for tooling compatibility with the asterisk syntax proposal.

    Zoom summary · GraphQL WG · 2025-04-03
    Next Steps

    Nullability working group to develop user stories for code-first shops regarding the nullability proposals.

    Zoom summary · GraphQL WG · 2025-04-03

    The Nullability working group discusses three potential solutions to address the nullability problem in GraphQL. Solution 1 introduces an asterisk syntax for semantic nullability, seen as a transitional type. Solution 6 uses a directive instead of new syntax for semantic nullability. Solution 7 proposes removing null propagation entirely and adding a "propagate error" directive to existing non-null fields. All solutions aim for the same end state, differing mainly in the transition approach. The group considers the trade-offs between introducing new syntax, backward compatibility, and ease of implementation. They also discuss the importance of making a decision, as maintaining the status quo is not without cost.

    Zoom summary · GraphQL WG · 2025-04-03

    The group discusses various approaches to handling nullability and error management in GraphQL schemas. They consider solutions involving new syntax (like asterisks) and directives. The main concerns are backward compatibility, tooling support, and migration paths. Participants express preferences for directive-based solutions (6 and 7) over syntax changes. Key issues to address include figuring out user stories for tooling with the asterisk approach and for code-first shops. The group also discusses several other pull requests that need review before the next spec cut. Martin's "include deprecated" proposal is advanced to RFC2, pending confirmation that it won't cause issues for Facebook's implementation.

    Zoom summary · GraphQL WG · 2025-04-03

March 2025

February 2025

October 2024

January 2024

November 2023

October 2023