react-apollo-hooks
react-apollo-hooks copied to clipboard
handling server side graphql errors without suspense
with getDataFromTree you could wrap the call in a try-catch block to prevent graphql errors from crashing app, since you could still render the html markup
but since getDataFromMarkup combines fetching data and rendering html, how should server side graphql errros be handled if you're not yet using suspense?
@alidcastano you should be able to wrap getDataFromMarkup in a try-catch block. This snippet should work:
try {
await getMarkupFromTree({ tree, renderFunction: renderToString });
} catch (error) {
// ...
}
yea but since the getMarkupFromTree also renders the markup, if it fails then you can't render the app. ideally graphql errors wouldn't cause it to fail, that's how I've usually seen it handled i.e. in Nextjs hocs
Yes, good catch. It seems our implementation of getMarkupFromTree is incompatible with the one in react-apollo: https://github.com/apollographql/react-apollo/blob/6a02550db2b14881582ede2c4e1a3e1ef51f0b7a/test/client/getDataFromTree.test.tsx#L1572. We should change this behavior.
@trojanowski yea it'd be great if react-apollo-hooks implementation could be compatible so that we can handle errors in the app itself (rather than having to deal with the error / restart the response in the server middleware)
so would it be OK to remove this snippet here? https://github.com/trojanowski/react-apollo-hooks/blob/master/src/getMarkupFromTree.tsx#L32-L34
and let end user decide how they want to handle non-suspense errors