# @apollo/federation-subgraph-compatibility 中文文档

规范地址：https://npmcn.com/package/%40apollo/federation-subgraph-compatibility/

版本：3\.0\.1
npm 元数据更新时间：2026-08-03T19:25:32.244Z
中文译文更新时间：2026-11-06T11:08:14.825Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40apollo/federation-subgraph-compatibility
原文对照：https://npmcn.com/package/%40apollo/federation-subgraph-compatibility/?lang=original
项目主页：https://github.com/apollographql/apollo-federation-subgraph-compatibility/blob/main/packages/script/README.md
源码仓库：https://github.com/apollographql/apollo-federation-subgraph-compatibility

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：23.8 kB，12 个文件
- TypeScript 类型：未声明
- Node.js 要求：\>=24\.0\.0
- 运行依赖：3 个
- 首次发布：2022-12-06T17:17:58.911Z
- 最新版本发布：2026-08-03T19:25:31.872Z
- 近 30 天下载量：4239（2026-10-07 至 2026-11-05，npm 官方下载统计）
- 已发布版本数：29（近 12 个月 2 个）

## 中文简介

用于检查子图与联邦网关兼容性的 CLI 工具

## 安装

```sh
npm install @apollo/federation-subgraph-compatibility
```

也可以使用：`pnpm add @apollo/federation-subgraph-compatibility`、`yarn add @apollo/federation-subgraph-compatibility`、`bun add @apollo/federation-subgraph-compatibility`

## README

# 阿波罗联邦子图兼容性测试

[![NPM Version](https://img.shields.io/npm/v/@apollo/federation-subgraph-compatibility)](https://www.npmjs.com/package/@apollo/federation-subgraph-compatibility) [![Continuous Integration](https://github.com/apollographql/apollo-federation-subgraph-compatibility/workflows/Continuous%20Integration/badge.svg)](https://github.com/apollographql/apollo-federation-subgraph-compatibility/actions?query=workflow%3A%22Continuous+Integration%22) [![Join the community forum](https://img.shields.io/badge/Join%20The%20Community-Forum-blueviolet)](https://community.apollographql.com/) [![MIT License](https://img.shields.io/github/license/apollographql/apollo-federation-subgraph-compatibility)](https://github.com/apollographql/apollo-federation-subgraph-compatibility/blob/main/LICENSE)

`@apollo/federation-subgraph-compatibility` 脚本是国家防范机制的软件包,允许您测试给定子图的执行是否兼容 [阿波罗联邦分图规格](https://www.apollographql.com/docs/federation/subgraph-spec/)这个测试套件对照子图的执行验证了联邦的各种特征。 见 [兼容性测试文件](https://npmcn.com/package/COMPATIBILITY.md) 关于预期计划、数据集和已执行测试信息的详细信息.

-   [阿波罗联邦子图兼容性测试](https://npmcn.com/package/%40apollo/federation-subgraph-compatibility/#readme-apollo-federation-subgraph-compatibility-testing)
    -   [安装](https://npmcn.com/package/%40apollo/federation-subgraph-compatibility/#readme-installation)
    -   [使用量](https://npmcn.com/package/%40apollo/federation-subgraph-compatibility/#readme-usage)
        -   [总理](https://npmcn.com/package/%40apollo/federation-subgraph-compatibility/#readme-pm2)
        -   [多克编曲](https://npmcn.com/package/%40apollo/federation-subgraph-compatibility/#readme-docker-compose)
        -   [测试结果](https://npmcn.com/package/%40apollo/federation-subgraph-compatibility/#readme-test-results)
        -   [调试模式](https://npmcn.com/package/%40apollo/federation-subgraph-compatibility/#readme-debug-mode)
    -   [联系人](https://npmcn.com/package/%40apollo/federation-subgraph-compatibility/#readme-contact)
    -   [警卫](https://npmcn.com/package/%40apollo/federation-subgraph-compatibility/#readme-security)
    -   [许可证](https://npmcn.com/package/%40apollo/federation-subgraph-compatibility/#readme-license)

## 安装

阿波罗联邦子图相容性测试脚本发布给国家预防机制.

```shell
npm install --dev @apollo/federation-subgraph-compatibility
```

您可以使用 [国家PX](https://docs.npmjs.com/cli/v7/commands/npx)

```shell
# remote package
npx @apollo/federation-subgraph-compatibility --help

# package installed locally
npx fedtest --help

# package installed globally
fedtest --help
```

## 使用量

`@apollo/federation-subgraph-compatibility` 测试脚本启动一个由您的子图执行、两个参考子图和 [阿波罗路由器](https://github.com/apollographql/router)。由于脚本需要管理多个进程,所以需要指定哪些进程管理技术应用于运行测试。 当前脚本支持 [总理](https://pm2.keymetrics.io/) 财务报告和审定财务报表 [多克编曲](https://docs.docker.com/compose/)。 。 。 .

```shell
npx fedtest --help
Usage: fedtest [options] [command]

Run Apollo Federation subgraph compatibility tests

Options:
  -V, --version             output the version number
  -h, --help                display help for command

Commands:
  pm2 [options]             Start supergraph using PM2
  docker [options]          Start supergraph using Docker Compose
  help [options] [command]  display help for command
```

### 总理

[总理](https://pm2.keymetrics.io/) 是一个以节点为基础的进程管理器。 当测试使用时 `pm2` 命令,脚本将使用 [阿波罗漫游者](https://github.com/apollographql/rover) `dev` 命令.

```shell
npx fedtest pm2 --help
Usage: fedtest pm2 [options]

Start supergraph using PM2

Options:
  --config <subgraph.config.js>  optional PM2 configuration file
  --debug                        debug mode with extra log info
  --endpoint <url>               subgraph endpoint
  --failOnRequired               boolean flag to indicate whether any failing required test should fail the script.
  --failOnWarning                boolean flag to indicate whether any failing test should fail the script.
  --format <json|markdown>       optional output file format (choices: "json", "markdown", default: "markdown")
  -h, --help                     display help for command
  --quiet                        suppress logging to minimum
  --schema <schema.graphql>      optional path to schema file, if omitted composition will fallback to introspection
```

如果您的子图已经启动并运行, 您可以使用 PM2 运行兼容性测试 `--endpoint <url>` 选项。 这将创造出使用内测来读取子图图的超地图.

```shell
npx fedtest pm2 --endpoint http://localhost:8080/graphql
```

如果有可用的子图方案,也可以在命令行上指定. Schema路径可以是绝对的或相对当前目录的.

```shell
npx fedtest pm2 --endpoint http://localhost:8080/graphql --schema /path/to/schema.graphql
```

PM2也可以用来启动您的子图. 您可以指定一个 [生态系统配置文件](https://pm2.keymetrics.io/docs/usage/application-declaration/) 包含如何启动子图的信息.

```js
// simple PM2 subgraph config that starts Node application
module.exports = {
    apps : [{
      name   : "subgraph product",
      script : "index.js",
      cwd: "/path/to/your/implementation"
    }]
}
```

```shell
npx fedtest pm2 --endpoint http://localhost:8080/graphql --config /path/to/subgraph.config.js
```

### 多克编曲

[多克编曲](https://docs.docker.com/compose/) 是运行多容器 Docker 应用程序的工具。 当测试使用时 `docker` 命令,脚本将使用 [阿波罗漫游者](https://github.com/apollographql/rover) `supergraph compose` 命令和运行独立的路由器图像.

```shell
npx fedtest docker --help
Usage: fedtest docker [options]

Start supergraph using Docker Compose

Options:
  --compose <docker-compose.yaml>  Path to docker compose file
  --debug                          debug mode with extra log info
  --failOnRequired                 boolean flag to indicate whether any failing required test should fail the script.
  --failOnWarning                  boolean flag to indicate whether any failing test should fail the script.
  --format <json|markdown>         optional output file format (choices: "json", "markdown", default: "markdown")
  -h, --help                       display help for command
  --path <path>                    GraphQL endpoint path (default: "")
  --port <port>                    HTTP server port (default: "4001")
  --quiet                          suppress logging to minimum
  --schema <schema.graphql>        Path to schema file
```

为了使用 `docker` 命令,您需要同时通过作曲文件和子图计划文件. 文件路径可以是绝对的,也可以是相对于当前工作目录的.

```shell
npx fedtest docker --compose /path/to/docker-compose.yaml --schema /path/to/schema.graphql
```

Docker Compose文件是一个YAML配置文件,它定义了运行您的应用程序所需的所有服务,网络和音量. 对于阿波罗联邦的兼容性测试 我们要求您定义一个叫做 `products` 显示您的 GraphQL 端点 `http://localhost:4001`。 。 。 .

```yaml
services:
  products:
    # must be a relative path to the directory that will be used to run the tests
    # if you are going to run the tests from the same directory as your docker file, then you can specify .
    build: path/to/my-implementation
    # expose ports
    ports:
      - 4001:4001
```

如果您的应用程序暴露自定义路径( 例如 ) . `/graphql`)或使用不同的端口,确保也将这些值指定为命令行参数.

```shell
# docker compose file starts subgraph exposing http://localhost:8080/graphql
npx fedtest docker --compose /path/to/docker-compose.yaml --schema /path/to/schema.graphql --path /graphql --port 8080
```

作曲文件示例,请参见此寄存器中的示例执行. 欲了解更多详情,请参见: [Docker 编写文档](https://docs.docker.com/compose/compose-file/)。 。 。 .

### 测试结果

脚本记录了控制台上的相容性测试结果并生成相应的结果文件. 默认情况下,脚本将以平分格式生成结果. 您可以通过指定和 `--format json` 选项.

```shell
# generate results.json file
npx fedtest pm2 --endpoint http://localhost:8080/graphql --format json
```

### 调试模式

为了启用提供更多动词日志的调试模式, 请指定 `--debug` 选项.

```shell
npx fedtest pm2 --endpoint http://localhost:8080/graphql --debug
```

## 联系人

如果您对测试库或代码有特定问题,请在 [阿波罗社区论坛](https://community.apollographql.com/)。 。 。 .

## 警卫

有关如何联系小组处理安全问题的更多信息,见我们 [安全政策](https://github.com/apollographql/.github/blob/main/SECURITY.md)。 。 。 .

## 许可证

这个图书馆的许可依据是 [《麻省理工学院许可证》](https://npmcn.com/package/LICENSE)。 。 。 .

## 常见问题

### @apollo/federation-subgraph-compatibility 是什么？

用于检查子图与联邦网关兼容性的 CLI 工具

### 如何安装 @apollo/federation-subgraph-compatibility？

在项目目录运行 npm install @apollo/federation-subgraph-compatibility，或使用 pnpm add / yarn add / bun add。它还提供命令行工具 fedtest，可以用 npx fedtest 直接运行。

### @apollo/federation-subgraph-compatibility 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/apollo\_\_federation-subgraph-compatibility 是否存在。

### @apollo/federation-subgraph-compatibility 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=24\.0\.0。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @apollo/federation-subgraph-compatibility 可以商用吗？

@apollo/federation-subgraph-compatibility 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @apollo/federation-subgraph-compatibility 的下载量有多少？

根据 npm 官方下载统计，@apollo/federation-subgraph-compatibility 在 2026/10/07 – 2026/11/05 这 30 天内被下载 4,239 次，日均约 141 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @apollo/federation-subgraph-compatibility 还在维护吗？

最新版本 3\.0\.1 发布于 2026/08/04（3 个月前）；至今共发布 29 个版本，其中过去 12 个月发布了 2 个；首次发布于 2022/12/07。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

