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
そのテスト、説明できますか?~LWテスト戦略FW~のご紹介
nakahara
0
170
Spec Driven Development | AI Summit Lisbon
danielsogl
PRO
0
210
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
130
Creating Composable Callables in Contemporary C++
rollbear
0
170
LaravelLive Japan の裏方のすべて — 第188回 PHP勉強会@東京 (2026-06-24)
suguruooki
2
130
Vite+ Unified Toolchain for the Web
naokihaba
0
360
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
12
4.4k
さぁV100、メモリをお食べ・・・
nilpe
0
160
Webフレームワークの ベンチマークについて
yusukebe
0
180
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
260
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
3
970
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
600
Featured
See All Featured
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.6k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.3k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.3k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.7k
Claude Code のすすめ
schroneko
67
230k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.2k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
62
55k
Making Projects Easy
brettharned
120
6.7k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Design in an AI World
tapps
1
250
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1k
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 ͷஔ͖͑ࣗମ؆୯ʹ Ͱ͖Δͣ