Skip to content

Relay Error Handling Project #4416

Open
@itamark

Description

@itamark

Relay Error Handling Project

TL;DR

We are proposing a way for engineers to have a safer, more controlled approach to handling GraphQL field errors in Relay.
The proposal includes the ability to specify how you want errors to be handled on fields - potentially including throwing, returning the error along with successful fields, and an option to preserve the current behavior.
These changes are meant to prevent inaccurate client behavior in cases where an error occurs on a field server-side, as well as more granular control over a user’s experience when something does go wrong.

Problem

A feature of GraphQL is that it coalesces errors to null, providing errors as metadata instead of directly throwing exceptions at the network level. Here are some issues that arise from this behavior:
An ecosystem-wide tradeoff (ecosystem-wide because no GraphQL client has addressed this before):

  • Discard queries with errors or,
  • Not be able to discern whether a null is error or not

Essentially, this leaves users with a choice between:

  • Robustness: meaning, “render at all costs” - so if one field errors, everything still returns and that field is null, or
    • This choice leaves users unable to delineate between errors and true nulls.
    • Users also forget that this is how Relay works - even after they’ve learned about it - and fail to account for that edge case.
  • Correctness: meaning, if something errors, the query throws and nothing is rendered - so that partially incorrect info never shows.

An additional severe pitfall is that some client-side data could write back incorrect info to the server. So if a field errors and is coalesced to 0 (from null) - it could potentially write back incorrect data to the server.

Our Proposed Solution

We are planning on introducing the ability to define how you want an erroring field to behave - giving users the flexibility to either define the existing behavior (return null upon server error), throw entirely (essentially rethrowing the server error client-side, to be handled by error boundaries for instance), or provided the error in the response to be handled separately.

We are currently working on ironing out implementation details, ergonomics, and addressing known edge-cases.
It’s important to note that we are taking performance and other concerns seriously.

You can expect to see more details on this project as our design solidifies, and we welcome any comments or questions here.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions