# @devoxa/prisma-relay-cursor-connection 中文文档

规范地址：https://npmcn.com/package/%40devoxa/prisma-relay-cursor-connection/

版本：3\.1\.3
npm 元数据更新时间：2025-12-08T02:03:26.264Z
中文译文更新时间：2026-11-12T03:53:53.921Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40devoxa/prisma-relay-cursor-connection
原文对照：https://npmcn.com/package/%40devoxa/prisma-relay-cursor-connection/?lang=original
源码仓库：https://github.com/devoxa/prisma-relay-cursor-connection

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

- 包体积（解压后）：275 kB，43 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- 运行依赖：1 个
- peer 依赖：@prisma/client \>=2\.0\.0
- 首次发布：2020-06-17T18:44:12.282Z
- 最新版本发布：2025-12-08T02:03:26.008Z
- 近 30 天下载量：129598（2026-10-12 至 2026-11-10，npm 官方下载统计）
- 已发布版本数：20（近 12 个月 1 个）

## 中文简介

扩展 Prisma 范围 `findMany` 支持中继光标连接的方法

## 安装

```sh
npm install @devoxa/prisma-relay-cursor-connection
```

也可以使用：`pnpm add @devoxa/prisma-relay-cursor-connection`、`yarn add @devoxa/prisma-relay-cursor-connection`、`bun add @devoxa/prisma-relay-cursor-connection`

## README

# 棱镜-中继-曲线连接

#### 扩展 [普丽斯玛](https://www.prisma.io/) `findMany` 支持的方法 [中继光标连接](https://relay.dev/graphql/connections.htm)

 [![Package Version](https://img.shields.io/npm/v/@devoxa/prisma-relay-cursor-connection?style=flat-square)](https://www.npmjs.com/package/@devoxa/prisma-relay-cursor-connection)[![Build Status](https://img.shields.io/github/actions/workflow/status/devoxa/prisma-relay-cursor-connection/push.yml?branch=master&style=flat-square) ](https://github.com/devoxa/prisma-relay-cursor-connection/actions?query=branch%3Amaster+workflow%3A%22Continuous+Integration%22)[![Code Coverage](https://img.shields.io/codecov/c/github/devoxa/prisma-relay-cursor-connection/master?style=flat-square)](https://codecov.io/github/devoxa/prisma-relay-cursor-connection)

[安装](https://npmcn.com/package/%40devoxa/prisma-relay-cursor-connection/#readme-installation) 二. 支助 [使用量](https://npmcn.com/package/%40devoxa/prisma-relay-cursor-connection/#readme-usage) 二. 支助 [捐款](https://npmcn.com/package/%40devoxa/prisma-relay-cursor-connection/#readme-contributing) 二. 支助 [贡献者](https://npmcn.com/package/%40devoxa/prisma-relay-cursor-connection/#readme-contributors) 二. 支助 [许可证](https://npmcn.com/package/%40devoxa/prisma-relay-cursor-connection/#readme-license)

  

## 安装

```bash
yarn add @devoxa/prisma-relay-cursor-connection
```

此模块对等端依赖 `@prisma/client`您可以在 [软件包.json](https://npmcn.com/package/%40devoxa/prisma-relay-cursor-connection/package.json) (单位:千美元)`peerDependencies`) (中文(简体) ).

## 使用量

### 一般使用

这个模块验证连接参数以确保它们与Prisma合作. 以下内容: 组合得到支持 :

-   `{}` 所有资源
-   `{ first: number }` 第一个X资源
-   `{ first: number, after: string }` Id Y 之后的第一个 X 资源
-   `{ last: number }` 最后一个 X 资源
-   `{ last: number, before: string }` Id Y 之前的最后 X 资源

如果您正在通过用户提供的数据,则需要在代码中检查两例,以防止 用户同时读取过多的资源 :

-   一个 `first` | `last` 必须定义
-   `first` | `last` 必须低于合理上限(例如100个)

```ts
import {
  findManyCursorConnection,
  ConnectionArguments,
} from '@devoxa/prisma-relay-cursor-connection'

const result = await findManyCursorConnection(
  (args) => client.todo.findMany(args),
  () => client.todo.count(),
  { first: 5, after: '5c11e0fa-fd6b-44ee-9016-0809ee2f2b9a' } // typeof ConnectionArguments
)
```

### 类型安全参数

您也可以使用额外的 `FindManyArgs` 在保持类型安全的前提下:

```ts
import { findManyCursorConnection } from '@devoxa/prisma-relay-cursor-connection'

const baseArgs = {
  select: { id: true, isCompleted: true },
  where: { isCompleted: true },
}

const result = await findManyCursorConnection(
  (args) => client.todo.findMany({ ...args, ...baseArgs }),
  () => client.todo.count({ where: baseArgs.where }),
  { last: 5, before: '5c11e0fa-fd6b-44ee-9016-0809ee2f2b9a' }
)

// Type error: Property text does not exist
result.edges[0].node.text
```

### 自定义光标

默认情况下,光标是 `id` 区域。 如果你想用另一个领域, 复合索引,或处理编码/解码,可以通过下列选项:

```ts
import { findManyCursorConnection } from '@devoxa/prisma-relay-cursor-connection'

const result = await findManyCursorConnection(
  (args) => client.todo.findMany(args),
  () => client.todo.count(),
  { first: 5, after: 'eyJpZCI6MTZ9' },
  {
    getCursor: (record) => ({ id: record.id }),
    encodeCursor: (cursor) => Buffer.from(JSON.stringify(cursor)).toString('base64'),
    decodeCursor: (cursor) => JSON.parse(Buffer.from(cursor, 'base64').toString('ascii')),
  }
)
```

您可以在 [单位测试](https://npmcn.com/package/%40devoxa/prisma-relay-cursor-connection/tests/index.spec.ts)。 。 。 .

### 自定义边缘和节点

默认情况下,边缘由 `cursor` 编辑 `node`。如果您想要添加 字段到边缘或节点,您可以通过以下选项:

```ts
import { findManyCursorConnection } from '@devoxa/prisma-relay-cursor-connection'

const result = await findManyCursorConnection(
  (args) => client.todo.findMany(args),
  () => client.todo.count(),
  { first: 5, after: 'eyJpZCI6MTZ9' },
  {
    recordToEdge: (record) => ({
      node: { ...record, extraNodeField: 'Foo' },
      extraEdgeField: 'Bar',
    }),
  }
)
```

箱外的这个会为您推断出修改过的类型 .

### 解析信息

您可以将 GraphQL 解析信息传送到可自动删除额外 Prisma 选项中 查询您 GraphQL 查询中没有的字段。 这主要有用,如果你不是 使用 `totalCount` 您的页码逻辑或您只想要查询 `totalCount` 没有 边缘.

```ts
import { findManyCursorConnection } from '@devoxa/prisma-relay-cursor-connection'
import { GraphQLResolveInfo } from 'graphql'

const resolveInfo: GraphQLResolveInfo = {
  // ...
}

const result = await findManyCursorConnection(
  (args) => client.todo.findMany(args),
  () => client.todo.count(),
  { first: 5, after: '5c11e0fa-fd6b-44ee-9016-0809ee2f2b9a' },
  { resolveInfo }
)
```

## 捐款

```bash
# Setup the test database
yarn prisma migrate dev --preview-feature

# Run the tests
yarn test
```

## 贡献者

感谢这些伟大的人[emoji 密钥](https://allcontributors.org/docs/en/emoji-key):

<table><tbody><tr><td align="center"><a href="https://www.david-reess.de/" rel="nofollow noopener noreferrer"><img alt="David Reeß" src="https://avatars3.githubusercontent.com/u/4615516?v=4?s=75" width="75px;" loading="lazy" decoding="async" referrerpolicy="no-referrer"><br><sub><b>大卫·瑞斯</b></sub></a><br><a href="https://github.com/devoxa/prisma-relay-cursor-connection/commits?author=queicherius" title="Code" rel="nofollow noopener noreferrer">💻</a> <a href="https://github.com/devoxa/prisma-relay-cursor-connection/commits?author=queicherius" title="Documentation" rel="nofollow noopener noreferrer">📖</a> <a href="https://github.com/devoxa/prisma-relay-cursor-connection/commits?author=queicherius" title="Tests" rel="nofollow noopener noreferrer">⚠️</a></td><td align="center"><a href="https://twitter.com/controlplusb" rel="nofollow noopener noreferrer"><img alt="Sean Matheson" src="https://avatars2.githubusercontent.com/u/12164768?v=4?s=75" width="75px;" loading="lazy" decoding="async" referrerpolicy="no-referrer"><br><sub><b>肖恩·马西森</b></sub></a><br><a href="https://github.com/devoxa/prisma-relay-cursor-connection/commits?author=ctrlplusb" title="Code" rel="nofollow noopener noreferrer">💻</a> <a href="https://github.com/devoxa/prisma-relay-cursor-connection/commits?author=ctrlplusb" title="Tests" rel="nofollow noopener noreferrer">⚠️</a></td><td align="center"><a href="https://marcjulian.de/?ref=github" rel="nofollow noopener noreferrer"><img alt="Marc" src="https://avatars1.githubusercontent.com/u/8985933?v=4?s=75" width="75px;" loading="lazy" decoding="async" referrerpolicy="no-referrer"><br><sub><b>马克</b></sub></a><br><a href="https://github.com/devoxa/prisma-relay-cursor-connection/commits?author=marcjulian" title="Code" rel="nofollow noopener noreferrer">💻</a></td><td align="center"><a href="http://jeongsd.dev/" rel="nofollow noopener noreferrer"><img alt="Jeong Seong Dae" src="https://avatars1.githubusercontent.com/u/7903426?v=4?s=75" width="75px;" loading="lazy" decoding="async" referrerpolicy="no-referrer"><br><sub><b>贞成大</b></sub></a><br><a href="https://github.com/devoxa/prisma-relay-cursor-connection/commits?author=jeongsd" title="Code" rel="nofollow noopener noreferrer">💻</a> <a href="https://github.com/devoxa/prisma-relay-cursor-connection/commits?author=jeongsd" title="Tests" rel="nofollow noopener noreferrer">⚠️</a></td><td align="center"><a href="https://github.com/ahmetuysal" rel="nofollow noopener noreferrer"><img alt="Ahmet Uysal" src="https://avatars.githubusercontent.com/u/26417668?v=4?s=75" width="75px;" loading="lazy" decoding="async" referrerpolicy="no-referrer"><br><sub><b>亚美特·维萨尔</b></sub></a><br><a href="https://github.com/devoxa/prisma-relay-cursor-connection/commits?author=ahmetuysal" title="Code" rel="nofollow noopener noreferrer">💻</a> <a href="https://github.com/devoxa/prisma-relay-cursor-connection/commits?author=ahmetuysal" title="Tests" rel="nofollow noopener noreferrer">⚠️</a></td><td align="center"><a href="https://github.com/nicksrandall" rel="nofollow noopener noreferrer"><img alt="Nick Randall" src="https://avatars.githubusercontent.com/u/1800460?v=4?s=75" width="75px;" loading="lazy" decoding="async" referrerpolicy="no-referrer"><br><sub><b>尼克·兰德尔</b></sub></a><br><a href="https://github.com/devoxa/prisma-relay-cursor-connection/commits?author=nicksrandall" title="Code" rel="nofollow noopener noreferrer">💻</a></td><td align="center"><a href="https://github.com/igo" rel="nofollow noopener noreferrer"><img alt="Igor Urminček" src="https://avatars.githubusercontent.com/u/55597?v=4?s=75" width="75px;" loading="lazy" decoding="async" referrerpolicy="no-referrer"><br><sub><b>伊戈尔·乌尔明切克</b></sub></a><br><a href="https://github.com/devoxa/prisma-relay-cursor-connection/commits?author=igo" title="Documentation" rel="nofollow noopener noreferrer">📖</a></td></tr><tr><td align="center"><a href="https://github.com/TheAschr" rel="nofollow noopener noreferrer"><img alt="Alex Schrimpf" src="https://avatars.githubusercontent.com/u/10580515?v=4?s=75" width="75px;" loading="lazy" decoding="async" referrerpolicy="no-referrer"><br><sub><b>亚历克斯·施里普夫</b></sub></a><br><a href="https://github.com/devoxa/prisma-relay-cursor-connection/commits?author=TheAschr" title="Code" rel="nofollow noopener noreferrer">💻</a></td><td align="center"><a href="https://github.com/marinarierav" rel="nofollow noopener noreferrer"><img alt="Marina Riera" src="https://avatars.githubusercontent.com/u/47626039?v=4?s=75" width="75px;" loading="lazy" decoding="async" referrerpolicy="no-referrer"><br><sub><b>玛丽娜·瑞拉</b></sub></a><br><a href="https://github.com/devoxa/prisma-relay-cursor-connection/commits?author=marinarierav" title="Code" rel="nofollow noopener noreferrer">💻</a></td><td align="center"><a href="https://kervin.tech/" rel="nofollow noopener noreferrer"><img alt="Kervin Vasquez" src="https://avatars.githubusercontent.com/u/15281277?v=4?s=75" width="75px;" loading="lazy" decoding="async" referrerpolicy="no-referrer"><br><sub><b>卡尔文·瓦斯克兹</b></sub></a><br><a href="https://github.com/devoxa/prisma-relay-cursor-connection/commits?author=kervin5" title="Code" rel="nofollow noopener noreferrer">💻</a> <a href="https://github.com/devoxa/prisma-relay-cursor-connection/commits?author=kervin5" title="Tests" rel="nofollow noopener noreferrer">⚠️</a></td><td align="center"><a href="http://stackoverflow.com/users/515932/jeff-gu-kang?tab=profile" rel="nofollow noopener noreferrer"><img alt="Jeff Gu Kang" src="https://avatars.githubusercontent.com/u/216363?v=4?s=75" width="75px;" loading="lazy" decoding="async" referrerpolicy="no-referrer"><br><sub><b>杰夫·顾康</b></sub></a><br><a href="https://github.com/devoxa/prisma-relay-cursor-connection/commits?author=JeffGuKang" title="Documentation" rel="nofollow noopener noreferrer">📖</a></td><td align="center"><a href="https://orta.io/" rel="nofollow noopener noreferrer"><img alt="Orta Therox" src="https://avatars.githubusercontent.com/u/49038?v=4?s=75" width="75px;" loading="lazy" decoding="async" referrerpolicy="no-referrer"><br><sub><b>Orta 热力学</b></sub></a><br><a href="https://github.com/devoxa/prisma-relay-cursor-connection/commits?author=orta" title="Code" rel="nofollow noopener noreferrer">💻</a> <a href="https://github.com/devoxa/prisma-relay-cursor-connection/commits?author=orta" title="Documentation" rel="nofollow noopener noreferrer">📖</a> <a href="https://github.com/devoxa/prisma-relay-cursor-connection/commits?author=orta" title="Tests" rel="nofollow noopener noreferrer">⚠️</a></td><td align="center"><a href="https://github.com/Kareem-Medhat" rel="nofollow noopener noreferrer"><img alt="Kareem-Medhat" src="https://avatars.githubusercontent.com/u/39652808?v=4?s=75" width="75px;" loading="lazy" decoding="async" referrerpolicy="no-referrer"><br><sub><b>卡来姆-梅德哈特</b></sub></a><br><a href="https://github.com/devoxa/prisma-relay-cursor-connection/commits?author=Kareem-Medhat" title="Code" rel="nofollow noopener noreferrer">💻</a></td></tr></tbody></table>

本项目遵循 [全部贡献者](https://github.com/all-contributors/all-contributors) 规格。 任何捐款都欢迎!

## 许可证

麻省理工学院

## 常见问题

### @devoxa/prisma-relay-cursor-connection 是什么？

扩展 Prisma 范围 findMany 支持中继光标连接的方法

### 如何安装 @devoxa/prisma-relay-cursor-connection？

在项目目录运行 npm install @devoxa/prisma-relay-cursor-connection，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：@prisma/client（\>=2\.0\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @devoxa/prisma-relay-cursor-connection 支持 TypeScript 吗？

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

### @devoxa/prisma-relay-cursor-connection 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @devoxa/prisma-relay-cursor-connection 可以商用吗？

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

### @devoxa/prisma-relay-cursor-connection 的下载量有多少？

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

### @devoxa/prisma-relay-cursor-connection 还在维护吗？

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

