Using GraphQL Gateway

1. Understanding Gateway Pattern

ResponsibilityDetail
Schema compositionBuild supergraph from subgraphs
Query planningDecompose into subgraph operations
ExecutionIssue, await, merge subgraph results
Entry pointSingle endpoint for clients

2. Setting Up Apollo Gateway

# router.yaml
supergraph:
  listen: 0.0.0.0:4000
  introspection: false
override_subgraph_url:
  users: http://users:4001/graphql
  orders: http://orders:4002/graphql
traffic_shaping:
  router: { timeout: 30s }

3. Configuring Supergraph Schema

SourceDetail
Static SDLPre-composed supergraph.graphql
Apollo StudioManaged federation; schema published per subgraph
IntrospectAndComposeRuntime composition (legacy gateway)

4. Implementing Query Planning

PhaseDetail
ParseStandard parse
PlanBuild minimal fetch graph across subgraphs
ExecuteRun fetches respecting dependencies
MergeStitch responses by entity keys

5. Handling Service Health

MechanismDetail
Health checksGET /.well-known/apollo/server-health
Circuit breakerSkip failing subgraph briefly
Schema reloadDetect subgraph schema updates

6. Routing Requests

StrategyDetail
DNS / service meshStandard k8s routing
Header propagationForward auth, tracing, locale
Per-subgraph TLSmTLS within mesh

7. Implementing Custom Resolvers

UseMechanism
Gateway-only fieldsResolver added at gateway
Cross-subgraph aggregationMultiple delegations + merge
Apollo Router coprocessors / RhaiCustom logic in router

8. Managing Service Updates

PracticeDetail
Schema check before deployrover subgraph check
Backward-compatible changesAdd fields/types, deprecate old
Coordinated mutationsAdd new field then migrate clients then remove

9. Handling Partial Failures

BehaviorDetail
Subgraph errorsReturned in errors[] with subgraph in extensions
Nullable propagationNullable parents protect rest of result
TimeoutsPer-subgraph timeout to prevent cascade

10. Monitoring Gateway Performance

MetricDetail
Plan timeQuery planning duration
Per-subgraph latencySlowest dependency
Cache hit ratePlan cache, response cache
Error rate by subgraphIsolate failures