How to: Deploy a GraphQL Mesh Gateway
GraphQL Mesh v0 documentation (superseded by v1): Learn how to deploy GraphQL Mesh anywhere. Use mesh dev for local development and mesh start for production. Deploy Mesh with ease on Vercel, AWS Lambda, Cloudflare Workers and more!
Thanks to its flexible architecture and embedded server relying on GraphQL Yoga and Envelop, GraphQL Mesh can be deployed anywhere!
We already saw that mesh dev could be used for local development.
Similarly, Mesh provides a mesh start CLI command for production environments.
mesh start can be used for all environments supporting starting a web server (Heroku, Digital
Ocean, etc).
Setup Mesh on a Serverless environment requires some integration work, detailed below.
Deploy Mesh with mesh start on Node.js
While mesh dev handles the generation of the SDK code, mesh start expects to load the Gateway
schema and runtime from the .mesh/ folder.
This mechanism helps:
- reducing the start time of the server: no build step is required
- preventing starting failure if one of the Sources is unreachable: we don’t fetch the API definition file at startup, ensuring that the fetched definitions are validated at build time
To deploy a Mesh Gateway, you need to ensure that mesh build is called during the deployment, for
example, with a prebuild step:
For more information about the embedded Mesh server configuration, please
refer to the serve reference documentation.
Deploy Mesh on Serverless
Serverless deployment requires some integration since we cannot keep the mesh start server
running.
Deploy Mesh on Vercel with Next.js API Routes
First, let’s ensure that mesh build will be run during deployment.
Vercel - list most platforms, and run yarn build for deployment. For this reason, we will add a
prebuild step:
Then, we have to update Mesh configuration to let Mesh know the actual endpoint;
Now, let’s integrate our Mesh Gateway in a Next.js API Routes:
Path ./.mesh refers to built Mesh folder that should be available in your project root (together
with your project package.json)
Deploy Mesh on AWS Lambda
Similarly to regular and Vercel deployment, we will need to add the mesh build command in the
build step.
Then, we can create a Lambda as it follows:
Deploy Mesh on Cloudflare Workers
Similarly to regular and Vercel deployment, we will need to add the mesh build command in the
build step.
Then:
You can see the following examples for more details:
Also you can see how to setup KV as a cache storage in GraphQL Mesh here.
Deploy Mesh on Apache OpenWhisk
You can see our example that shows how to setup an OpenWhisk action for GraphQL Mesh. OpenWhisk Example
Deploy Mesh on GCP Cloud Functions
Similarly to regular and Vercel deployment, we will need to add the mesh build command in the
build step.
Then assuming that your function’s name is mesh;
We need to configure Mesh CLI to generate artifacts for the function’s path;
You can see our example that shows how to setup a Cloud Function for GraphQL Mesh. Cloud Functions Example
Deploy on Azure Functions
Similarly to regular and Vercel deployment, we will need to add the mesh build command in the
build step.
Then assuming that your function’s name is mesh;
We need to configure Mesh CLI to generate artifacts for the function’s path;
Deploy on Node.js
Mesh as an Express route
Similarly to regular and Vercel deployment, we will need to add the mesh build command in the
build step.
Mesh as a Fastify route
Similarly to regular and Vercel deployment, we will need to add the mesh build command in the
build step.
Mesh as a Node.js request handler
Similarly to regular and Vercel deployment, we will need to add the mesh build command in the
build step.
Mesh as a Koa route
Similarly to regular and Vercel deployment, we will need to add the mesh build command in the
build step.
Mesh and Docker
A GraphQL Mesh Gateway should be treated like any Node.js project while keeping in mind that a
mesh build step should be added to the deployment steps.