IssueRaiser

GraphQL error handling in Relay Modern

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 `<QueryRenderer>` 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?

Posted by taion on Jun 23, 2017, 9:54 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.4,500 issues0 comments

github (Network)

GraphQL error handling in Relay Modern

taionJun 23, 2017, 9:54 PM

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 `<QueryRenderer>` 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?

Comments (0)

No comments yet. Start the discussion.

Comment on this issue