9 Consuming GraphQL APIs

 

This chapter covers

  • Running a GraphQL mock server to test our API design
  • Using the GraphiQL client to explore and consume a GraphQL API
  • Running queries and mutations against a GraphQL API
  • Consuming a GraphQL API programmatically using cURL and Python

This chapter teaches you how to consume GraphQL APIs. As we learned in chapter 8, GraphQL offers a query language for web APIs, and in this chapter, you’ll learn how to use this language to run queries on the server. In particular, you’ll learn how to make queries against a GraphQL API. You’ll learn to explore a GraphQL API so that we can discover its available types, queries, and mutations. Understanding how GraphQL APIs work from the client side is a very important step towards mastering GraphQL.

Learning to interact with GraphQL APIs will help you learn to consume the APIs exposed by other vendors, it’ll let you run tests against your own APIs, and it’ll help you design better APIs. You’ll learn to use the GraphiQL client to explore and visualize a GraphQL API. As you’ll see, GraphiQL offers an interactive query panel that makes it easier to run queries on the server.

9.1 Running a GraphQL mock server

9.2 Introducing GraphQL queries

9.2.1 Running simple queries

9.2.2 Running queries with parameters

9.2.3 Understanding query errors

9.3 Using fragments in queries

9.4 Running queries with input parameters

9.5 Navigating the API graph

9.6 Running multiple queries and query aliasing

9.6.1 Running multiple queries in the same request

9.6.2 Aliasing our queries

9.7 Running GraphQL mutations

9.8 Running parametrized queries and mutations

9.9 Demystifying GraphQL queries

9.10 Calling a GraphQL API with Python code

9.11 Summary