GraphQL
APIで使用するための問合せ言語の仕様そのものを指す
特定のフレームワーク、ライブラリを指すわけではない
Meta製
2015/7に仕様が公開された
GraphQL specifivaton
website
https://www.apollographql.com/blog/the-concepts-of-graphql-bc68bd819be3/
こんせぷと
実装
GraphQL Client
GraphQL Server
clientとserverに使用するLibraryは同じものを使う必要はない
そもそも片方にしか用意されていないものもある
両方用意されているものは同じものを使ったほうが楽なのかな #??
Debugするやつ
GraphQL Playground
curlやHTTPieでGraphQLを送る
実装によって個別に用意されているやつもある
Apollo Studio Explorerとか
#WIP
GPT-4.icon
GraphQL Schema
Operation
GraphQLのquery
GraphQLのmutation
subscription
https://engineering.mercari.com/blog/entry/20221215-graphql-client-architecture-recommendation/
RESTとGraphQLとgRPCの比較
reqもresも型安全である
Self-documenting(自己文書化)である
TypeScriptと相性が良い
要求した通りのresが返るためover fetchにならない
「このendpointはこの塊を返す」というのをclientは知らなくていい(覚えなくていい)
https://zenn.dev/babel/articles/graphql-typing-for-babel
型安全
Production Ready GraphQL
読むと良いらしい
https://zenn.dev/adwd/articles/4b1e38796bd763
https://zenn.dev/adwd/articles/de331215898739#production-ready-graphql
https://productionreadygraphql.com/articles/
読むと良いらしい
https://zenn.dev/saboyutaka/articles/680542da534de5
https://engineering.mercari.com/blog/entry/20220303-concerns-with-using-graphql/
https://speakerdeck.com/sonatard/rethinking-graphql
https://tech.layerx.co.jp/entry/2022/12/19/230000
koichik (@koichik)
GitHubにShopifyという2大Public GraphQL APIに関わってきたMarc-André Giroux氏でさえGraphQLはPublic APIで使うべきではないと考えてるのか……
むしろそれらに関わってきたからこそ、なのかな
https://www.magiroux.com/eight-years-of-graphql
GraphQLの型
Selection set
GraphQL Editor
tutorialとか、実行のお試し
https://github.com/APIs-guru/graphql-apis
お試しできるやつ集
2021/5/27 ApolloのTutorialをやる
#??
modelingする場合は、サーバー側にEntityが置かれる感じになるのか
たしかにmrsekut.icon
返り値のエイリアス
普通に書くとこんな感じの時、
code:graphql
query liftsAndTrails {
liftCount(status: OPEN)
allLifts {
liftName: name
status
}
}
返り値は、liftCountとallLiftsというkeyを持ったJSONになるが
これはschemaの定義と同じ
これをkeyを書くことで取得時に好きなように変えられる
code:graphql
query liftsAndTrails {
open: liftCount(status: OPEN)
chairlifts: allLifts {
liftName: name
status
}
}
keyは、openとchairliftsになる
query引数
queryの結果をfilteringする
Selection setの中のkeyに対して指定する
ここでは、Selection setの1つであるstatusが、CLOSEDであるもので絞り込む
code:graphql
query closedLifts {
allLifts(status: CLOSED) {
name
status
}
}
短所
N+1問題
https://zenn.dev/yoshii0110/articles/2233e32d276551#graphqlに対する問題(デメリット)
Over-fetching
クライアントで必要な分以上にデータを取得している状態
アンダーフェッチ問題
https://tech.layerx.co.jp/entry/2021/04/12/121427
関連
GraphQL DB
とは #??
GraphQL Server側でやっていた自動生成SQLの非効率さの改善とか?
https://github.com/dgraph-io/dgraph
https://graphjin.com/
https://www.graph.cool/
https://dgraph.io/
Graph CMS
GraphQLでレスポンスを返してくれるHeadlessCM
https://qiita.com/ryo2132/items/ff847079d6927f263f73
CDN for graphQL
https://graphcdn.io/
Schema First
どういうサービスに向いているのか
https://k0kubun.hatenablog.com/entry/graphql
https://qiita.com/shibukawa/items/a913cb4912d32af37bc5
チームの規模がクソデカの時に向いている
LSUDsと呼ぶらしい
large set of unknown developers
対はSSKDs
small set of known developers)
フロントエンドが複数のデータソースにアクセスしている
フロントエンドで複数のプラットフォームのアプリケーションが存在する
サーバーサイドがMicroservicesで実装されている
既存のアプリケーションを変更なしにモダンなフロントエンドを実装したい
フロントエンドでGraphQLを利用して実装したい
https://qiita.com/saboyutaka/items/171f7382cdf75b67d076#graphqlをいつ導入するべきか
https://oisham.hatenablog.com/entry/2022/07/11/033508
nitrogql
@uhyo
https://zenn.dev/uhyo/articles/nitrogql-beta-release
https://github.com/uhyo/nitrogql
Rust実装で、wasmにcompileされる
採用者の声
https://github.blog/2016-09-14-the-github-graphql-api/
github
なぜ採用したか
https://medium.com/soelu-developers/graphqlをプロダクトに採用した所感-c60030b9864c
https://speakerdeck.com/qsona/graphql-changing-and-unchanging
https://user-first.ikyu.co.jp/entry/2019/12/10/111705
https://speakerdeck.com/mackee/graphqlsabawozuo-ruku-simitojie-jue-shou-fa
議論
/graphql-ruby-ja/GraphQLは内部API向きか外部API向きか
https://numb86-tech.hatenablog.com/entry/2022/03/14/203723
nextjs
https://www.youtube.com/watch?v=783ccP__No8
GraphQLのドキュメンタリー
MSW
https://speakerdeck.com/kamiyam/graphqldeshi-udetani-typescriptdexing-woding-yi-suru
tsの型生成
https://speakerdeck.com/nobuhikosawai/improving-online-shopping-site-performance-which-using-the-graphql?slide=2
JSConfJP2019 day2#5de48b4819827000005c3254できいたやつ