Upgrade to Pro — share decks privately, control downloads, hide ads and more …

gql.tada の紹介

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.
Avatar for hirataku hirataku
April 19, 2024

gql.tada の紹介

Avatar for hirataku

hirataku

April 19, 2024
Tweet

More Decks by hirataku

Other Decks in Technology

Transcript

  1. 自己紹介 • Taku Hiramatsu(ひらたく) • X: @hirataq__ ◦ (最近アカウント作り直しました) •

    関西在住、娘👭 • 趣味はサッカー、山登り、コードを書くこと • ソフトウェアエンジニア • 経歴 ◦ 新卒で株式会社フリークアウト ◦ いくつかの新規事業に従事 ◦ 2020/6〜 株式会社カケハシ
  2. Web フロントエンドにおける GraphQL 開発体験 • TypeScript と GraphQL の相性は抜群 •

    エコシステムも充実している ◦ 特に GraphQL Code Generator
  3. GraphQL Code Generator をフル活用 GraphQL を利用する Web フロントエンドにおいて、GraphQL Code Generator

    のエコシステムは強力。利用しない手はない。 (以前、GraphQLスキーマからの自動生成 - フロントエンド開発体験の向上と いうタイトルで以前 LT させてもらいました) Web フロントエンドにおける GraphQL 開発体験
  4. GraphQL Code Generator はプラグインが豊富 私は以下をよく使っています • @graphql-codegen/client-preset ◦ フロントエンド開発に必要なプラグインの組み合わせ ◦

    TypedDocumentNode を生成(メジャーな GraphQL クライアントがサポート) ◦ Fragment Colocation を支援する fragment-masking の機能を提供 • @graphql-codegen/typescript-msw ◦ MSWモックハンドラを生成してくれる • graphql-codegen-typescript-mock-data ◦ GraphQL レスポンスモックデータの factory 関数の生成をしてくれる Web フロントエンドにおける GraphQL 開発体験
  5. @graphql-codegen/client-preset の課題 ① コンポーネントに書く GraphQL operation, fragment に補完が効かない。 コード生成するまで正しく記述できているかわからない。 ②

    コンポーネントに GraphQL operation, fragment を書いた後、コード生成 しないと、コンパイルエラーになる Web フロントエンドにおける GraphQL 開発体験
  6. @graphql-codegen/client-preset の課題 fragment-masking を導入し、Fragment Colocation したコンポーネントの増加 ↓ fragment を書く機会の増加 ↓

    fragment を書き換えるたびに、コード再生成(graphql-codegen)=> エディタのTS サーバ再起動(VSCode => `TypeScript: Restart TS server`)を実行 Web フロントエンドにおける GraphQL 開発体験
  7. @graphql-codegen/client-preset の課題 fragment-masking を導入し、Fragment Colocation したコンポーネントの増加 ↓ fragment を書く機会の増加 ↓

    fragment を書き換えるたびに、コード再生成(graphql-codegen)=> エディタのTS サーバ再起動(VSCode => `TypeScript: Restart TS server`)を実行 Web フロントエンドにおける GraphQL 開発体験
  8. @graphql-codegen/client-preset の課題 fragment-masking を導入し、Fragment Colocation したコンポーネントの増加 ↓ fragment を書く機会の増加 ↓

    fragment を書き換えるたびに、コード再生成(graphql-codegen)=> エディタのTS サーバ再起動(VSCode => `TypeScript: Restart TS server`)を実行 もうちょっと体験が良くなるといいな Web フロントエンドにおける GraphQL 開発体験
  9. gql.tada のモチベーション gql.tada as a project was started to answer

    the question: “Why can’t we teach TypeScript to understand the GraphQL query language?” ref: https://gql-tada.0no.co/get-started/ 訳: gql.tada は、「TypeScript に GraphQL クエリ言語を理解させること はできないか」という問いに答えるために開始されたプロジェクトです。 gql.tada とは
  10. Magical GraphQL query engine for TypeScript • parses your GraphQL

    documents in the TypeScript type system ◦ TSの型システムで、GraphQLドキュメントをパース • uses your introspected schema and scalar configuration to derive a schema ◦ イントロスペクトされたスキーマとスカラーを使用してスキーマを導出 • maps your GraphQL queries and fragments with the schema to result and variables types ◦ GraphQL クエリとフラグメントをスキーマを使用して結果と変数の型にマッピング • creates fragment masks and enforces unwrapping fragments gradually ◦ フラグメントマスクを作成し、フラグメントのアンラップを段階的に強制 gql.tada とは ↑をTypeScriptの型システム、型チェッカーで実施するため、 コード編集中に即時反映される!
  11. Magical GraphQL query engine for TypeScript • parses your GraphQL

    documents in the TypeScript type system ◦ TSの型システムで、GraphQLドキュメントをパース • uses your introspected schema and scalar configuration to derive a schema ◦ イントロスペクトされたスキーマとスカラーを使用してスキーマを導出 • maps your GraphQL queries and fragments with the schema to result and variables types ◦ GraphQL クエリとフラグメントをスキーマを使用して結果と変数の型にマッピング • creates fragment masks and enforces unwrapping fragments gradually ◦ フラグメントマスクを作成し、フラグメントのアンラップを段階的に強制 gql.tada とは ↑をTypeScriptの型システム、型チェッカーで実施するため、 コード編集中に即時反映される! よさそう
  12. gql.tada の開発体験 その他 • client-preset の makeFragmentData (テストや Storybook で便利な

    モック Fragment 生成関数)相当の関数(readFragment)もある