Apollo Client Error Handling in React
In this lesson, you will learn how to handle GraphQL errors and network errors when using Apollo Client in React.
We'll cover the following...
Before diving into GraphQL mutations in React with Apollo Client, this lesson should clarify error handling with Apollo in React.
The error handling happens on two levels:
- the application level
- query/mutation level
Both can be implemented with the two cases that follow. On a query level, in your Profile component, you have access to the query data and loading properties. Apart from these, you can also access the error object, which can be used to show a conditional error message.
Whereas the ErrorMessage component from the src/Error/index.js could look like the following:
If we now try to change the name of a field in our query to something not offered by GitHub’s GraphQL API, and observe what’s rendered in the browser. We should see something ...