apollo-federation by apollographql/skills
npx skills add https://github.com/apollographql/skills --skill apollo-federationApollo Federation 支持将多个 GraphQL API(子图)组合成一个统一的超级图。
每个 Federation 2 子图都必须通过 @link 选择加入:
extend schema
@link(url: "https://specs.apollo.dev/federation/v2.12",
import: ["@key", "@shareable", "@external", "@requires", "@provides"])
仅导入你的子图使用的指令。
| 指令 | 用途 | 示例 |
|---|---|---|
@key | 定义具有唯一键的实体 | type Product @key(fields: "id") |
@shareable |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 允许多个子图解析字段 |
type Position @shareable { x: Int! } |
@external | 引用来自另一个子图的字段 | weight: Int @external |
@requires | 依赖于外部字段的计算字段 | shippingCost: Int @requires(fields: "weight") |
@provides | 有条件地解析外部字段 | @provides(fields: "name") |
@override | 将字段迁移到此子图 | @override(from: "Products") |
@inaccessible | 从 API 模式中隐藏 | internalId: ID! @inaccessible |
@interfaceObject | 向实体接口添加字段 | type Media @interfaceObject |
特定主题的详细文档:
type Product @key(fields: "id") {
id: ID!
name: String!
price: Int
}
# Products 子图
type Product @key(fields: "id") {
id: ID!
name: String!
price: Int
}
# Reviews 子图
type Product @key(fields: "id") {
id: ID!
reviews: [Review!]!
averageRating: Float
}
type Product @key(fields: "id") {
id: ID!
size: Int @external
weight: Int @external
shippingEstimate: String @requires(fields: "size weight")
}
type Money @shareable {
amount: Int!
currency: String!
}
type Product @key(fields: "id", resolvable: false) {
id: ID!
}
@link 指令的 Federation 2.x 语法@shareable@key 进行简单的实体标识rover supergraph compose 在本地验证组合rover subgraph check 根据生产环境超级图进行验证每周安装量
185
仓库
GitHub 星标数
32
首次出现
2026年1月30日
安全审计
安装于
github-copilot176
codex172
gemini-cli170
opencode170
kimi-cli168
amp168
Apollo Federation enables composing multiple GraphQL APIs (subgraphs) into a unified supergraph.
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.
| 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 |
Detailed documentation for specific topics:
type Product @key(fields: "id") {
id: ID!
name: String!
price: Int
}
# 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
}
type Product @key(fields: "id") {
id: ID!
size: Int @external
weight: Int @external
shippingEstimate: String @requires(fields: "size weight")
}
type Money @shareable {
amount: Int!
currency: String!
}
type Product @key(fields: "id", resolvable: false) {
id: ID!
}
@link directive@shareable without ensuring all subgraphs return identical values for that field@key with single ID field for simple entity identificationrover supergraph compose to validate composition locallyrover subgraph check to validate against production supergraphWeekly Installs
185
Repository
GitHub Stars
32
First Seen
Jan 30, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
github-copilot176
codex172
gemini-cli170
opencode170
kimi-cli168
amp168
飞书OpenAPI Explorer:探索和调用未封装的飞书原生API接口
15,500 周安装