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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
Are APIs Still Relevant in the AI Era?
soyuka
0
360
[ハンズオン]AIへの指示だけで「五目並べ」を作ってみよう
satoshi256kbyte
1
290
JPUG勉強会 OSSデータベースの内部構造を理解しよう(第2回)
oga5
0
280
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
340
Java 27新機能 / Java 27 new features
kishida
2
180
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
2.6k
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
260
スマートフォンでモールス信号を送受信する 〜スマートフォンのLEDとカメラで作る光通信の設計と実装〜
atsuki_seo
0
210
モデルのリファクタリングが難しいと思ったら、そもそも複雑だったのはビジネス仕様だった ? / is-the-business-domain-the-real-complexity
hatsu38
0
420
mrbgem 三角測量 開発
ogom
0
130
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
250
Workers Cache を知る
syumai
0
310
Featured
See All Featured
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
620
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
Un-Boring Meetings
codingconduct
0
430
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.4k
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
340
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
310
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
Music & Morning Musume
bryan
48
7.4k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
290
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
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