# @graphql-hive/router-query-planner 中文文档

规范地址：https://npmcn.com/package/%40graphql-hive/router-query-planner/

版本：0\.0\.53
npm 元数据更新时间：2026-11-16T22:30:52.619Z
中文译文更新时间：2026-11-16T23:02:34.211Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40graphql-hive/router-query-planner
原文对照：https://npmcn.com/package/%40graphql-hive/router-query-planner/?lang=original
项目主页：https://the-guild.dev/graphql/hive/docs/router
源码仓库：https://github.com/graphql-hive/router

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

- 包体积（解压后）：14.6 MB，9 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=20
- 运行依赖：0 个
- 首次发布：2025-11-05T11:29:31.668Z
- 最新版本发布：2026-11-16T22:30:52.189Z
- 近 30 天下载量：22911（2026-10-17 至 2026-11-15，npm 官方下载统计）
- 已发布版本数：49（近 12 个月 44 个）

## 中文简介

一个高性能的节点.js addon,包含查询计划器 [蜂巢路由器](https://the-guild.dev/graphql/hive/docs/router). 这个软件包提供GraphQL Federation查询规划能力,与Rust和N-API相建,以达到最佳性能.

## 安装

```sh
npm install @graphql-hive/router-query-planner
```

也可以使用：`pnpm add @graphql-hive/router-query-planner`、`yarn add @graphql-hive/router-query-planner`、`bun add @graphql-hive/router-query-planner`

## README

# @graphql-hive/router-query-planner (英语)

一个高性能的节点.js addon,包含查询计划器 [蜂巢路由器](https://the-guild.dev/graphql/hive/docs/router). 这个软件包提供GraphQL Federation查询规划能力,与Rust和N-API相建,以达到最佳性能.

## 概览

此节点加通包含蜂巢路由器的查询规划器, 允许您生成 [阿波罗联邦使用的查询计划](https://www.apollographql.com/docs/graphos/schema-design/federated-schemas/reference/query-plans)它为规划跨联邦计划的GraphQL业务提供了快速、本地的实施.

## 安装

```bash
npm install @graphql-hive/router-query-planner
# or
yarn add @graphql-hive/router-query-planner
# or
pnpm add @graphql-hive/router-query-planner
```

## 平台支持

此软件包支持以下平台:

-   **链接**: x86 64 and arch64 (英语)
-   **马科斯**: x64 和 arm64 (苹果硅)

该软件包包括所有被支持平台的预建二进制. 已支持Node.js 20+和 Bun 1+.

## 使用量

### 基本用途

要在 TypeScript 中使用,您会先做一些诸如:

```ts
import {
  QueryPlanner,
  type QueryPlan,
} from "@graphql-hive/router-query-planner";

const supergraphSdl = "<your sdl from file or in code>";

const qp = new QueryPlanner(supergraphSdl);

const plan: QueryPlan = qp.plan(/* GraphQL */ `
  {
    posts {
      title
      author {
        name
      }
    }
  }
`);

// see QueryPlan types in lib/node-addon/src/query-plan.d.ts
```

这将生成一个 [阿波罗联邦使用的查询计划](https://www.apollographql.com/docs/graphos/schema-design/federated-schemas/reference/query-plans)。 。 。 .

### 与蜂巢网关合并

蜂巢网关使用此软件包作为备选的联邦查询规划器 [`@graphql-hive/router-runtime`](https://github.com/graphql-hive/gateway/blob/main/packages/router-runtime)。 。 。 .

要使用蜂巢网关, 请先安装运行时间 :

```bash
npm install @graphql-hive/router-runtime
```

然后配置您的网关 :

```ts
// gateway.config.ts
import { defineConfig } from "@graphql-hive/gateway";
import { unifiedGraphHandler } from "@graphql-hive/router-runtime";

export const gatewayConfig = defineConfig({
  unifiedGraphHandler,
});
```

## 常见问题

### @graphql-hive/router-query-planner 是什么？

一个高性能的节点\.js addon,包含查询计划器 蜂巢路由器\. 这个软件包提供GraphQL Federation查询规划能力,与Rust和N-API相建,以达到最佳性能\.

### 如何安装 @graphql-hive/router-query-planner？

在项目目录运行 npm install @graphql-hive/router-query-planner，或使用 pnpm add / yarn add / bun add。

### @graphql-hive/router-query-planner 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @graphql-hive/router-query-planner 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @graphql-hive/router-query-planner 需要什么版本的 Node\.js？

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

### @graphql-hive/router-query-planner 可以商用吗？

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

### @graphql-hive/router-query-planner 的下载量有多少？

根据 npm 官方下载统计，@graphql-hive/router-query-planner 在 2026/10/17 – 2026/11/15 这 30 天内被下载 22,911 次，日均约 764 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @graphql-hive/router-query-planner 还在维护吗？

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

