GraphQL Gateway
The GraphQL gateway is the single entry point for all frontend GraphQL traffic. It composes six domain subgraphs into one federated supergraph using Apollo Gateway, runs on Fastify, and handles cross-cutting concerns like authentication, caching, and observability.
Stack
| Component | Version |
|---|---|
| Apollo Gateway | 2.11.2 |
| Apollo Server | 5.0.0 |
| Fastify | 5.6.0 |
| GraphQL Hive | 0.40.0 |
Supergraph composition
The gateway loads its supergraph schema from one of two sources:
- Production: Hive CDN, polling for updates every 15 seconds
- Development: a local
supergraph.generated.graphqlfile
Hive CDN is activated when both HIVE_CDN_ENDPOINT and
HIVE_CDN_ACCESS_TOKEN are set. Otherwise the gateway falls back to
the local file.
Two composition profiles ship with the platform, differing only in which CMS subgraph they include:
| Profile | File |
|---|---|
| Contentful | supergraphs/commercetools-contentful.yaml |
| Storyblok | supergraphs/commercetools-storyblok.yaml |
Subgraphs
| Subgraph | Default dev URL | Domain |
|---|---|---|
| account | http://localhost:4001/graphql | Authentication & customer data |
| catalog | http://localhost:4002/graphql | Products, categories, search |
| checkout | http://localhost:4003/graphql | Cart, orders, payments |
| cms | http://localhost:4004/graphql | CMS content (Contentful or Storyblok) |
| order | http://localhost:4005/graphql | Order history & management |
| quotes | http://localhost:4006/graphql | B2B quote requests |
Endpoints
| Path | Method | Purpose |
|---|---|---|
/graphql | POST | Main GraphQL endpoint |
/auth/graphql | POST | GraphQL with refresh-token cookie path |
/healthcheck | GET | Returns {"status": "OK"} |
The /auth/graphql endpoint exists for cookie path separation. The
refresh-token cookie is scoped to /auth/graphql so it is never sent
on regular queries, reducing request size and limiting exposure.
Authentication
The gateway handles all token lifecycle management: reading tokens
from cookies or headers, propagating them to subgraphs, and writing
updated tokens back. It also provides the @requiresSession
directive that creates anonymous sessions on the fly for first-time
visitors.
See Authentication & tokens for the full
details on token types, the session flow, and the @requiresSession
directive.
Trusted documents
Persisted queries are enforced through
@labdigital/apollo-trusted-documents. In production, only
pre-registered query hashes are accepted. The document store is backed
by Hive CDN with a local LRU cache (1 000 entries).
During development you can bypass the check by sending the
X-TrustedDocument-BypassSecret header with the value from the
TRUSTED_DOCUMENT_BYPASS_SECRET environment variable.
Caching
The gateway uses a KeyvAdapter backed by Keyv for Apollo's response
cache. When REDIS_URL is set, the cache is backed by Redis. Without
Redis, caching is effectively disabled (a no-op store is used). See
Caching for how response caching interacts with the
CDN layer.
Custom fetcher & retries
Subgraph requests use make-fetch-happen with custom retry logic:
- Retries on 502 and 503 responses
- Up to 6 retries with 250 ms base delay
Each retry is tracked with an OpenTelemetry span so you can see retry behaviour in traces.
CORS
In development the gateway allows requests from localhost:3000,
localhost:4000, localhost:3010, and *.evolve.labdigital.nl. In
production, set CORS_ORIGIN to a comma-separated list of allowed
origin suffixes. Credentials are always included.