@devoxa/prisma-relay-cursor-connection

中文文档
3.1.3发布于 2025/12/08MITCommonJS近 30 天下载 13万

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

中文使用文档
文档目录10 节
  1. 安装
  2. 使用量
  3. 一般使用
  4. 类型安全参数
  5. 自定义光标
  6. 自定义边缘和节点
  7. 解析信息
  8. 捐款
  9. 贡献者
  10. 许可证

棱镜-中继-曲线连接

扩展 普丽斯玛 findMany 支持的方法 中继光标连接

Package Version Build Status Code Coverage

安装 二. 支助 使用量 二. 支助 捐款 二. 支助 贡献者 二. 支助 许可证


安装

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

此模块对等端依赖 @prisma/client您可以在 软件包.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个)
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 在保持类型安全的前提下:

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 区域。 如果你想用另一个领域, 复合索引,或处理编码/解码,可以通过下列选项:

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')),
  }
)

您可以在 单位测试。 。 。 .

自定义边缘和节点

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

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 没有 边缘.

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 }
)

捐款

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

# Run the tests
yarn test

贡献者

感谢这些伟大的人emoji 密钥:

David Reeß
大卫·瑞斯

💻 📖 ⚠️
Sean Matheson
肖恩·马西森

💻 ⚠️
Marc
马克

💻
Jeong Seong Dae
贞成大

💻 ⚠️
Ahmet Uysal
亚美特·维萨尔

💻 ⚠️
Nick Randall
尼克·兰德尔

💻
Igor Urminček
伊戈尔·乌尔明切克

📖
Alex Schrimpf
亚历克斯·施里普夫

💻
Marina Riera
玛丽娜·瑞拉

💻
Kervin Vasquez
卡尔文·瓦斯克兹

💻 ⚠️
Jeff Gu Kang
杰夫·顾康

📖
Orta Therox
Orta 热力学

💻 📖 ⚠️
Kareem-Medhat
卡来姆-梅德哈特

💻

本项目遵循 全部贡献者 规格。 任何捐款都欢迎!

许可证

麻省理工学院

版本与发布记录

@devoxa/prisma-relay-cursor-connection 共发布 20 个版本,首次发布于 2020/06/18;过去 12 个月发布了 1 个版本。

版本发布日期距今
3.1.3latest2025/12/0811 个月前
3.1.22024/11/291.9 年前
3.1.12023/11/212 年前
3.1.02023/08/023 年前
3.0.02023/07/293 年前
2.2.42023/07/253 年前

关于 @devoxa/prisma-relay-cursor-connection 的常见问题

@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 和提交记录判断。