Schema from Local File

Load supergraph schemas from local files


Overview

Load schemas from local files to give you complete control over which schema version is deployed. However, you must manage those files yourself.

Configuration

Command line

Bash
1router --supergraph ./supergraph.graphql

Environment variable

Bash
1APOLLO_ROUTER_SUPERGRAPH_PATH=./supergraph.graphql router

Docker

Mount the schema file into the container:

Bash
1docker run -v $(pwd)/supergraph.graphql:/app/supergraph.graphql \
2  ghcr.io/apollographql/router:latest \
3  --supergraph /app/supergraph.graphql

Or use a Dockerfile:

dockerfile
1FROM ghcr.io/apollographql/router:latest
2COPY supergraph.graphql /app/supergraph.graphql
3CMD ["--supergraph", "/app/supergraph.graphql"]

Kubernetes ConfigMap

Store the schema in a ConfigMap:

YAML
1apiVersion: v1
2kind: ConfigMap
3metadata:
4  name: supergraph-schema
5data:
6  supergraph.graphql: |
7    schema
8      @link(url: "https://specs.apollo.dev/link/v1.0")
9      @link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@key", "@shareable"])
10    {
11      query: Query
12    }
13    
14    type Query {
15      hello: String
16    }

Mount the schema in your deployment:

YAML
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4  name: router
5spec:
6  template:
7    spec:
8      containers:
9        - name: router
10          image: ghcr.io/apollographql/router:latest
11          args: ["--supergraph", "/config/supergraph.graphql"]
12          volumeMounts:
13          - name: schema
14            mountPath: /config
15      volumes:
16        - name: schema
17          configMap:
18            name: supergraph-schema

Hot reloading

Enable hot reloading to automatically reload the schema when the file changes.

note
Hot reloading has performance implications and might not be suitable for production environments. See Hot Reload for details.

Command line

Bash
1router --supergraph ./supergraph.graphql --hot-reload

Environment variable

Bash
1APOLLO_ROUTER_SUPERGRAPH_PATH=./supergraph.graphql \
2APOLLO_ROUTER_HOT_RELOAD=true \
3router

Development mode

Development mode automatically enables hot reloading:

Bash
1router --supergraph ./supergraph.graphql --dev

Best practices

Follow these guidelines to ensure reliability:

  • Version control: Store schema files in version control to track changes.

  • CI/CD integration: Download schemas in CI/CD pipelines for reproducible deployments.

  • Use hot reload for development only: Avoid hot reloading in production due to performance impact.

  • Validate schemas: Validate schemas before deploying to catch errors early.

  • Use ConfigMaps for Kubernetes: Store schemas in ConfigMaps for Kubernetes deployments.

For more information, see the following resources:

Feedback

Edit on GitHub

Ask Community