Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
GraphQL with Apollo Client
Search
Kawakami Natsumi
October 25, 2019
Programming
520
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
GraphQL with Apollo Client
Kawakami Natsumi
October 25, 2019
More Decks by Kawakami Natsumi
See All by Kawakami Natsumi
個人開発サービスを使ってもらうための技術選定
natsumican63
1
2k
個人開発を加速させる効率アップ戦術
natsumican63
20
12k
がんばらない個人開発
natsumican63
1
1.5k
スモールスタートのための技術スタック検討
natsumican63
1
350
Other Decks in Programming
See All in Programming
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
370
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
450
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
370
そのリトライ、死んだコネクションを使い回していませんか ── GoのHTTPクライアントとHTTP/2を実プロダクト障害から学び直す
myus4a
0
340
モバイル交通系ICへのチャージ実例から考える、クロスプラットフォーム開発におけるiOS実機テスト設計とCI運用
yusuga
1
570
技術的負債の返済は、AI時代の複利で効く投資 — 経営としての意思決定とその遂行
curekoshimizu
1
2k
フロントエンドUIフレームワークのこれまでとこれから
ssssota
5
3.1k
速習iPhone Duo対応
yuukiw00w
2
910
世界の中心で、AI(App Intents)をさけぶ ー App Intents中心設計の実践ガイド
touyou
0
740
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
200
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
1
330
技術的負債を組織課題として解く-増えすぎたマイクロサービスとの戦い-
reimaru
1
2.6k
Featured
See All Featured
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
780
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
480
[SF Ruby Conf 2025] Rails X
palkan
3
1.4k
Designing Powerful Visuals for Engaging Learning
tmiket
1
580
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
Amusing Abliteration
ianozsvald
1
320
What does AI have to do with Human Rights?
axbom
PRO
1
2.4k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
500
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
290
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
Transcript
GraphQL with Apollo Client
About Me Kawakami Natsumi @natsumican63 Work for Studio Arcana 2
Agenda 1. GraphQLの何がうれしいのか 2. GraphQLクライアントサイド実装 3
GraphQLだと何がうれしいのか 4
5 { "data": { "pokemon": { "name": "Pikachu", "number": "025",
"weight": { "maximum": "6.75kg" }, "height": { "maximum": "0.45m" }, "classification": "Mouse Pokémon", ~~~~~~~~~~ 中略 ~~~~~~~~~~ "evolutions": [ { "name": "Raichu" } ] } } } GET /pokemon/<pikachu> ピカチュウの図鑑番号と、進化先の ポケモンの図鑑番号が知りたい! 1.リソース取得が過不足なく行えてうれしい
6 { "data": { "pokemon": { "name": "Raichu", "number": "026",
"weight": { "maximum": "33.75kg" }, "height": { "maximum": "0.9m" }, "classification": "Mouse Pokémon" ~~~~~~~~~~ 中略 ~~~~~~~~~~ } } } GET /pokemon/<raichu> ピカチュウの図鑑番号と、進化先の ポケモンの図鑑番号が知りたい! RESTでは、目的のデータを取得するのに複数回リクエストを投げる必要があったり、 不要なデータまで取得してしまうケースがある。
ピカチュウの図鑑番号と、進化先の ポケモンの図鑑番号が知りたい! { "data": { "pokemon": { "number": "025", "evolutions":
[ { "name": "Raichu", "number": "026" } ] } } } POST /graphql { pokemon(name: "pikachu") { number evolutions { name number } } } GraphQLはネストしたデータを一度かつ不要なデータを含まずに取得できるため、ラ ウンドトリップやレスポンスサイズを減縮することができる。
2.スキーマによる型安全がうれしい • GraphQLサーバーは、定義されたスキーマに応じてレスポンスを返す • スキーマによる型付けにより、実装から型情報を取得することができる ◦ ドキュメントも自動生成される 8
GraphQLクライアントサイド実装 9
Apollo Client • GraphQLサーバーと通信するためのクライアントサイドライブラリ ◦ React,Vue,Angular,iOSなどの実装がある ◦ Apollo以外だとRelayとか • 便利機能がたくさん
◦ Loading,errorなどの通信状態の管理 ◦ キャッシュ機構による状態管理 ◦ Optimistic UIの実装が簡単 10
11 Apollo Providerで囲ったコンポーネント下でApollo Clientを使うことができる。
graphql-code-genでTypeScript用の型を自動生成する • GraphQLサーバーのエンドポイントからSchemaを取得 ◦ 実装から取得するので乖離がおこらない • クライアントサイドで利用するデータのクエリを書く • 要求したデータの型定義のみが生成される ◦
Nonnull,Nullableの情報も型として表現される 12
Thank you! 13