@genql/cli

中文文档
6.3.4发布于 2026/06/11MITTypeScriptCommonJS近 30 天下载 25.9万

Generate a TypeScript SDK for any GraphQl API

原始使用文档
文档目录4 节
  1. Type safe Graphql query builder
  2. Example
  3. Why
  4. Sponsors




Type safe Graphql query builder

Write Graphql queries with type validation and auto completion



[!IMPORTANT] Genql is building a cloud platform to automate SDK generation in multiple languages, docs website with examples, changelog website and more. Fill this form if you are interested!

Read the quick start guide to generate your client and start writing queries.

You can stay up to date with the latest changes subscribing to the Genql changelog.

Features

Example

First generate your client with the genql cli.

You can find other cli options here

npm i -D @genql/cli # cli to generate the client code
genql --schema ./schema.graphql --output ./generated

Then you can use your client as follow

import { createClient, everything } from './generated'
const client = createClient()

client
    .query({
        countries: {
            // pass arguments to the query
            __args: {
                filter: {
                    currency: {
                        eq: 'EUR',
                    },
                },
            },
            name: true,
            code: true,
            nestedField: {
                // fetch all scalar fields
                __scalar: true,
            },
        },
    })
    .then(console.log)

The code above will fetch the graphql query below

query {
    countries(filter: { currency: { eq: "EUR" } }) {
        name
        code
        nestedField {
            scalarField1
            scalarField2
        }
    }
}

Why

Genql has a lot of benefits over writing graphql queries by hand:

  • Writing queries is faster thanks to TypeScript auto completion
  • You can safely update your schema and be sure your queries are still valid
  • You can fetch all scalar fields in a type with __scalar: true
  • No graphql package dependency, no runtime parsing of queries
  • You have to generate the client only after your schema changes, not after every query change

Sponsors

Notaku

Notaku

Vercel


Licensed under MIT.

版本与发布记录

@genql/cli 共发布 44 个版本,首次发布于 2020/07/05;过去 12 个月发布了 1 个版本。

版本发布日期距今
6.3.4latest2026/06/115 个月前
6.3.32024/03/302 年前
6.3.22024/02/022 年前
6.3.12024/01/232 年前
6.3.02024/01/182 年前
6.2.12023/08/103 年前

其他发布通道:beta → 2.0.3。

关于 @genql/cli 的常见问题

@genql/cli 是什么?

Generate a TypeScript SDK for any GraphQl API

如何安装 @genql/cli?

在项目目录运行 npm install @genql/cli,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 genql,可以用 npx genql 直接运行。

@genql/cli 支持 TypeScript 吗?

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

@genql/cli 支持 ESM 还是 CommonJS?

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

@genql/cli 可以商用吗?

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

@genql/cli 的下载量有多少?

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

@genql/cli 还在维护吗?

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