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
2k
フロントエンドテストの育て方
quramy
12
3.8k
App Router 悲喜交々
quramy
8
730
上手に付き合うコンポーネントテスト
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
Signal Forms: Details & Live Coding @enterJS 2026 in Mannheim
manfredsteyer
PRO
0
200
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
600
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.3k
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
5.4k
act1-costs.pdf
sumedhbala
0
120
Datadog LLM Observabilityで実現する 安全なLLM Usage 管理
3150
0
120
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
290
Vite+ Unified Toolchain for the Web
naokihaba
0
360
1B+ /day規模のログを管理する技術
broadleaf
0
120
軽量Java基盤の設計 DIコンテナに頼らない、長期保守と1秒起動の実現 JJUG CCC 2026 Spring
macha64
0
590
Developing with AI Agents — Codex, Claude Code & Cowork Practical Guide
x5gtrn
PRO
0
1.3k
OSもどきOS
arkw
0
590
Featured
See All Featured
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.2k
Navigating Weather and Climate Data
rabernat
0
240
For a Future-Friendly Web
brad_frost
183
10k
Mind Mapping
helmedeiros
PRO
1
260
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
2
250
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.3k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
210
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
240
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2.1k
WENDY [Excerpt]
tessaabrams
11
38k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.5k
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 ͷஔ͖͑ࣗମ؆୯ʹ Ͱ͖Δͣ