Testing components that use GraphQL
In this section, you will learn how to test components that use GraphQL to consume API data. In Chapter 3, Testing Complex Components with React Testing Library, we learned how to test components that interacted with REST APIs. The same concept to test REST API consuming components also applies with GraphQL, but with a few differences. We will use the Table
component we tested in the Testing integrated components section of this chapter, only now the component will be refactored to receive data via the GraphQL server using Apollo Client
(https://www.apollographql.com/docs/react/).
We can look at the implementation details of the Table
component to understand how it interacts with GraphQL:
export const EMPLOYEES = gql` query GetEmployees { employees { id name department ...