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
1router --supergraph ./supergraph.graphqlEnvironment variable
1APOLLO_ROUTER_SUPERGRAPH_PATH=./supergraph.graphql routerDocker
Mount the schema file into the container:
1docker run -v $(pwd)/supergraph.graphql:/app/supergraph.graphql \
2 ghcr.io/apollographql/router:latest \
3 --supergraph /app/supergraph.graphqlOr use a 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:
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:
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-schemaHot reloading
Enable hot reloading to automatically reload the schema when the file changes.
Command line
1router --supergraph ./supergraph.graphql --hot-reloadEnvironment variable
1APOLLO_ROUTER_SUPERGRAPH_PATH=./supergraph.graphql \
2APOLLO_ROUTER_HOT_RELOAD=true \
3routerDevelopment mode
Development mode automatically enables hot reloading:
1router --supergraph ./supergraph.graphql --devBest 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.
Related documentation
For more information, see the following resources:
Router Configuration Overview - Overview of all schema loading options
Hot Reload - Hot reloading details and performance considerations
Rover CLI - Schema composition and management tools