Implementing a GraphQL API in a backend
We are now going to set up GraphQL in our existing blog application backend in addition to the REST API. Doing so will allow us to see how GraphQL compares to and differs from a REST API. Follow these steps to get started setting up GraphQL on the backend:
- Copy the existing
ch10folder to a newch11folder, as follows:$ cp -R ch10 ch11
- Open the
ch11folder in VS Code. - First, let’s install a VS Code extension to add GraphQL language support. Go to the Extensions tab and search for the
GraphQL.vscode-graphqlextension developed by the GraphQL Foundation. Install the extension. - Next, install the
graphqland@apollo/serverlibraries in the backend using the following commands:$ cd backend/ $ npm install graphql@16.8.1 @apollo/server@4.10.0
Apollo Server is a production-ready GraphQL server implementation that supports multiple backend web frameworks, including Express.
- Create a new
backend/src/graphql/folder. Inside it...