@gatsbyjs/relay-compiler

中文文档
2.0.0-printer-fix.4发布于 2019/08/23MITCommonJS近 30 天下载 2.9万

A compiler tool for building GraphQL-driven applications.

原始使用文档

Relay Compiler

Relay-Compiler is a code-generation toolkit for GraphQL. It contains the core functionalities of GraphQL code-gen, including file parsing, validation, syntax tree parsing and transformation.

The GraphQL-Compiler package exports library code which you may use to find the modules you need, or to extend the compiler with your own custom input and output. Note, the internal APIs of the GraphQL-Compiler are under constant iteration, so rolling your own version may lead to incompatibilities with future releases.

The following graph illustrates the high-level architecture of a complete GraphQL code-generation pipeline:

CodegenPipeline

To understand the underlying workflow of the core compilation step, which is what happens in the "GraphQL Compiler" block in the above graph, please refer HERE.

You can build your own version of the Compiler by adding your own FileWriter, and by swapping or adding a FileParser and additional IRTransforms (IR, which stands for Intermediate Representation, a special-purpose syntax tree format designed for transformability).

  • The GraphQL-Compiler package provides a GraphQLFileParser, which can be used to parse general .graphql files, and a GraphQLTextParser, which can be used to parse GraphQL text in any source files with customized tags. You can also write your own FileParser at your discretion.

  • You can add additional IRTransforms by extending the basic GraphQLIRTransforms. A sample can be found HERE.

  • Similarly, you can add additional validation rules by extending the basic GraphQLValidator. Sample HERE.

  • A sample FileWriter can be found HERE.

To actually run your compiler, you will also need a script to assemble all the above components. A sample file can be found HERE.

版本与发布记录

@gatsbyjs/relay-compiler 共发布 5 个版本,首次发布于 2019/02/14;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.0.0-printer-fix.4latest2019/08/237 年前
2.0.0-printer-fix.32019/08/237 年前
2.0.0-printer-fix.22019/02/147 年前
2.0.0-printer-fix2019/02/147 年前
2.0.12019/02/147 年前

关于 @gatsbyjs/relay-compiler 的常见问题

@gatsbyjs/relay-compiler 是什么?

A compiler tool for building GraphQL-driven applications.

如何安装 @gatsbyjs/relay-compiler?

在项目目录运行 npm install @gatsbyjs/relay-compiler,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:graphql(^14.1.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。它还提供命令行工具 relay-compiler,可以用 npx relay-compiler 直接运行。

@gatsbyjs/relay-compiler 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/gatsbyjs__relay-compiler 是否存在。

@gatsbyjs/relay-compiler 支持 ESM 还是 CommonJS?

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

@gatsbyjs/relay-compiler 可以商用吗?

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

@gatsbyjs/relay-compiler 的下载量有多少?

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

@gatsbyjs/relay-compiler 还在维护吗?

最新版本 2.0.0-printer-fix.4 发布于 2019/08/23(7 年前);至今共发布 5 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/02/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。