Interacting with GraphQL APIs
GraphQL APIs are web APIs that have a special language for interacting with them. These APIs are a very popular alternative to REST APIs with React frontends.
In this chapter, we’ll first understand the special GraphQL language, executing some basic queries on the GitHub GraphQL API. We will then build a React app that allows users to search for a GitHub repository and star it, experiencing the benefits of GraphQL over REST.
The app will use the browser’s fetch
function with React Query to interact with the GitHub GraphQL API. We will then refactor the implementation of the app to use a specialized GraphQL client called Apollo Client.
We’ll cover the following topics:
- Understanding the GraphQL syntax
- Getting set up
- Using the React Query with fetch
- Using Apollo Client