Designing a GraphQL API
In 2015, Facebook released a project meant to rival traditional web APIs and flip the concept of a RESTful web application on its head. This project is what we now know as GraphQL. This book has so far assumed that we are building out endpoints using the traditional method of combining HTTP methods with thoughtful paths to point to specific resources. In this approach, web servers are responsible for being the interface between a client and the source of data (for example, a database). The concept of GraphQL pushes all of that aside and allows the client to directly request what information it wants to receive. There is a single endpoint (usually /graphql
) and a single HTTP method (usually POST
). The single route definition is meant to be used for both retrieving data and causing state changes in the application. This all happens through a set of queries that are sent as the body on that single endpoint. GraphQL was meant to revolutionize the way we build the...