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
Transcript
13 slides
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
More Decks by Kawakami Natsumi
See All by Kawakami Natsumi
個人開発サービスを使ってもらうための技術選定
natsumican63
1
2k
個人開発を加速させる効率アップ戦術
natsumican63
19
12k
がんばらない個人開発
natsumican63
1
1.5k
スモールスタートのための技術スタック検討
natsumican63
1
350
Other Decks in Programming
See All in Programming
Enforcing Your Architecture with Unit Tests in the AI Era (Swift Connection X)
steliosf
PRO
1
180
AIが実装を担う時代の「技術設計」と「チームマネジメント」
kamina_zzz
2
270
Kawaiicon: Kubernetes, it's no longer cool, but let's secure it anyway!
barnbarn
0
130
私なりのハーネスエンジニアリング ~独自の言語処理系の開発を通して~
seosoft
0
210
AI駆動開発4年目の現在地(『あなたはFDEになるべきか?』イベント資料)
kumaiu
0
650
Apple Intelligenceとオンデバイス時代の到来
yahir0
0
250
AI時代のIaC入門 〜なぜインフラをコードで管理したいのか?〜 / Introduction to IaC in the AI Era
akihisaikeda
6
1.5k
Vapor Mode でアクセシビリティは 壊れないか検証した話
fuqda
1
350
TanStack Vue Query と Pinia Colada から学ぶ非同期状態の型設計
aoshi
0
680
Scalaの型でマルチテナントの認可を守る
nextbeatdev
0
150
クラウドエージェントは、 何がそんなに便利なのか / what makes cloud agents so useful
rkaga
5
900
どうしても Eloquent でリポジトリパターンをやりたいんだ #phpcon_niigata / phpcon-niigata-2026
shogogg
0
550
Featured
See All Featured
Being A Developer After 40
akosma
PRO
92
590k
The Curse of the Amulet
leimatthew05
4
17k
Testing 201, or: Great Expectations
jmmastey
46
8.4k
A Tale of Four Properties
chriscoyier
163
24k
ラッコキーワード サービス紹介資料
rakko
5
5.9M
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.4k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.6k
Embracing the Ebb and Flow
colly
88
5.2k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
830
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
400
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
810