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
Apollo Client useFragment
Search
Yosuke Kurami
August 31, 2022
Programming
2.1k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Apollo Client useFragment
Yosuke Kurami
August 31, 2022
More Decks by Yosuke Kurami
See All by Yosuke Kurami
TypeScript LSP の今までとこれから
quramy
1
2.1k
フロントエンドテストの育て方
quramy
12
3.8k
App Router 悲喜交々
quramy
8
740
上手に付き合うコンポーネントテスト
quramy
6
2.4k
Patched fetch did not work
quramy
6
790
GraphQL あるいは React における自律的なデータ取得について
quramy
18
5.9k
Next.js App Router
quramy
15
3.9k
Fragment Composition of GraphQL
quramy
17
4.8k
reg-viz VRT tools
quramy
4
1.7k
Other Decks in Programming
See All in Programming
SREの積み重ねがAI駆動開発のガードレールになった ― 7つの実践/SRE Guardrails The 7
tomoyakitaura
8
4.9k
Welcome to the "Parametricity" 🏙️ − Generic だけど Specific な世界 −
guvalif
PRO
1
180
AWS CDK を「作」ってみた 〜フルスクラッチで見えた CDK の裏側〜 / aws-cdk-from-scratch
gotok365
3
470
エンジニア向け会社紹介/Findy Company Profile
findyinc
6
360k
AIを活用したE2Eテスト実装効率化のあゆみ / ebisu-mobile-14-kotetu
kotetuco
0
170
エンジニアにデザインハーネスを 〜デザインプロセスを規定するためのハーネス〜 / Design harness from an engineer's perspective
rkaga
2
1.6k
全PRの83%がAIレビューだけでマージできるようになった開発組織はその後どうなったか
athug
0
220
AIエージェントで 変わるAndroid開発環境
takahirom
2
690
技術記事、 専門家としてのプログラマ、 言語化
mizchi
14
7.5k
PHP Application における Kubernetes 内 gRPC 通信
ganchiku
0
520
【やさしく解説 設計編 #0】DDDのコード、読めるのに分からない人へ
panda728
PRO
2
270
これからAgentCoreを触る方へトレンドはGatewayです
har1101
6
500
Featured
See All Featured
4 Signs Your Business is Dying
shpigford
187
22k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
For a Future-Friendly Web
brad_frost
183
10k
From π to Pie charts
rasagy
0
240
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
55k
Rails Girls Zürich Keynote
gr2m
96
14k
Utilizing Notion as your number one productivity tool
mfonobong
4
440
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
730
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
My Coaching Mixtape
mlcsv
0
170
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
310
Transcript
Apollo Client useFragment @Quramy 2022.08.31 #GraphQLTokyo LT
͓ॻ͖ - ࣗݾհ - @Quramy - GraphQL Tokyo ΦʔΨφΠβ -
Web Frontend ΤϯδχΞ - ࠒ React (Next.js) / Apollo Client Ͱ͓ࣄͯ͠·͢ - ࠓ͢͜ͱ - Apollo Client ͷ Future ͬΆ͍ Feature ͷΛ͠·͢ - 2022.08.31 ࣌ͰͷใͳͷͰɺࠓޙେ͖͘มߋ͞ΕΔՄೳੑ͕͋Γ·͢
AC Roadmap IUUQTHJUIVCDPNBQPMMPHSBQIRMBQPMMPDMJFOUCMPCNBJO30"%."1NE
useFragment ͱ Colocation
https://quramy.medium.com/render-as-you-fetch-incremental-graphql-fragments-70e643edd61e
Colocation $PNQPOFOU ࢠ$PNQPOFOU 2VFSZ ࢠ'SBHNFOU Colocated Component Colocated Component React
Component Tree GraphQL Composition Tree
Collocation w/ AC 3.6 $PNQPOFOU ࢠ$PNQPOFOU 2VFSZ ࢠ'SBHNFOU Colocated Component
Colocated Component React Component Tree GraphQL Composition Tree useQuery Fragment Spread partial data as props
Collocation via useFragment $PNQPOFOU ࢠ$PNQPOFOU 2VFSZ ࢠ'SBHNFOU Colocated Component Colocated
Component React Component Tree GraphQL Composition Tree useQuery Fragment Spread partial data as props Cache key useFragment
Example Code - https://github.com/Quramy/apollo-client-37-study/pull/1 -
useFragment ༗ແʹΑΔҧ͍ - ࠓ·Ͱ - Component ͕ Query ݁Ռͷ
data Λ Apollo Cache ͔Βऔಘ͢Δ - Fragment ʹରԠ͢Δ data Component ͕ࢠ Component prop ͱͯ͢͠ - useFragment - Component ͕ Query ݁Ռͷ data Λ Apollo Cache ͔Βऔಘ͢Δ - ࢠ Component Component ͔Β Fragment ͷ Cache key ͷΈΛΒ͏ - Fragment ʹରԠ͢Δ data Component ͕ࣗ Apollo Cache ͔Βऔಘ͢Δ
useFragment ͷಛੑ - -> ࢠ Component ͷ props όέπϦϨʔͰͳ͘ɺStore
͔ΒͷσʔλऔಘͱͳΓɺ ݸʑͷ Component ͕ΑΓࣗతʹՔಇ͢Δ͜ͱʹͳΔ - React Redux ʹ͓͚Δ useSelector ʹ͍ۙଘࡏ - ແବͳมߋݕΛճආ͍͢͠ - - ࢠ - ଙ ͱ͍͏ Component ֊ʹͳ͍ͬͯͨ߹ɺதؒ֊ͷมߋݕΛͬ͢ඈ͠ ͯɺઅ͚ͩ࠶ Render Ͱ͖Δ $PNQPOFOU Store ( Apollo Cache ) useFragment $PNQPOFOU $PNQPOFOU
Background Query - useBackgroundQuery = Apollo Client v3.8 ʹੵ·Ε͍ͯΔ৽ hook.
͜ͷ hook ͕ useFragment Λิ͢Δɺͱ͍͏ݐ͚ͯ https://github.com/apollographql/apollo-client/pull/8783 - ػೳͷΠϝʔδʢଟʣ: - Redux pub/sub తͳΞφϩδʔͱͯ͠ཧղͰ͖ͳ͘ແ͍͕ɺࠓߋඞཁ͔ʁͱײͨ͡ HRMͷൃߦٴͼDBDIFߋ৽ useQuery = useBackgroundQuery + useFragment DBDIFσʔλͷߪಡ
@defer / Suspense - v3.7 ʹ @defer, v3.9 Ͱ React
Suspense ͷରԠ͕༧ఆ͞Ε͍ͯΔ - @defer: Fragment ͷऔಘΛԆͤ͞Δ GraphQL ͷ࣮ݧత༷ - Suspense: Component Λඇಉظॲཧͱڠௐಈ࡞ͤ͞ΔͨΊͷ React v18ͷػೳ - @defer ઌ PR Խ͞Ε͍ͯΔ https://github.com/apollographql/apollo-client/pull/10018/files - ͨͩ͠ɺDeferred ͳ Fragment Λ Component ͔Βར༻͢Δͱ͍͏ έʔε͕·ͩߟྀ͞Ε͍ͯͳ͍༷
@defer Directive - 1 Operation : ෳ ResponseͱͳΔ - Fragment
ʹ༩ - React ͷ Suspense for data fetch ͱ ੑߴ͍(ͣ) query ProductDetailQuery { product(id: 100) { id name imageURL ...DeferredPrice @defer } } fragment DeferredPrice on Product { specialPrice }
@defer Directive
@defer ͱ useFragment - GraphQL ͷΫΤϦ݁Ռͷ͏ͪɺҰ෦ͷ Fragment ͕Ԇ͞ΕΔ߹ɺ Fragment ຖʹҎԼ͕औಘͰ͖ͳͯ͘ͳΒͳ͍
- ࠓ౸ୡͨ͠ͷ͔Ͳ͏͔ (= ඇಉظͷঢ়ଶཧ ) - ౸ୡ͍ͯ͠ΔͷͰ͋Εɺͦͷσʔλ - ͜Εݱߦͷ useQuery ͚ͩͰ͍ͣ͠ͰɺuseFragment ্͕هͷ ׂΛ୲ͬͯ͘ΕΔ͜ͱΛظ͍ͯ͠Δ͕ɺઌ·ͩͦ͏ʁ
None
·ͱΊ - Apollo Client v4 ʹ͚ͯ৭ʑͳػೳ͕࣮͞Εͭͭ͋Δ - Relay
urql ͳͲͷ Client ϥΠϒϥϦͱൺֱ͢ΔͱपճΕؾຯ - طʹ Apollo Client Λӡ༻͍ͯ͠ΔͷͰ͋Εɺࠓͷ͏͔ͪΒ Fragment Colocation Λ͓͚ͬͯɺ useFragment ͷஔ͖͑ࣗମ؆୯ʹ Ͱ͖Δͣ