Apollo Server is an open source and GraphQL spec-compliant server developed by the Apollo platform for building GraphQL APIs. We can use it standalone or with other Node.js web frameworks such as Express, Koa, Hapi, and so on. We will use Apollo Server as it is in this book, but if you want to use it with other frameworks, please visit https://github.com/apollographql/apollo-serverinstallation-integrations.
In this GraphQL API, we will create a server that queries a collection of books by title and author. Let's get started:
- Install Apollo Server and GraphQL.js via npm as the project dependencies:
$ npm i apollo-server
$ npm i graphql
- Create an index.js file in the project root directory and import the ApolloServer and gql functions from the apollo-server package:
// index.js
const { ApolloServer, gql } = require('apollo-server')
The gql function is used to parse GraphQL operations and the schema language by wrapping them...