Interfacing with GraphQL on the Frontend Using Apollo Client
After successfully implementing a GraphQL backend using Apollo Server in the previous chapter, we are now going to interface with our new GraphQL API on the frontend using Apollo Client. Apollo Client is a library that makes it easier and more convenient to interact with GraphQL APIs. We’ll start by replacing the fetching of the post list with GraphQL queries, then resolve the author usernames without needing extra queries, showing the power of GraphQL. Next, we’ll add variables to the query to allow setting filters and sorting options. Finally, we’ll learn how to use mutations on the frontend.
In this chapter, we are going to cover the following main topics:
- Setting up Apollo Client and making our first query
- Using variables in GraphQL queries
- Using mutations on the frontend