GraphQL Codegen
https://gyazo.com/422a6a667b49d620fb21aa0740f971b7
基本的に型を生成するが、一部のpluginは実装を生成するものもある
例えば、react-queryで使いやすい形で生成してくれるなど
コマンド
$ bunx graphql-codegen --config codegen.ts
codegenする
Plugin
GraphQLスキーマからTypeScriptの型を生成するプラグイン
エンティティやスカラー型をTypeScriptにマッピング
GraphQL APIエンドポイントからスキーマファイルを生成するプラグイン
(既にスキーマファイルがある場合はオプション)
GraphQL オートコンプリート用の TypeScript 言語サーバープラグイン (オプション)
Getting Started
Introduction
Installation
Development workflow
CIとかの話
ESM TypeScript usage
Guides
Vanilla TypeScript
React Query
React / Vue
Apollo Server / GraphQL Yoga
Apollo Server / GraphQL Yoga with Server Preset
API Testing
GraphQL Modules
Further Reading
Config Reference
codegen.ts
schema field
documents field
plugin config
require field
Naming Convention
Lifecycle Hooks
Multi Project
Advanced Usage
Generated files colocation
Programmatic Usage
CLIではなくプログラム内から生成指示したい時
How does it work?
Profiler
Document Transform
Integrations
VSCode Extension
Prettier & Linters
Apollo Federation
apollo-local-state
create-react-app
Gatsby
Writing Plugins
What are Plugins?
Plugin structure
Validate Configuration
Extend Schema
Using Visitor Pattern
Contributing
、GraphQLサーバーからスキーマを取得してTypeScriptの型定義が書かれたファイルを生成することができます。
graphql-codegenのツール群は、GraphQLを使って開発するなら絶対に知っておいたほうがいいと思うので、まだ知らない方は以下のドキュメントをサッと眺めてみることをおすすめします ref