apollo-error-catcher
It is used as higher order component to catch apollo graphql error in a generic manner.
Usage:
It is to wrap the react component which is using apollo-react to call graphql query. If there is any unhandled apollo error, it would catch the error and return a component which is readable for user instead of a red error page.
Installation:
You could install this package via following command
npm install apollo-error-catcher
Example:
We need to prepare our own Error Component for unhandled apollo error case.
; Component { return <p>not found</p> } ;
In our react component which is using react-apollo to query. We import catchGraphqlError from apollo-error-catcher and the error component we have made above. We would wrap our component by catchGraphqlError
;;;;;;; Component static propTypes = email: PropTypesstring isTested: PropTypesbool testAction: PropTypesfunc ; { superprops; } { return <div> !thispropsdataloading && <p>thispropsdatafindUserByEmailemail</p> </div> } const getUserQuery = gql` query($email:String!) { findUserByEmail(email: $email) { _id email } }`; const getUser = ; const mapStateToProps = ...; const mapDispatchToProps = ...; getUser ;
In case there is any error returned, e.g. network error. Error component would be shown instead