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
phperだってパンチカードでコーディングしたい
o0h
PRO
0
410
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
2
1.2k
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
470
Kotlinize Is Not Just Converting to Kotlin
chigichan24
1
190
Apple Intelligenceとオンデバイス時代の到来
yahir0
0
120
Groovy as a human and AI friendly programming language
paulk
0
110
우리의 Nitro Modules는 당신의 Turbo Modules보다 아름답다
l2hyunwoo
0
200
sbt 2.0: takeoff
eed3si9n
0
170
Event is what happens
moro
2
1.5k
Seven New Principles of Software Engineering
yegor256
0
280
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
390
Performance Optimization With LLMs
xleitix
0
200
Featured
See All Featured
Google's AI Overviews - The New Search
badams
0
1.6k
How to train your dragon (web standard)
notwaldorf
96
6.9k
Side Projects
sachag
456
43k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
300
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
1
460
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
12k
Ethics towards AI in product and experience design
skipperchong
2
440
Testing 201, or: Great Expectations
jmmastey
46
8.4k
The Curse of the Amulet
leimatthew05
3
16k
Fireside Chat
paigeccino
43
4.1k
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