Mesh Serve
Mesh Serve is a GraphQL gateway for any JavaScript environment and runtime such as Node.js, Bun, Deno, Google Cloud Functions, Azure Functions, Cloudflare Workers, and more.
Mesh Serve supports two different modes:
- Serve a Supergraph. Serve a supergraph provided by GraphQL Mesh Compose or any other Federation compliant composition tool such as Apollo Rover or schema registry (GraphQL Hive, Apollo GraphOS)
- Proxy a GraphQL API. Mesh Serve can also act as a proxy to a GraphQL API for adding additional features such as monitoring/tracing, caching, rate limiting, security layers and more
Getting Started
Prepare a Supergraph
A Gateway for a composed supergraph file (supergraph.graphql
) generated by
Mesh Compose, or any other compliant tool (GraphQL Hive, Apollo GraphOS), can be
served with Mesh Serve.
Using the CLI
Install
To use the CLI, you need to have Node.js installed in your environment. Then, you can install Serve CLI with your favorite package manager:
npm i @graphql-mesh/serve-cli
Serve
Having prepared the supergraph, serve it with:
mesh-serve
Using Docker
Mesh Serve also has an official Docker image that’s easy to use and can directly replace the CLI in environments where Node.js is not present.
Serve
Having prepared the supergraph, serve it with:
docker run -p 4000:4000 -v $(pwd)/supergraph.graphql:/serve/supergraph.graphql ghcr.io/ardatan/mesh-serve
Check out the Docker deployment guide for more details on using Mesh Serve with Docker.
Configuration
Arguments
Mesh Serve supports basic configuration through CLI arguments.
For example, you may want to change the port:
mesh-serve --port 5000
The Docker image also supports arguments, simply add them to the run command:
docker run \
-p 5000:5000 \
-v "$(pwd)/my-schema.graphql:/serve/my-schema.graphql" \
ghcr.io/ardatan/mesh-serve --port=5000
For a full list of CLI arguments, please refer to the CLI Reference.
Config File
The Mesh Serve config file is used for enabling additional features such as authorization, authentication caching, rate limiting, and more…
You’re recommended to use the mesh.config.ts
file to configure Mesh Serve.
import { defineConfig } from '@graphql-mesh/serve-cli'
export const serveConfig = defineConfig({
supergraph: 'my-schema.graphql'
})
Mesh Serve will automatically pick up the default config file and apply the settings. Simply start Mesh Serve:
mesh-serve
However, when using Docker, you have to mount the mesh.config.ts
file first:
docker run \
-p 4000:4000 \
-v "$(pwd)/mesh.config.ts:/serve/mesh.config.ts" \
ghcr.io/ardatan/mesh-serve
Proxy a GraphQL API
Mesh Serve can also act as a proxy to an existing GraphQL API. This is useful for adding additional features such as monitoring/tracing, caching, rate limiting, security layers, and more.
You can configure Mesh Serve to proxy a GraphQL API by providing the URL of the API in the configuration file.
import { defineConfig } from '@graphql-mesh/serve-cli'
export const serveConfig = defineConfig({
proxy: {
endpoint: 'https://example.com/graphql'
}
})
If you serve with the following config, Mesh Serve will start a gateway that proxies the GraphQL API.
Next steps
After learning the first steps of Mesh Serve, you can explore the following topics.