implement-trpc-query

Installation
SKILL.md

tRPC 按需查询接口设计规范

本 Skill 指导在 tRPC 架构下,通过标准化的 includefields 参数,为查询接口添加按需数据加载与字段裁剪能力,无需引入 GraphQL。

使用说明

  1. 阅读 按需查询设计指南,了解参数设计规范与执行流程
  2. 参考 Router 实现示例 了解完整实现
  3. 参考 Schema 定义示例:BattleSchema.tsBattleExtendedSchema.tsGetBattleInputSchema.ts
  4. 使用 检查清单 验证实现是否符合规范

核心规范

  • 双参数设计include(扩展字段加载)+ fields(响应裁剪),职责分离
  • 三步执行流程:基础查询 → include 扩展加载 → fields 字段裁剪
  • 枚举 include 选项:使用 z.enum([...]) 明确声明支持的扩展字段名
  • 权限校验:扩展字段按需进行权限检查(不加载即不暴露)
  • 一级限制:仅支持一级扩展,禁止嵌套 include(如 user.friends.votes
  • 降级安全fields 包含未加载的 include 字段时,静默忽略并记录 warning
Related skills

More from forge-town/skills

Installs
5
GitHub Stars
5
First Seen
Mar 26, 2026