@grantjs/schema

中文文档
1.29.0发布于 2026/11/10MITTypeScriptES Module构建来源已验证近 30 天下载 6084

Grant 图QL 计划和生成的类型

中文使用文档
文档目录13 节
  1. 概览
  2. 安装
  3. 使用量
  4. 基本类型
  5. 图QL 操作
  6. 解析器
  7. 发展
  8. 生成类型
  9. 测试
  10. 构建软件包
  11. Schema 结构
  12. 捐款
  13. 许可证

@ granjs/ schema (英语)

GraphQL 计划并为 Grant 生成类型 .

概览

此套件包含:

  • 图QL 计划定义
  • 生成类型脚本
  • 图QL 操作和解析器
  • 其他特定平台类型

安装

npm install @grantjs/schema

使用量

基本类型

import { User, Role, Permission, Organization, Project } from '@grantjs/schema';

const user: User = {
  id: '1',
  email: '[email protected]',
  // ... other properties
};

图QL 操作

import { GetUsersQuery, CreateUserMutation } from '@grantjs/schema';

// Use in your GraphQL operations
const GET_USERS = gql`
  query GetUsers {
    users {
      id
      email
      roles {
        id
        name
      }
    }
  }
`;

解析器

import { Resolvers } from '@grantjs/schema';

const resolvers: Resolvers = {
  Query: {
    users: () => {
      // Your resolver implementation
    },
  },
};

发展

生成类型

# Generate types from GraphQL schema
pnpm generate

# Watch for changes and regenerate
pnpm dev

在下方生成输出 src/generated/ 承诺,必须与其 来源。 CI 运行 pnpm codegen:check (再生成,在任何 diff 上失败),所以编辑 .graphql 文档或 codegen.ts 从来没有 src/generated/ 直接说.

测试

pnpm test

对合并的SDL的结构性断言:它构建,每个操作文件 和无法接触到的种类数 Query编号 :Mutation 被钉住。 见 src/sdl-contract.test.ts。 。 。 .

构建软件包

pnpm build

Schema 结构

src/
├── schema/                   # GraphQL SDL — one directory per domain, each with
│   │                         # inputs/, types/ and (where the domain is on the graph)
│   │                         # queries/ and mutations/
│   ├── base.graphql          # Scalars, shared interfaces, Tenant/SortOrder, Scope
│   └── root.graphql          # Query/Mutation roots the domains extend
├── operations/               # Client operation documents, one directory per domain
├── generated/                # Codegen output — committed, never hand-edited
│   ├── schema-types.ts       # Schema types (owns every type name)
│   ├── graphql.ts            # Operation types + typed document nodes
│   └── resolvers.ts          # Resolver types; imports from schema-types
├── events/                   # Event catalog and envelope types
├── cdm/, notifications/,     # Hand-written contract types that are not codegen'd
│   webhooks/
└── index.ts                  # Public barrel

apps/api 装入每个文件 src/schema/ 输入 makeExecutableSchema这样 任何船只在船上都声明 是否收到询问.

捐款

修改 GraphQL 方案时:

  1. 更新相关的 .graphql 文件在 src/schema/
  2. 运行 pnpm generate 重新生成类型
  3. 更新任何受影响的解析器或操作
  4. 测试更改

许可证

麻省理工学院执照 - 看 自由主义 详细情况.

版本与发布记录

@grantjs/schema 共发布 69 个版本,首次发布于 2026/03/12;过去 12 个月发布了 69 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.29.0latest2026/11/106 天前
1.28.02026/11/098 天前
1.27.12026/11/098 天前
1.27.02026/11/098 天前
1.26.02026/11/0710 天前
1.25.12026/11/0610 天前

关于 @grantjs/schema 的常见问题

@grantjs/schema 是什么?

Grant 图QL 计划和生成的类型

如何安装 @grantjs/schema?

在项目目录运行 npm install @grantjs/schema,或使用 pnpm add / yarn add / bun add。

@grantjs/schema 支持 TypeScript 吗?

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

@grantjs/schema 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@grantjs/schema 可以商用吗?

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

@grantjs/schema 的下载量有多少?

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

@grantjs/schema 还在维护吗?

最新版本 1.29.0 发布于 2026/11/10(6 天前);至今共发布 69 个版本,其中过去 12 个月发布了 69 个;首次发布于 2026/03/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。