react-apollo-hooks icon indicating copy to clipboard operation
react-apollo-hooks copied to clipboard

handling server side graphql errors without suspense

Open alidcast opened this issue 6 years ago • 5 comments

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?

alidcast avatar Jan 26 '19 18:01 alidcast

@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) {
  // ...
}

trojanowski avatar Feb 22 '19 15:02 trojanowski

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

alidcast avatar Feb 22 '19 15:02 alidcast

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 avatar Feb 22 '19 16:02 trojanowski

@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)

alidcast avatar Feb 25 '19 02:02 alidcast

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

alidcast avatar Mar 09 '19 16:03 alidcast