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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
Snowflake Summitでの新機能 CoCo / CoWork / snowflake-summit-2026-overall-what-new-coco
tatsuhiro
1
210
吝嗇家のためのAI活用 / AI development for miser - ChatGPT + Issue Driven Development
tooppoo
0
170
Even G2とAWSで推しのエージェントを召喚しよう!
har1101
1
140
SREの積み重ねがAI駆動開発のガードレールになった ― 7つの実践/SRE Guardrails The 7
tomoyakitaura
7
1.3k
AI時代の仕事技芸論〜ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ(スクフェス仙台 2026バージョン)
kuranuki
0
280
コーディングルールの鮮度を保ちたい for SRE NEXT 2026 / keep-fresh-go-internal-conventions-sre-next-2026
handlename
0
110
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
210
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
290
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
5.6k
Hatena Engineer Seminar #37「言語モデルの活用に関する研究」
slashnephy
0
490
作って学ぶ、 JSX (TSX) ランタイムの基本
syumai
7
1.7k
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
3
820
Featured
See All Featured
Done Done
chrislema
186
16k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
340
The Cult of Friendly URLs
andyhume
79
6.9k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.2k
Faster Mobile Websites
deanohume
310
32k
How to Ace a Technical Interview
jacobian
281
24k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
890
Scaling GitHub
holman
464
140k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
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 ͷஔ͖͑ࣗମ؆୯ʹ Ͱ͖Δͣ