Deploying Apollo Server to ZEIT Now

Deploy Your Apollo GraphQL Server to ZEIT Now.

In this guide, we will be deploying an Apollo GraphQL server with ZEIT Now.

Getting Started

The first step is to create a directory for the project and cd into it via your terminal. It can be done with the following command:

mkdir -p apolloserver/api && cd apolloserver

Creating and entering into the /apolloserver directory which also contains an /api directory.

Next, initialize the project and install the apollo-server-micro and graphql packages via your terminal.

npm init -y && npm i apollo-server-micro graphql

Adding apollo-server-micro and graphql as dependencies to the project.

Once the dependencies are installed, go ahead and create an index.js file inside of the /api directory with the following code as its contents:

const { ApolloServer, gql } = require('apollo-server-micro')

const typeDefs = gql`
  type Query {
    hello: String
  }
`

const resolvers = {
  Query: {
    hello: (root, args, context) => {
      return 'Hello world!'
    }
  }
}

const server = new ApolloServer({
  typeDefs,
  resolvers,
  introspection: true,
  playground: true
})

module.exports = server.createHandler({ path: '/api' })

The code above shows a basic Apollo server with an enabled GraphQL playground for testing out queries.

Deploy with Now

With your project setup you are ready to deploy it with Now.

Deploying your project could not be easier and can be done with a single command:

now

Deploying the app with the now command.

Your project has now been deployed, you can access the Apollo Server endpoint, using the deployment URL generated, at /api.

If you want to deploy your ApolloServer project when you push to a Git repository, you can use either Now for GitHub or Now for GitLab to have your project automatically deployed on every push, and aliased on push to master.



Written By
Written by unicodeveloper, msweeneydevunicodeveloper, msweeneydev
on January 24th 2019