Docker is a tool that allows you to package an application and its dependencies into a container
that can run on any system. This makes it easy to deploy applications in a consistent and
reproducible way, regardless of the underlying infrastructure.
To simplify running your GraphQL gateway, you can use the Docker image and the Docker Compose
template we provide. This setup allows you to easily configure and run the gateway without the need
to install Node.js and the required gateway npm packages.
Prerequisites
Make sure you have Docker installed on your system.
For a full list of CLI arguments, please refer to the
Config Reference.
Changing Port in Container
The default port where Hive Gateway listens is 4000; however, maybe the container is running
inside a network (like when using
Networking in Compose) and you wish to change the
port of Hive Gateway in the image.
You can use the gateway.config.ts to change the port, or simply pass in the --port argument when
running the image:
You may have an environment where you want to use Docker Compose
and would like to add Hive Gateway there.
Start by defining the docker-compose.yml
services: hive-gateway: image: ghcr.io/graphql-hive/gateway command: supergraph ports: - "4000:4000" # Add Hive Registry environment variables in case you use it # environment: # HIVE_CDN_ENDPOINT: <secret> # HIVE_CDN_KEY: <secret> # HIVE_REGISTRY_TOKEN: <secret> volumes: - ./gateway.config.ts:/gateway/gateway.config.ts
And then simply start the services with:
docker compose up
Extend Docker Image
Install Plugin
You may want to add additional functionality, or plugins to the base image - you just need to create
a new Dockerfile basing the image off ghcr.io/graphql-hive/gateway.
If need only a handful of plugins (or some other dependencies), you can simply extend the image and
install the modules with npm i:
However, you may be developing a plugin and have a setup with some dependencies and source code,
copying over your project’s files is the way to go.
In the following example, we’re developing a useTiming plugin that will add a human readable
execution duration to the GraphQL result extensions property.
import { defineConfig } from "@graphql-hive/gateway";import { useTiming } from "./my-timing";export const gatewayConfig = defineConfig({ plugins: () => [useTiming()],});
Your Dockerfile should then look something like this:
Dockerfile
FROM ghcr.io/graphql-hive/gateway# we dont install dev deps because:# 1. we need them for type checking only# 2. Hive Gateway is already available in the docker imageCOPY package*.json .RUN npm i --omit=devCOPY my-time.ts .COPY gateway.config.ts .
Then build your image:
docker build -t hive-gateway-w-my-timing .
And finally start it (the config file is in the image and doesn’t need to be mounted):
docker run -p 4000:4000 hive-gateway-w-my-timing supergraph
Additional Resolvers
Instead maybe you need to define additional resolvers that depend on other dependencies. Similarly
to the Develop Plugin approach, you can just copy the project code over and build
another image.
import moment from "moment";export const additionalResolvers = { Query: { formattedToday() { return moment().format("DD.MM.YYYY"); }, },};
gateway.config.ts
import { defineConfig } from "@graphql-hive/gateway";import { additionalResolvers } from "./my-time";export const gatewayConfig = defineConfig({ additionalResolvers });
Your Dockerfile should then look something like this:
Dockerfile
FROM ghcr.io/graphql-hive/gateway# we dont install dev deps because:# 1. we need them for type checking only# 2. Hive Gateway is already available in the docker imageCOPY package*.json .RUN npm i --omit=devCOPY my-time.ts .COPY gateway.config.ts .
Then build your image:
docker build -t hive-gateway-w-add-res .
And finally start it (the config file is in the image and doesn’t need to be mounted):
docker run -p 4000:4000 hive-gateway-w-add-res supergraph
This site uses cookies for analytics and improving your experience.