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
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
5.4k
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2.3k
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
260
Inside Stream API
skrb
1
790
Hatena Engineer Seminar #37「言語モデルの活用に関する研究」
slashnephy
0
200
Even G2とAWSで推しのエージェントを召喚しよう!
har1101
1
130
AIを活用したE2Eテスト実装効率化のあゆみ / ebisu-mobile-14-kotetu
kotetuco
0
130
Lessons from Spec-Driven Development
simas
PRO
0
220
鹿野さんに聞く!『TypeScriptコードレシピ集』で磨く実践力
tonkotsuboy_com
4
840
作って学ぶ、 JSX (TSX) ランタイムの基本
syumai
7
1.7k
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
290
JavaDoc 再入門
nagise
1
420
Featured
See All Featured
30 Presentation Tips
portentint
PRO
1
330
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.1k
Building AI with AI
inesmontani
PRO
1
1.1k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
First, design no harm
axbom
PRO
2
1.2k
KATA
mclloyd
PRO
35
15k
Making Projects Easy
brettharned
120
6.7k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.6k
Designing for Timeless Needs
cassininazir
1
260
Unsuck your backbone
ammeep
672
58k
Skip the Path - Find Your Career Trail
mkilby
1
150
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
400
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 ͷஔ͖͑ࣗମ؆୯ʹ Ͱ͖Δͣ