GraphQL Federation is a backend architecture pattern that enables a unified GraphQL API (called a supergraph) to be composed from multiple, independently managed GraphQL services (called subgraphs). A federation gateway (or router) receives client queries, intelligently plans their execution across the relevant subgraphs, and stitches the results into a single response. This allows large organizations to scale their GraphQL implementation across separate teams and technology stacks while presenting a single, cohesive schema to consumers.
Glossary
GraphQL Federation

What is GraphQL Federation?
GraphQL Federation is an architectural pattern for composing a single, unified GraphQL API (a supergraph) from multiple, independently deployed GraphQL services (subgraphs).
The pattern is defined by a federation specification that subgraphs follow, primarily using directives like @key to designate an entity's primary fields and @requires and @provides to express dependencies between services. This enables schema stitching at runtime without a centralized build process. Federation contrasts with GraphQL schema stitching, which often requires manual coordination, by providing a declarative, contract-first approach for building a distributed GraphQL architecture.
Core Components of GraphQL Federation
GraphQL Federation is an architectural pattern for composing a single, unified GraphQL API (a supergraph) from multiple, independently deployable GraphQL services (subgraphs). This enables teams to own their domain data while contributing to a cohesive enterprise schema.
Subgraph
A subgraph is an independently deployable GraphQL service that defines a portion of the overall domain. It exposes its own GraphQL schema and is responsible for resolving the data for the types and fields it owns. Key characteristics include:
- Ownership: A subgraph owns specific types (e.g., a
Productsubgraph owns theProducttype). - Schema Definition: It uses special federation directives (like
@key) to declare how its types can be referenced and extended by other subgraphs. - Resolver Implementation: Contains the business logic and data-fetching code for its portion of the graph.
Supergraph Schema
The supergraph schema is the unified, composed GraphQL API schema that clients interact with. It is generated by a federation gateway by intelligently merging all subgraph schemas. Its composition involves:
- Schema Stitching: The gateway combines type definitions, merges duplicate types, and connects them via @key references.
- Query Planning: The gateway analyzes incoming client queries and generates an execution plan that determines which subgraphs to call and in what order.
- Single Endpoint: Clients send queries to a single supergraph endpoint, unaware of the underlying service decomposition.
Federation Gateway / Router
The gateway (or router) is the runtime component that sits between clients and the subgraphs. It is responsible for query execution, routing, and composition. Its core duties are:
- Query Parsing & Validation: Accepts and validates incoming GraphQL operations against the supergraph schema.
- Query Planning: Creates an optimized execution plan, breaking a single client query into multiple sub-queries for different subgraphs.
- Request Routing: Delegates these sub-queries to the correct subgraph services.
- Response Composition: Aggregates the results from all subgraphs and returns a single, unified response to the client. Apollo Router and WunderGraph are common implementations.
Federation Directives
Federation directives are custom GraphQL schema directives used within subgraph schemas to provide metadata for composition. They are the declarative language of federation.
@key: Defines the primary key fields for an entity, enabling other subgraphs to reference it. Example:type Product @key(fields: "id") { id: ID! name: String }@extends: Used to indicate that a type is defined in another subgraph but is being extended with new fields in the current subgraph.@external: Marks a field as being defined in another subgraph; it's used in conjunction with@requiresand@provides.@requires: Specifies that a field in this subgraph requires data from another subgraph to resolve.@provides: Specifies that a subgraph, while resolving a field, can guarantee to return certain fields defined in another subgraph.
Entity
An entity is a GraphQL object type that can be resolved across multiple subgraphs. It is the central concept for sharing and extending types in federation.
- Definition: Any type annotated with the
@keydirective is an entity. - Reference Resolution: When a subgraph returns a reference to an entity (e.g.,
{ __typename: "Product", id: "prod_1" }), the gateway uses this representation to fetch the remaining fields from the subgraph that owns that entity. - Distributed Ownership: Different subgraphs can contribute different fields to the same entity. For example, the
Productentity might haveidandnamefrom a Catalog subgraph, andinventoryCountfrom an Inventory subgraph.
Query Plan
A query plan is the internal execution blueprint created by the federation gateway. It is the result of query planning and dictates how a client's single query is decomposed.
- Operation: The gateway parses the client query and matches each field against the supergraph schema to see which subgraph can resolve it.
- Decomposition: The query is split into a series of dependent fetch nodes.
- Optimization: The plan minimizes sequential calls and batches requests where possible.
- Execution: The gateway executes the fetch nodes in order, passing data from one subgraph's response as variables to the next, finally composing the final result. This process is transparent to the client.
How GraphQL Federation Works
GraphQL Federation is an architecture pattern for composing a unified GraphQL API (a supergraph) from multiple independent GraphQL microservices (subgraphs).
GraphQL Federation is an architectural pattern that enables a single, unified GraphQL API, called a supergraph, to be composed from multiple independent GraphQL services, known as subgraphs. A federation gateway (or router) manages this composition, receiving client queries and intelligently delegating portions of the query to the appropriate backend subgraph services. This allows different teams to own and evolve their domain-specific subgraphs autonomously while presenting a cohesive data graph to consumers.
The pattern relies on a federation specification that defines how subgraphs declare their schema contributions and resolve references to entities owned by other services. Key mechanisms include entity keys for unique identification across subgraphs and reference resolvers that allow the gateway to fetch related data from other services. This stands in contrast to schema stitching, as federation pushes query planning and execution logic to a dedicated gateway, providing a more declarative and managed approach to schema composition for large-scale, distributed GraphQL implementations.
Frequently Asked Questions
GraphQL Federation is an architectural pattern for composing a unified GraphQL API from multiple independent backend services. This FAQ addresses its core concepts, implementation, and role in AI agent integration.
GraphQL Federation is an architecture pattern that enables multiple independent GraphQL services (called subgraphs) to be combined into a single, unified supergraph API, managed by a federation gateway (or router). It works by allowing each subgraph to define a portion of the overall schema and declare which types and fields it is responsible for. The gateway composes these partial schemas, intelligently routes incoming queries to the correct services, and merges the results into a single response for the client. This allows a client to query data from multiple backend services in one request without knowing the underlying service boundaries.
Key components include:
- Subgraph: An independent GraphQL service that defines a fragment of the overall schema.
- Supergraph Schema: The composed, unified schema generated from all subgraph schemas.
- Federation Gateway/Router: The runtime component that receives client queries, plans their execution across subgraphs, and assembles the final result.
@keyDirective: The primary directive a subgraph uses to mark a type as an entity and specify its primary key fields, enabling other subgraphs to reference and extend it.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
GraphQL Federation is a design pattern for composing a unified GraphQL API (a supergraph) from multiple, independently deployed GraphQL services (subgraphs). Understanding its core components and related architectural concepts is essential for building scalable, modular API ecosystems.
Supergraph
The supergraph is the unified, composed GraphQL API schema exposed to clients. It is not manually written but is automatically generated by a federation gateway (like Apollo Router) by merging the schemas from all registered subgraphs. The supergraph intelligently routes incoming queries to the appropriate subgraph services, presenting a single, cohesive API endpoint.
- Composition: The process of merging subgraph schemas and their federation directives into one executable supergraph schema.
- Gateway/Router: The runtime component that executes the supergraph, handling query planning, routing, and response merging.
Subgraph
A subgraph is an independent GraphQL service that defines a portion of the overall domain model. Each subgraph is responsible for a specific set of types and fields, which it owns. Subgraphs use federation-specific schema directives (like @key, @shareable, @requires) to declare how their portion of the data graph connects to others.
- Ownership: A subgraph is the single source of truth for the types and fields it defines.
- Autonomy: Subgraphs can be developed, deployed, and scaled independently by separate teams.
- Example: An
Orderssubgraph might own theOrdertype, while aProductssubgraph owns theProducttype.
Schema Stitching
Schema stitching is an alternative, older technique for combining multiple GraphQL schemas into a single gateway schema. Unlike federation, which relies on subgraphs declaring their relationships via directives, stitching typically involves a centralized gateway manually wiring together schemas and writing resolver logic to merge types and fields.
- Key Difference: Federation is a declarative architecture, while stitching is often more imperative and procedural.
- Complexity: Stitching can become complex to maintain as the number of services grows, whereas federation's declarative nature offers more robust tooling for schema composition and conflict resolution.
Query Planning
Query planning is the process performed by the federation gateway to decompose a client's GraphQL query into a series of sub-queries (query plans) that can be executed against the relevant subgraphs. The planner must optimize for:
- Correctness: Ensuring all required data is fetched.
- Efficiency: Minimizing the number of subgraph calls and avoiding redundant data fetching (the N+1 problem).
- Ordering: Managing dependencies between subgraphs (e.g., fetching an entity's
@keyfields before using them in a@requiresfield).
Advanced gateways perform query plan caching to avoid re-planning identical queries.
Entity & @key Directive
An entity is a GraphQL object type that can be resolved across multiple subgraphs. It is the fundamental unit of federation. An entity is defined using the @key directive in a subgraph schema, which specifies the primary key fields needed to uniquely fetch an instance of that type.
Example:
graphql# In Products subgraph type Product @key(fields: "id") { id: ID! name: String! price: Float } # In Reviews subgraph type Review { product: Product @provides(fields: "name") } extend type Product @key(fields: "id") { id: ID! @external name: String! @external reviews: [Review] }
The @key(fields: "id") declares Product as an entity. The Reviews subgraph extends this entity by providing the reviews field, using the id to fetch the correct product.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us