Skip to content
Apollo Federation Schema Authoring

Apollo Federation Schema AuthoringSkill

Released
v1.0.2
MIT
Repository Docs

Summary

Apollo's official skill for writing Federation 2 subgraph schemas — entities and @key, @shareable, @external, @requires, @provides, @override, and reading composition errors.

Features

  • Federation 2 @link setup and version pinning
  • Entity design with @key and reference resolvers
  • Decision guidance for @shareable, @external, @requires, @provides, @override, @inaccessible
  • Maps Rover composition errors back to the schema decision that caused them
  • Works with any Federation 2.x subgraph library, not just Apollo Server

Install This Skill

Add this skill to your favorite AI agent in a few steps.

Any AI agent

This skill is plain instructions — it works with any assistant that accepts custom instructions or system prompts.

  1. Copy the skill content with the button below.
  2. Paste it into your agent's instruction file or system prompt (for example AGENTS.md, .cursorrules, or a custom instructions field).
  3. Ask the agent to apply the skill whenever the task matches.

Skill Content

Markdown Content

Copy this content and use it with your preferred AI agent

---
name: apollo-federation
description: >
  Guide for authoring Apollo Federation subgraph schemas. Use this skill when:
  (1) creating new subgraph schemas for a federated supergraph,
  (2) defining or modifying entities with @key,
  (3) sharing types/fields across subgraphs with @shareable,
  (4) working with federation directives (@external, @requires, @provides, @override, @inaccessible),
  (5) troubleshooting composition errors,
  (6) any task involving federation schema design patterns.
license: MIT
compatibility: Works with any Federation 2.x compatible subgraph library (Apollo Server, GraphQL Yoga, etc.)
metadata:
  author: apollographql
  version: "1.0.2"
allowed-tools: Bash(rover:*) Read Write Edit Glob Grep
---

# Apollo Federation Schema Authoring

Apollo Federation enables composing multiple GraphQL APIs (subgraphs) into a unified supergraph.

## Federation 2 Schema Setup

Every Federation 2 subgraph must opt-in via `@link`:

```graphql
extend schema
  @link(url: "https://specs.apollo.dev/federation/v2.12",
        import: ["@key", "@shareable", "@external", "@requires", "@provides"])
```

Import only the directives your subgraph uses. The version shown (`v2.12`) is
illustrative — check the [Federation changelog](https://www.apollographql.com/docs/graphos/schema-design/federated-schemas/reference/versions)
for currently supported versions before copying it verbatim.

> A subgraph's `@link` version is a floor, not the composition version — see
> [Federation versions](references/composition.md#federation-versions-floor-vs-composition)
> for the full explanation.

## Core Directives Quick Reference

| Directive | Purpose | Example |
|-----------|---------|---------|
| `@key` | Define entity with unique key | `type Product @key(fields: "id")` |
| `@shareable` | Allow multiple subgraphs to resolve field | `type Position @shareable { x: Int! }` |
| `@external` | Reference field from another subgraph | `weight: Int @external` |
| `@requires` | Computed field depending on external fields | `shippingCost: Int @requires(fields: "weight")` |
| `@provides` | Conditionally resolve external field | `@provides(fields: "name")` |
| `@override` | Migrate field to this subgraph | `@override(from: "Products")` |
| `@inaccessible` | Hide from API schema | `internalId: ID! @inaccessible` |
| `@interfaceObject` | Add fields to entity interface | `type Media @interfaceObject` |

## Reference Files

Detailed documentation for specific topics:

- [Directives](references/directives.md) - All federation directives with syntax, examples, and rules
- [Schema Patterns](references/schema-patterns.md) - Multi-subgraph patterns and recipes
- [Composition](references/composition.md) - Composition rules, error codes, and debugging

## Key Patterns

### Entity Definition

```graphql
type Product @key(fields: "id") {
  id: ID!
  name: String!
  price: Int
}
```

### Entity Contributions Across Subgraphs

```graphql
# Products subgraph
type Product @key(fields: "id") {
  id: ID!
  name: String!
  price: Int
}

# Reviews subgraph
type Product @key(fields: "id") {
  id: ID!
  reviews: [Review!]!
  averageRating: Float
}
```

### Computed Fields with @requires

```graphql
type Product @key(fields: "id") {
  id: ID!
  size: Int @external
  weight: Int @external
  shippingEstimate: String @requires(fields: "size weight")
}
```

### Value Types with @shareable

```graphql
type Money @shareable {
  amount: Int!
  currency: String!
}
```

### Entity Stub (Reference Without Contributing)

```graphql
type Product @key(fields: "id", resolvable: false) {
  id: ID!
}
```

## Ground Rules

- ALWAYS use Federation 2.x syntax with `@link` directive
- ALWAYS import only the directives your subgraph uses
- NEVER use `@shareable` without ensuring all subgraphs return identical values for that field
- PREFER `@key` with single ID field for simple entity identification
- USE `rover supergraph compose` to validate composition locally
- USE `rover subgraph check` to validate against production supergraph

Usage Instructions

Learn how to use this skill with different AI agents.

Generic Instructions
npx skills add apollographql/skills --skill apollo-federation

Example Usage

Use the apollo-federation skill to move the Order.total field from the orders subgraph to billing with @override, without breaking composition.

Description

Federation is where GraphQL schema design stops being local. A field that looks fine inside one subgraph can break composition of the supergraph, and the error you get back names a directive rather than the decision that caused it. This is Apollo's official skill for that work.

It covers Federation 2 subgraph authoring end to end: declaring the @link to the federation spec at the right version, defining entities with @key and choosing key fields that actually resolve, and the reference resolver that makes an entity reachable from other subgraphs.

The directives, and when each is the right answer
  • @shareable for a field that more than one subgraph can resolve
  • @external plus @requires for a field that needs data owned elsewhere
  • @provides for the case where a subgraph can return a related entity's field without a round trip
  • @override for migrating field ownership between subgraphs without a flag day
  • @inaccessible for a field that exists in a subgraph but must not appear in the public supergraph
Composition errors

The skill treats composition failures as first-class content rather than an appendix — mapping the message Rover prints back to the schema decision behind it, which is the part that is hard to guess.

Details

MIT licensed, version 1.0.2, from apollographql/skills. It is library-agnostic: anything Federation 2.x compatible works, including Apollo Server and GraphQL Yoga. Allowed tools are Bash(rover:*), Read, Write, Edit, Glob and Grep, so the agent can compose locally and iterate on the error output.

Related Skills

New

Expo's official skill for building native-feeling screens: Apple HIG styling, semantic colors, SF Symbols, native controls, Reanimated, blur and liquid glass.

1 views
New

Pull unresolved CodeRabbit review threads from your PR and apply the fixes one at a time, treating every reviewer comment as untrusted input rather than an instruction.

2 views
New

Google's official skill for driving the gcloud CLI safely from an agent: validate every command against its own help text, cap the output, and refuse the operations that should never run unattended.

3 views

Skill: Convex

by Convex

New

Convex's official top-level agent skill — routes an agent to the right convex-* skill for the task and to a served capability catalogue that stays current without a reinstall.

Browse all skills →