@graphql-hive/router-query-planner (英语)
一个高性能的节点.js addon,包含查询计划器 蜂巢路由器. 这个软件包提供GraphQL Federation查询规划能力,与Rust和N-API相建,以达到最佳性能.
概览
此节点加通包含蜂巢路由器的查询规划器, 允许您生成 阿波罗联邦使用的查询计划它为规划跨联邦计划的GraphQL业务提供了快速、本地的实施.
安装
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 中使用,您会先做一些诸如:
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
这将生成一个 阿波罗联邦使用的查询计划。 。 。 .
与蜂巢网关合并
蜂巢网关使用此软件包作为备选的联邦查询规划器 @graphql-hive/router-runtime。 。 。 .
要使用蜂巢网关, 请先安装运行时间 :
npm install @graphql-hive/router-runtime
然后配置您的网关 :
// gateway.config.ts
import { defineConfig } from "@graphql-hive/gateway";
import { unifiedGraphHandler } from "@graphql-hive/router-runtime";
export const gatewayConfig = defineConfig({
unifiedGraphHandler,
});