QA
Senior LevelREST APIs & Web Services

How does Apollo Federation v2 compose multiple microservice GraphQL subgraphs into a unified supergraph?

❓ Interview Prompt: Explain Apollo Federation v2, Subgraphs, Supergraph schema composition, `@key` directive, `@shareable`, and query planning by Federation Router.

Apollo Federation v2 composes independent GraphQL microservices (Subgraphs) into a single unified API endpoint (Supergraph):

Core Directives & Routing:

1
'@key(fields: "id")': Marks an entity (e.g. 'User') that can be extended by other subgraphs.
2
Federation Router: Intercepts client GraphQL queries, analyzes entity keys, and automatically generates an optimized multi-service query execution plan, merging sub-responses seamlessly!

Code Implementation Example

yaml
# User Subgraph Schema (Users Microservice)
type User @key(fields: "id") {
  id: ID!
  name: String!
}

# Reviews Subgraph Schema (Reviews Microservice)
type User @key(fields: "id", resolvable: false) {
  id: ID!
}
extend type User {
  reviews: [Review!]!
}
💡Apollo Federation v2 entity key sharing across subgraphs.
🎯 Interview Key Takeaway

Apollo Federation v2 composes modular GraphQL subgraphs into a unified supergraph using entity key directives.

#Apollo Federation#GraphQL Subgraphs#Architecture#Senior
Back to all REST APIs & Web Services Questions→

More REST APIs & Web Services Interview Questions

Beginner LevelREST APIs & Web Services

What is HTTP Method Idempotency and how do you implement Idempotency Keys for REST APIs?

Beginner LevelREST APIs & Web Services

What are standard HTTP Status Codes (200, 201, 204, 400, 401, 403, 404, 409, 429, 500, 503)?

Beginner LevelREST APIs & Web Services

What are HTTP Verbs (GET, POST, PUT, PATCH, DELETE) and when to use PUT vs PATCH?