GraphQL most commonly lives at the edge of a microservice system—in an API gateway or a federated graph layer that presents one schema to clients while routing work to backend services—though it can also appear inside individual services, where it usually stays private to the system. That is the short answer; the rest of this article explains the placements, when each is appropriate, and where the boundaries blur.
The question is genuinely ambiguous because "GraphQL" names both a query language/specification and a runtime that executes queries against resolvers. Asking where it "lives" could mean where the server is deployed, where the schema is defined, or which layer owns query planning. This answer addresses all three, while noting that no single passage, diagram, or product version was supplied, so specific tooling choices (Apollo Router, GraphQL Mesh, Hasura, custom gateways) are described by role rather than endorsed.
The default pattern: one GraphQL schema at the edge
The GraphQL Foundation's own guidance is unusually direct on this point: if you are integrating GraphQL into a microservice architecture, it recommends a single GraphQL schema acting as an API gateway rather than having clients talk to multiple GraphQL services. The backend stays split into microservices, but the frontend gets one aggregated API. The same FAQ notes that a GraphQL gateway lets you exploit caching, request budgeting, and query scheduling—capabilities that matter precisely because the gateway sees whole client operations.
Architecturally, this placement puts GraphQL in front of the services, not among them:
In this arrangement the gateway owns the public schema, resolves fields by calling downstream services, and composes the responses. The microservices themselves need not know GraphQL exists. This is the "graph as boundary" model: GraphQL is the contract with clients, while internal transport remains whatever each team already operates—REST, gRPC, message queues, or direct database access for read models.
The reason this placement dominates is that GraphQL's core value—letting clients request exactly the fields they need in one round trip—is realized only when a single schema spans the data. If each microservice exposed its own separate GraphQL endpoint, a mobile client needing order history plus customer profile plus shipping status would have to orchestrate three GraphQL calls itself, reimplementing the aggregation the gateway was supposed to provide. You would have replaced REST's chatty-client problem with a GraphQL-shaped version of the same problem.
The federation variant: GraphQL distributed across subgraphs
Federation is the pattern that pushes GraphQL "into" the microservices while preserving one client-facing schema. According to the GraphQL Foundation's federation material, federation builds a unified GraphQL schema from multiple independent services, most often called subgraphs, each responsible for its portion of the data graph. Apollo introduced Apollo Federation in 2019, and the Foundation's Composite Schema Working Group—with participants from Apollo, ChilliCream, Graphile, Hasura, Netflix, The Guild, and WunderGraph—has been working toward an official specification.
In a federated system the pieces live in two places at once:
Entity definitions and resolvers live inside each subgraph, typically alongside or inside the owning microservice. The Products team defines Product and its fields; the Reviews team extends Product with reviews. The router (or gateway) lives at the edge. It holds the composed supergraph schema (or fetches it from a control plane), plans queries across subgraphs, and executes the plan.
So the honest answer for federation is that GraphQL is distributed: schema fragments are owned by service teams, while the execution brain sits at the edge. The Foundation's analogy is apt—federation is "like microservices for GraphQL," letting autonomous components cooperate while keeping independence. The federal-government comparison in the same source (states retaining sovereignty, a central authority handling shared concerns) captures the governance model as much as the technical one.
A concrete example: a query for { product(id: "p1") { name price reviews { rating } } } might be planned so the router first asks the Products subgraph for name and price, then uses the product's federation key to ask the Reviews subgraph for ratings. Neither subgraph knows the full query; the router does. This is why federation is often described as schema composition plus query planning—two distinct responsibilities that happen to ship together.
GraphQL inside a single service, hidden from clients
A less discussed but legitimate placement is GraphQL as an internal service's own API. A search service, for instance, might expose a GraphQL endpoint that only other backend components call, using GraphQL's type system and field selection to let internal consumers trim payloads. Here GraphQL lives behind the edge gateway, invisible to external clients.
This pattern works, but it forfeits the main client-facing benefit and adds a second schema to govern. Teams adopt it when the service's data is genuinely graph-shaped and internal consumers have varied field needs. The risk is schema sprawl: every internal GraphQL endpoint is another contract to version, document, and secure. If a service's consumers are few and stable, a typed RPC interface usually serves better.
The anti-pattern to name explicitly is exposing multiple public GraphQL endpoints, one per microservice, and asking clients to federate them. That is the arrangement the Foundation's guidance steers away from, and it recreates client-side orchestration with extra steps.
What the gateway actually does, and why placement matters
Putting GraphQL at the edge concentrates several cross-cutting concerns in one place, which is both the pattern's strength and its operational risk.
Schema ownership. The public schema becomes a product with a review process. In federation, ownership is delegated: each subgraph owns its types, and the composition step validates that the pieces fit. Composition failures—conflicting field types, missing entity keys—surface at build or deploy time rather than at query time, which is the main governance advantage of federation over a hand-written gateway.
Authentication and authorization. The Foundation's best-practices FAQ recommends enforcing authorization in the business logic layer so there is a single source of truth, and, for pipeline models, placing GraphQL after authentication middleware. In microservice terms: the gateway authenticates the caller and forwards identity (a token, a header, a context object); each service still enforces its own authorization on the data it owns. A gateway that tries to be the sole authorization point becomes a single place where a mistake exposes everything.
Query planning and performance. The gateway sees the whole operation, so it can batch downstream calls (the classic N+1 problem solved with per-request loaders), cache, and schedule. This is a real architectural reason to centralize GraphQL: field-level resolution across services is hard to do well anywhere else.
Failure semantics. A gateway is a single point of failure for the client experience even when backends are healthy. Partial-failure behavior—returning null for a field with an error entry in GraphQL's errors array versus failing the whole operation—must be designed deliberately, because a schema that marks everything non-null turns one slow subgraph into a failed page load.
When GraphQL should not live at the edge
The edge-gateway recommendation is a default, not a universal rule, and several conditions argue against it.
If clients are few, known, and stable—say, one internal web app calling three services—a GraphQL gateway adds a schema, a deploy target, and a query planner to maintain for little gain. A BFF (backend-for-frontend) per client type, possibly REST or tRPC, may be simpler. If the domain is not graph-shaped—flat, independent resources with little cross-entity traversal—REST's HTTP caching and predictable semantics often win. GraphQL shines when clients traverse relationships and need varying field sets; it offers less when every client wants the same payload.
Public API caching is another boundary. REST responses cache naturally in HTTP infrastructure; GraphQL's single POST endpoint and client-shaped responses require custom or layer-specific caching, as comparisons of the two styles note. Teams with heavy CDN caching requirements should account for this before moving the edge to GraphQL.
Finally, organizational readiness matters. Federation's promise of team autonomy only holds if teams can own subgraphs, run composition checks in CI, and coordinate schema changes. Without that discipline, a federated graph becomes a distributed monolith with a nicer diagram.
Common points of confusion
"GraphQL is a microservice." It is not. GraphQL is a specification and a runtime; the gateway or subgraph is a service that implements it. Calling the gateway "the GraphQL microservice" is colloquial shorthand that obscures the distinction between transport and schema.
"Federation means no gateway." Federation still has a router at the edge. What changes is that schema fragments live in subgraphs rather than being hand-written in the gateway. The router is thinner and more automated, not absent.
"One endpoint means one service." GraphQL typically exposes a single endpoint, usually /graphql, handling reads and writes—queries and mutations—over that path. That is an API-surface fact, not a deployment fact; the single endpoint can front dozens of services.
"GraphQL replaces the services." In the recommended pattern it replaces client-to-service chatter, not the services. The microservices keep their own storage and logic; GraphQL resolves fields by calling them.
Register and region. "Lives" is informal usage; architecture writing more precisely says GraphQL is deployed at the edge or embedded in subgraphs. No regional or dialect variation applies—GraphQL is a specification, and the architectural vocabulary is industry-wide.
A practical decision guide
| Situation | Typical placement |
|---|---|
| Many client types, varied field needs, graph-shaped domain | Single GraphQL schema at the edge (gateway or BFF) |
| Multiple teams owning distinct domains, one public schema required | Federated subgraphs plus a router |
| Few stable clients, flat resources, heavy HTTP caching | REST or typed RPC; GraphQL optional |
| Internal service with graph-shaped data and field-variable consumers | Private GraphQL inside the service, behind the edge |
| Legacy mix of REST and GraphQL backends | GraphQL gateway that also proxies REST routes, living alongside them |
The last row reflects a pragmatic reality: GraphQL can coexist with standard REST routes at the gateway, so adoption need not be all-or-nothing.
The consistent thread is that GraphQL belongs where the client contract is defined—at the edge, or distributed across subgraphs with the contract composed centrally. Its placement inside individual services is an implementation detail that should stay private. The specification work now underway through the Composite Schema Working Group suggests federation is consolidating as the standard way to scale that edge, but the underlying principle predates any particular implementation: one schema for clients, many services behind it.