Deploying Node to Heroku

How to configure and deploy your GraphQL server with Engine to Heroku

This section describes how to deploy your GraphQL service with production-ready Engine features. Before starting, make sure you have added Engine to your GraphQL server. If you haven’t built a GraphQL server yet, check out our tutorial first and then come back when you’re ready to deploy!

This guide is specifically made for Node GraphQL servers. For non-Node servers, we recommend using the launcher API which is a small Node script packaged with apollo-engine used to run Engine as a standalone proxy server.

1. Configure environment variables

Engine will get your API key from the ENGINE_API_KEY environment variable by default, so you just need to create an ApolloEngine with no options:

import { ApolloEngine } from 'apollo-engine';
const engine = new ApolloEngine();

The API key represents your service’s secret ID in Engine. To get one, log into the Engine UI and create a service.

Also, for Heroku we need to make sure to get the port for our application from an environment variable provided by Heroku:

// Set a default value of 3000 if we don't pass an env var
const PORT = process.env.PORT || 3000;

engine.listen({
  port: PORT,
  expressApp: app
}, () => {
  console.log(`Server running on port ${PORT}!`);
});

2. Create and set up a new Heroku application

Log into the Heroku dashboard. Then click “New” > “Create New App” in the top right

New App Screenshot

Name your app and hit “Create app”

Create App Screenshot

Select a deployment method. GitHub is a common choice, which requires selecting a repository:

Add Integration Screenshot

Put you Apollo Engine API key in the environment. Under the “Settings” tab, click “Reveal Config Vars”. Next copy your key from the Engine UI as the value for ENGINE_API_KEY.

Add Engine Api Key Screenshot

3. Try it out and build more!

Send a query to your GraphQL service at your Heroku Application at <APP NAME>.herokuapp.com and then check out the tracing data in the Engine UI.

To get the most out of Engine, read on about some of the features:

  • Performance tracing will help you learn how your GraphQL execution is working.
  • Caching will enable you to reduce load on your server and reduce response times.
Edit on GitHub
// search box