Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
GraphQLを_Rubyで気軽に試す.pdf
Search
Hiroto Fukui
August 31, 2018
0
300
GraphQLを_Rubyで気軽に試す.pdf
Hiroto Fukui
August 31, 2018
Tweet
Share
More Decks by Hiroto Fukui
See All by Hiroto Fukui
Deploy from slack
bary822
0
64
メールアドレスを深堀りする
bary822
2
1.1k
kiba ETLで小さく始めるデータ分析基盤構築
bary822
3
260
AR_migrationの例外.pdf
bary822
0
59
Featured
See All Featured
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
33
2.4k
YesSQL, Process and Tooling at Scale
rocio
173
14k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.8k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
11
1.1k
How to Think Like a Performance Engineer
csswizardry
26
1.9k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
252
21k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
34
6k
Designing for humans not robots
tammielis
253
25k
Optimising Largest Contentful Paint
csswizardry
37
3.4k
The World Runs on Bad Software
bkeepers
PRO
70
11k
Done Done
chrislema
185
16k
Transcript
GraphQLを Rubyで気軽に試す Hiroto Fukui @bary822 Ruby関西 #83
Who 2014 - 2017 2017 - Hiroto Fukui @bary822
Who
Who Osaka Tokyo
Who
Who
Who
Who
Who
• What • Why • History • Req & Res
Example • What's special? ◦ Type ◦ Introspection • Demo • Challenges
What
Query Language
Query Language SQL GraphQL
Query Language SQL GraphQL
Why REST
/mobile • デバイス毎に最適化されたAPI • PC > mobile
/v2 • バージョン管理 • 互換性
GET /product GET /inventory GET /shipping GET /payment
docs
{ “status”: 400, “message”: “Bad Request” }
None
History • 2012 - Facebookが内部向けに開発 • 2015 - 仕様がRFCとして公開される •
2015 - React Europeでお披露目される • 2018 - Working Draft
増え続けるエンドポイント 滞るドキュメント更新 止まない問い合わせ
None
Automatically Solved!! • 単一エンドポイント • 適切で具体的なエラーメッセージ • ドキュメントの更新
Example
Request POST http://api.example.com/graphql?{dog(dogId:1):{name,wei ght,color}}
Request POST http://api.example.com/graphql? { dog(dogId: 1):{ name, weight color }
}
Response { "data": { "dog": { "name": "Goemon", "weight": 20.0,
"color": "Red" } } }
☝ • Requestに記述した欲しいデータだけが同じフォーマットで 帰ってきている • 1つのエンドポイント(/graphql)だけですべてのリソースを提供 できる • データを取得しているけど、HTTP methodはPOST
Type
DogType { name: String weight: Float color: String favoriteToys: [ToyType]
friends: [DogType] }
Client Server DogType ToyType name, color name DogType ToyType name,
color name
None
Client Server /dog name, color, weight, ... DogType ToyType OwnerType
FoodType name, category, ... name, gender, ... name, ingredient, ...
None
Introspection
POST http://.../graphql { IntrospectionQuery: { ... } } { "Dog":
{ "name": "String", "weight": "Float", "color": "String", ... } "Owner": { name: "String", dogs: ["Dog"] } }
None
Client Server DogType ToyType Self-Validation Static-Validation Auto-Generated Error Message
# Request POST http://api.example.com/graphql?query= { dog(dogId: "Not an integer"){ name
} }
# Response { "errors": [ { "message": "Argument 'dogId' on
Field 'dog' has an invalid value. Expected type 'Int!'.", "locations": [{ "line": 2, "column": 2} ], "fields": [ "query", "dog", "dogId" ] } ] }
mid-summary • GraphQLは欲しいデータを記述するためのAPI問い合わせ言 語である • GraphQLを使うと複数のクライアントの要望に対応しやすく、 その後のメンテナンスもしやすい • GraphQLは強く型付けされた言語であり、それによってAPI運 用にで発生する典型的な辛みを解決できる
None
graphql-ruby
https://github.com /bary822/graphql-api-rails
None
(demo) - auto-genrated doc - req&res - validation
Challenges • 既に多くのREST APIクライアントを抱えている場合 • いつRESTにサヨナラするのか • 学習コスト • 周辺ライブラリ