facebook / facebook/relay

GraphQL error handling in Relay Modern

Open
#1,913 38 comments 64 reactions 0 assignees View on GitHub
wontfix
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

I think error handling is a little bit weird.

Contra the example in https://facebook.github.io/relay/docs/network-layer.html, it looks like I need to actually `throw` an `Error` in the event that there are any query errors. I can't just pass through the `graphql` object with the `errors` property.

This is because in https://github.com/facebook/relay/blob/v1.1.0/packages/relay-runtime/network/RelayNetwork.js#L197-L208, `normalizePayload` only throws an error if `data` is nully.

But the forward `throw` branch there is the only code path that will trigger `onError` for the request, and correspondingly the only path that will hit `onError` in `` per https://github.com/facebook/relay/blob/v1.1.0/packages/react-relay/modern/ReactRelayQueryRenderer.js#L205-L212.

Otherwise we hit `onNext` per https://github.com/facebook/relay/blob/v1.1.0/packages/react-relay/modern/ReactRelayQueryRenderer.js#L229, and will always set `error: null` on the `readyState` that gets passed to the `render` callback.

This is weird. Am I missing something, or are things supposed to work this way?

Contributor guide

Open the contributing guide

Research direction

Review packages/relay-runtime/network/RelayNetwork.js around lines 197-208 and packages/react-relay/modern/ReactRelayQueryRenderer.js around lines 205-212 and 229. Compare those paths with the network-layer documentation linked in the issue, then determine the expected callback and readyState behavior for GraphQL responses containing errors; confirm the result with relevant tests if available.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, javascript, react
Domain
api, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.