apollo-federation作者: apollographql
Apollo Federation enables composing multiple GraphQL APIs (subgraphs) into a unified supergraph.
npx skills add https://github.com/apollographql/skills --skill apollo-federationApollo 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:
extend schema
@link(url: "https://specs.apollo.dev/federation/v2.12",
import: ["@key", "@shareable", "@external", "@requires", "@provides"])
Import only the directives your subgraph uses.
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 - All federation directives with syntax, examples, and rules
- Schema Patterns - Multi-subgraph patterns and recipes
- Composition - Composition rules, error codes, and debugging
Key Patterns
Entity Definition
type Product @key(fields: "id") {
id: ID!
name: String!
price: Int
}
Entity Contributions Across Subgraphs
# 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
type Product @key(fields: "id") {
id: ID!
size: Int @external
weight: Int @external
shippingEstimate: String @requires(fields: "size weight")
}
Value Types with @shareable
type Money @shareable {
amount: Int!
currency: String!
}
Entity Stub (Reference Without Contributing)
type Product @key(fields: "id", resolvable: false) {
id: ID!
}
Ground Rules
- ALWAYS use Federation 2.x syntax with
@linkdirective - ALWAYS import only the directives your subgraph uses
- NEVER use
@shareablewithout ensuring all subgraphs return identical values for that field - PREFER
@keywith single ID field for simple entity identification - USE
rover supergraph composeto validate composition locally - USE
rover subgraph checkto validate against production supergraph
来自 apollographql 的更多技能
apollo-client
by apollographql
Apollo Client is a comprehensive state management library for JavaScript that enables you to manage both local and remote data with GraphQL. Version 4.x brings improved caching, better TypeScript support, and React 19 compatibility.
apollo-client
by apollographql
Comprehensive guide for building React applications with Apollo Client 4.x, covering queries, mutations, caching, and state management. Supports multiple React frameworks and setups: client-side apps (Vite, CRA), Next.js App Router with React Server Components, React Router 7 with streaming SSR, and TanStack Start Includes hooks for queries ( useQuery , useLazyQuery ), mutations ( useMutation ), and Suspense-based patterns ( useSuspenseQuery , useBackgroundQuery ) for modern React 18+ and 19...
apollo-connectors
by apollographql
Integrate REST APIs into GraphQL supergraphs using @source and @connect directives. Provides a structured 5-step process: research API structure, implement schema with directives, validate via rover supergraph compose , execute connectors, and test coverage Supports request configuration including headers, body payloads, batching for N+1 patterns, and environment variable injection via $env Handles response mapping with field selection, aliasing, sub-selections for nested data, and entity...
apollo-ios
by apollographql
Apollo iOS is a strongly-typed GraphQL client for Apple platforms. It generates Swift types from your GraphQL operations and schema, and ships an async/await client, a normalized cache (in-memory or SQLite-backed), a pluggable interceptor-based HTTP transport that handles queries, mutations, and multipart subscriptions, and an optional WebSocket transport ( graphql-transport-ws ) that can carry any operation type.
apollo-kotlin
by apollographql
Apollo Kotlin is a strongly typed GraphQL client that generates Kotlin models from your GraphQL operations and schema, that can be used in Android, JVM, and Kotlin Multiplatform projects.
apollo-mcp-server
by apollographql
Connect AI agents to GraphQL APIs through the Model Context Protocol with built-in introspection and operation tools. Exposes GraphQL operations as MCP tools; supports three operation sources: local files, GraphOS Studio collections, and persisted query manifests Provides four introspection tools (introspect, search, validate, execute) for schema exploration and ad-hoc query testing; minification mode reduces token usage with compact notation Configurable authentication via static headers,...
apollo-router
by apollographql
Apollo Router is a high-performance graph router written in Rust for running Apollo Federation 2 supergraphs. It sits in front of your subgraphs and handles query planning, execution, and response composition.
apollo-router-plugin-creator
by apollographql
Create native Rust plugins for Apollo Router.