graphql-code-generator README

The project's README from github.com/dotansimha/graphql-code-generator. As one markdown file: README.md.

GraphQL Code Generator logo Created by The Guild

npm version

https://the-guild.dev/graphql/codegen

GraphQL Code Generator is a tool that generates code out of your GraphQL schema. Whether you are developing a frontend or backend, you can utilize GraphQL Code Generator to generate output from your GraphQL Schema and GraphQL Documents (query/mutation/subscription/fragment).

By analyzing the schema and documents and parsing it, GraphQL Code Generator can output code at a wide variety of formats, based on pre-defined templates or based on custom user-defined ones. Regardless of the language that you're using, GraphQL Code Generator has you covered.

GraphQL Code Generator lets you choose the output that you need, based on plugins, which are very flexible and customizable. You can also write your plugins to generate custom outputs that match your needs.

You can try this tool live on your browser and see some useful examples. Check out GraphQL Code Generator Live Examples.

We currently support and maintain these plugins (TypeScript, Flow, React, Angular, MongoDB, Stencil, Reason, and some more), and there is an active community that writes and maintains custom plugins.

Quick Start

You can find the complete instructions in GraphQL Code Generator website.

Start by installing the basic deps of GraphQL Codegen:

pnpm add graphql
pnpm add -D @graphql-codegen/cli

GraphQL Code Generator lets you setup everything by simply running the following command:

pnpm graphql-codegen init

Question by question, it will guide you through the whole process of setting up a schema, selecting plugins, picking a destination of a generated file, and a lot more.

If you wish to manually setup codegen, follow these instructions.

Besides our docs page, feel free to go through our published Medium articles to get a better grasp of what GraphQL Code Generator is all about:

Contributing

If this is your first time contributing to this project, please do read our Contributor Workflow Guide before you get started off.

Feel free to open issues and pull requests. We're always welcome support from the community.

For a contribution guide specific to this project, please refer to: http://the-guild.dev/graphql/codegen/docs/custom-codegen/contributing.

Code of Conduct

Help us keep GraphQL Code Generator open and inclusive. Please read and follow our Code of Conduct as adopted from Contributor Covenant

License

GitHub license

MIT

graphql-code-generator (dotansimha/graphql-code-generator)

Searching Database…

这是什么?GraphQL Code Generator 是一个工具,它根据你的 GraphQL schema 和操作(查询、变更、订阅、片段)生成代码,并通过插件输出你所配置的语言或框架对应的带类型代码。
这是命令行工具,还是我要导入到代码中的库?它主要是一个命令行工具,你针对 schema 和 GraphQL 文档运行它;实际输出由插件系统生成(TypeScript、Flow、React、Angular、Stencil 等),而不是你手写的代码。
怎样才能在我的项目里跑起来?安装 GraphQL Codegen 的基础依赖,然后运行设置命令;它会通过一系列问题引导你选择 schema、挑选插件并设置输出位置。也支持手动配置。
运行之前我需要准备什么?需要一个 Node.js 环境(16 或更新版本),以及一份现有的 GraphQL schema 和用于生成代码的查询、变更、订阅、片段文档。
要得到我想要的输出,我需要自己写插件吗?通常不需要:已有官方维护的插件,支持 TypeScript、Flow、React、Angular、MongoDB、Stencil 和 Reason,还有许多社区插件。如果都不适合你的场景,你仍然可以编写自定义插件。
开箱即用支持哪些语言和框架?官方维护的插件覆盖 TypeScript、Flow、React、Angular、MongoDB、Stencil 和 Reason,还有许多社区插件扩展到 Java、C# 等其他语言。
我能在设置之前先试用吗?可以,项目网站提供在线浏览器示例,你可以在把工具加入项目之前先看到生成的输出。
前端和后端都能用吗?可以,README 中说明无论你做的是前端还是后端,都可以使用,并且两者都能从同一份 GraphQL schema 生成代码。
Creator
dotansimha
Size
94.9 MB
Stars
11.3K
Age
9y
Commits · 90 Days