GraphQLライブラリ gqlgencを作成した

Twitter: @Yamashou0314

Github: Yamashou

Yamashou

Appify Technologies

Software Engineer

 

Language: Go, Typescript

Framework: React, Apollo

Twitter: @Yamashou0314

Github: Yamashou

 

目次

  • GraphQL
  • GraphQLと環境
  • なぜgqlgencが必要になったか
  • GraphQL Client 定義
  • Go GraphQL Client
  • Go GraphQL Library
  • gqlgenc紹介とサンプル
  • GraphQL x Go 活動紹介
  • facebookから発表したAPIクエリ言語およびランタイム
  • 表現力の高く、複雑なデータ構造も表現&取得可能
  • オーバーフェッチングを避けられる

 

GraphQL

GraphQLと環境

  • 日本だとgRPCとかなり検索対象として並ぶ
  • 実際記事やコミュニティサイズではGraphQLまだまだ
  • さまざまな企業が採用を始めている

GraphQLと環境

  • 日本だとgRPCとかなり検索対象として並ぶ
  • 実際記事やコミュニティサイズではGraphQLまだまだ
  • さまざまな企業が採用を始めている

GraphQLと環境

https://graphql.org/users

  • 日本だとgRPCとかなり検索対象として並ぶ
  • 実際記事やコミュニティサイズではGraphQLまだまだ
  • さまざまな企業が採用を始めている

  

なぜ必要になったか

既存API

Server Code

Client Code

e2e用クライアント

なぜ必要になったか

Server Code

Client Code

なぜ必要になったか

Server Code

Client Code

gqlgen

Schema

Query

なぜ必要になったか

Server Code

Client Code

gqlgen

Schema

Query

?

?

なぜ必要になったか

Server Code

Client Code

gqlgen

Schema

Query

gqlgenc

何が良くなるのか

Schema編集

Server

gqlgen

Query編集

Client修正

Client

何が良くなるのか

Schema編集

Server

gqlgen

Query編集

Client

gqlgenc

GraphQL Client定義

  • GraphQL Schema Parser
  • Intorospection to Client Schema
  • GraphQL Query Parser
  • GraphQL Query Response Model Generator
  • GraphQL Client Generator
  • GraphQL JSON Parser

GraphQL Client定義

  • GraphQL Schema Parser
    GraphQLスキーマを静的解析してASTツリーを作る
  • Intorospection to Client Schema
    サーバーからSchema情報を取得してASTツリーを作る
  • GraphQL Query Parser
    GraphQLクエリーを静的解析してASTツリーを作る
  • GraphQL Query Response Model Generator
    スキーマとクエリーのASTからGraphQLの型を生成する
  • GraphQL Client Generator
    生成された型を利用してGraphQLのリクエストとレスポンスを受けるコードを生成する
  • GraphQL JSON Parser
    GraphQL特有のJSONをパースして、生成された型にマッピングする

Go GraphQL Client

Go GraphQL Client

  • GraphQL Schema Parser
  • Intorospection to Client Schema
  • GraphQL Query Parser
  • GraphQL Query Response Model Generator
  • GraphQL Client Generator
  • GraphQL JSON Parser

Go GraphQL Client

  • GraphQL Schema Parser
  • Intorospection to Client Schema
  • GraphQL Query Parser
  • GraphQL Query Response Model Generator
  • GraphQL Client Generator
  • GraphQL JSON Parser

Go GraphQL Library

  • GraphQL Schema Parser:
              github.com/vektah/gqlparser
  • Intorospection to Client Schema: 🙅‍♀️
  • GraphQL Query Parser:
          github.com/vektah/gqlparser
  • GraphQL Query Response Model Generator:
       
     github.com/99designs/gqlgenがModelのみ生成
  • GraphQL Client Generator: 🙅‍♀️
  • GraphQL JSON Parser:
         
    github.com/shurcooL/graphql

作成が必要なもの

  • Intorospection to Client Schema
  • GraphQL Query Response Model Generator
  • GraphQL Client Generator

gqlgenc

  • IntorospectionからSchema情報を取得できます。
  • 定義したQueryからクライアントの型を生成
  • 生成した型を使ったクライアントを生成
  • gqlgenのplugin機構をベースに構築

GraphQL x Go

GraphQL x Go

  • github.com/99designs/gqlgen
  • github.com/gqlgo/gqlanalysis
  • github.com/gqlgo/gqlint
  • github.com/Code-Hex/gqldoc

🎉Let's enjoy🎉
GraphQL with Go

Made with Slides.com