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
270
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
53
メールアドレスを深堀りする
bary822
2
1.1k
kiba ETLで小さく始めるデータ分析基盤構築
bary822
3
250
AR_migrationの例外.pdf
bary822
0
51
Featured
See All Featured
Building Adaptive Systems
keathley
41
2.5k
Code Reviewing Like a Champion
maltzj
523
40k
Testing 201, or: Great Expectations
jmmastey
42
7.5k
Code Review Best Practice
trishagee
68
18k
The Power of CSS Pseudo Elements
geoffreycrofte
75
5.8k
How to train your dragon (web standard)
notwaldorf
91
6k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Product Roadmaps are Hard
iamctodd
PRO
53
11k
Making Projects Easy
brettharned
116
6.2k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
47
2.7k
Building Better People: How to give real-time feedback that sticks.
wjessup
368
19k
Statistics for Hackers
jakevdp
799
220k
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にサヨナラするのか • 学習コスト • 周辺ライブラリ