Relay Error Handling
GraphQL WG Monthly - September 2023
Itamar Kestenbaum
Meta
Ryan Holdren
Meta
Jordan Eldredge
Meta
Tianyu Yao
Meta
Agenda
Why Relay Error Handling?�
Relay Error Handling�
Interop with Other Features�
Progress
01 Why Relay Error Handling?
Current State
01 WHY RELAY ERROR HANDLING?
A feature of GraphQL is that it coalesces errors to null, providing errors as metadata instead of directly throwing exceptions at the network or query level.
The Problem
01 WHY RELAY ERROR HANDLING?
An ecosystem-wide tradeoff (because no GraphQL client has addressed this before):
The Current Options
01 WHY RELAY ERROR HANDLING?
Essentially, this leaves users with a choice between:
Other Significant Side-Effects
01 WHY RELAY ERROR HANDLING?
02 Relay Error Handling
Default: field errors throw
02 RELAY ERROR HANDLING
@catch directive
02 RELAY ERROR HANDLING
Note: @catch is still in design phase, but this is our current approach
@catch directive - catching
02 RELAY ERROR HANDLING
Query
GraphQL Response
Relay Response
@catch directive - catching at parent
02 RELAY ERROR HANDLING
Query
GraphQL Response
Relay Response
@catch directive - opting back into null
02 RELAY ERROR HANDLING
Query
GraphQL Response
Relay Response
Positive side effects
02 RELAY ERROR HANDLING
03 Interop with other features
@required
03 INTEROP WITH OTHER FEATURES
The @required directive can be added to fields in your Relay queries to declare how null values should be handled at runtime. You can think of it as saying "if this field is ever null, its parent field is invalid and should be null".
Client-Controlled Nullability (CCN)
03 INTEROP WITH OTHER FEATURES
04 Progress
Progress
04 PROGRESS
tysm