From harness-claude
Composes a unified GraphQL API from independently deployed subgraph services using Apollo Federation, with directives like @key, @shareable, @override, and @requires.
How this skill is triggered — by the user, by Claude, or both
Slash command
/harness-claude:graphql-federation-patternThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
> Compose a unified GraphQL API from independently deployed subgraph services using Apollo Federation
Compose a unified GraphQL API from independently deployed subgraph services using Apollo Federation
orders to User from the orders service)User, the orders service defines Order. No type is defined in two places — types are extended across boundaries.# users subgraph
type User @key(fields: "id") {
id: ID!
name: String!
email: String!
}
type Query {
user(id: ID!): User
}
Use @key to mark entity types. An entity is a type that can be referenced and extended by other subgraphs. The @key directive specifies which fields uniquely identify the entity.
Extend entities in other subgraphs with stub types. The orders service references User without redefining it — it provides only the key field and adds new fields.
# orders subgraph
type User @key(fields: "id") {
id: ID!
orders: [Order!]!
}
type Order @key(fields: "id") {
id: ID!
total: Money!
status: OrderStatus!
customer: User!
}
__resolveReference for each entity. This resolver is called by the gateway when it needs to hydrate a stub entity. It receives the key fields and returns the full object.const resolvers = {
User: {
__resolveReference: (ref: { id: string }, { dataSources }) => {
return dataSources.users.findById(ref.id);
},
},
};
# supergraph-config.yaml
subgraphs:
users:
routing_url: http://users-service:4001/graphql
schema:
subgraph_url: http://users-service:4001/graphql
orders:
routing_url: http://orders-service:4002/graphql
schema:
subgraph_url: http://orders-service:4002/graphql
Use @shareable for fields that multiple subgraphs can resolve. In Federation v2, fields are exclusive by default. Mark fields @shareable when multiple subgraphs need to return the same field.
Use @override to migrate fields between subgraphs. When moving a field from one subgraph to another, the new owner uses @override(from: "old-subgraph") to claim resolution without a breaking change.
Use @external, @provides, and @requires for computed fields. @requires tells the gateway to fetch specified fields from the owning subgraph before calling the current resolver.
# shipping subgraph
type Order @key(fields: "id") {
id: ID!
weight: Float @external
shippingCost: Float @requires(fields: "weight")
}
Run composition checks in CI. Use rover subgraph check to validate that schema changes in one subgraph do not break the composed supergraph before deploying.
Keep the gateway stateless. The router/gateway should not contain business logic — it composes and routes. All business logic lives in subgraphs.
Federation v1 vs. v2: Federation v2 (current) uses @link to import federation directives, supports @shareable, @override, @inaccessible, and progressive @override for safe migrations. Prefer v2 for new projects.
Query planning: The gateway decomposes incoming queries into subgraph fetches. A query for user { name orders { total } } fetches name from the users subgraph, then fetches orders from the orders subgraph using the user's id as the reference key. This happens transparently.
Performance considerations:
__resolveReference on the owning subgraph@provides to return extra fields alongside entities to reduce follow-up fetches__resolveReference using DataLoaderOwnership rules:
@key fields must be resolvable by the defining subgraph@shareable)@key) must be identical across subgraphsCommon mistakes:
__resolveReference — the gateway cannot hydrate the entity@key fields without updating all referencing subgraphshttps://www.apollographql.com/docs/federation/
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeGuides authoring Apollo Federation subgraph schemas: entities with @key, shared types, computed fields, and composition troubleshooting.
Designs GraphQL schemas with Apollo Federation, implements resolvers with DataLoader, and optimizes query performance. Invoke for schema design, federation directives, and real-time subscriptions.
Designs GraphQL schemas with Apollo Federation, implements resolvers using DataLoader, and optimizes query performance. Useful for schema-first design, real-time subscriptions, and query complexity analysis.