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 / react / esm
Search
Yosuke Kurami
September 27, 2022
Programming
1
310
apollo client / react / esm
Yosuke Kurami
September 27, 2022
Tweet
Share
More Decks by Yosuke Kurami
See All by Yosuke Kurami
App Router 悲喜交々
quramy
7
480
上手に付き合うコンポーネントテスト
quramy
4
1.8k
Patched fetch did not work
quramy
6
570
GraphQL あるいは React における自律的なデータ取得について
quramy
18
4.4k
Next.js App Router
quramy
15
3k
Fragment Composition of GraphQL
quramy
16
3.1k
reg-viz VRT tools
quramy
4
1.3k
NoInfer
quramy
0
220
Precondition with schema directives
quramy
0
1.4k
Other Decks in Programming
See All in Programming
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
7
1.4k
【re:Growth 2024】 Aurora DSQL をちゃんと話します!
maroon1st
0
790
PHPで学ぶプログラミングの教訓 / Lessons in Programming Learned through PHP
nrslib
3
340
「とりあえず動く」コードはよい、「読みやすい」コードはもっとよい / Code that 'just works' is good, but code that is 'readable' is even better.
mkmk884
3
630
Go の GC の不得意な部分を克服したい
taiyow
3
810
各クラウドサービスにおける.NETの対応と見解
ymd65536
0
150
ある日突然あなたが管理しているサーバーにDDoSが来たらどうなるでしょう?知ってるようで何も知らなかったDDoS攻撃と対策 #phpcon.2024
akase244
2
300
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
200
命名をリントする
chiroruxx
1
430
GitHubで育つ コラボレーション文化 : ニフティでのインナーソース挑戦事例 - 2024-12-16 GitHub Universe 2024 Recap in ZOZO
niftycorp
PRO
0
100
create_tableをしただけなのに〜囚われのuuid編〜
daisukeshinoku
0
270
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
110
Featured
See All Featured
Navigating Team Friction
lara
183
15k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
A better future with KSS
kneath
238
17k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
How GitHub (no longer) Works
holman
311
140k
Visualization
eitanlees
146
15k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
17
2.3k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Facilitating Awesome Meetings
lara
50
6.1k
Transcript
Apollo Client ͱ React ͱ ESM @Quramy 2022.9.27 iCare Dev
Meetup#35
About me - Twitter / GitHub: @Quramy - ࣾͰ Web
ϑϩϯτΤϯδχΞͬͯ·͢ - iCare Ͱ GraphQL पΓͷ͓ख͍Λ͍ͯ͠·͢ - TypeScript GraphQL ׂͱੲ͔Β͍ͬͯ·͢
͍͖ͳΓࠓͷ݁ @apollo/client Λ Node.js Ͱ͏ͷ͖ͼ͍͠
@apollo/client ͱ - ݴΘͣͱΕͨ JavaScript ʹ͓͚Δ GraphQL ΫϥΠΞϯτϥΠϒϥϦ - ϑϩϯτΤϯυ͚
GraphQL ϥΠϒϥϦͱͯ͠ฮ. v1.0.0 ͕ϦϦʔε͞Εͨͷ͕ 2017ࠒ - ※ Meta(چ Facebook) ͕ GraphQL ͷ༷Λެ։ͨ͠ͷ2015 - ݱߦͷ҆ఆ൛ v3.6.x - ※ ͍ͭ5ఔલʹ v3.7 ͷ RC ͕ग़·ͨ͠Ͷ 🎉
@apollo/client ͷྺ࢙ - v2.x - ࡉ͔͘ npm ύοέʔδ͕ผΕ͍ͯͨ ։ൃऀ͕ඞཁʹԠͯ͡ɺݸผͷύοέʔδΛΠϯετʔϧ͍ͯͨ͠ -
v3.x - all in one ͳ npm ύοέʔδʹੜ·ΕมΘͬͨ
@apollo/client ͷྺ࢙ - v2.x - ࡉ͔͘ npm ύοέʔδ͕ผΕ͍ͯͨ ։ൃऀ͕ඞཁʹԠͯ͡ɺݸผͷύοέʔδΛΠϯετʔϧ͍ͯͨ͠ -
v3.x - all in one ͳ npm ύοέʔδʹੜ·ΕมΘͬͨ
apollo-client v2.x ͦΕͧΕʹOQNJ͢Δඞཁ͕͋Δ https://github.com/Quramy/apollo-link-fragment-argument/blob/master/src/link.test.ts
@apollo/client ͷྺ࢙ - v2.x - ࡉ͔͘ npm ύοέʔδ͕ผΕ͍ͯͨ ։ൃऀ͕ඞཁʹԠͯ͡ɺݸผͷύοέʔδΛΠϯετʔϧ͍ͯͨ͠ -
v3.x - all in one ͳ npm ύοέʔδʹੜ·ΕมΘͬͨ
@apollo/client v3.x
@apollo/client ͕ఏڙ͢Δػೳ - React ʹಛԽͨ͠ػೳ - Provider / hooks /
SSR ͚ػೳ / HoC (deprecated) - React ͱಠཱͨ͠ػೳ - GraphQL client - Cache - Links
React ͷ༗ແ - ʮ͍ɺ͏ͪ React ͱΈ߹Θ͍ͤͨΘ͚͡Όͳ͍Μ͚ͩͲʯͱ͍͏ ϢʔβʔͲ͏ͨ͠Β͍͍ͷ͔ʁ - ϑϩϯτΤϯυ: Vue.js
/ Angular / Svelte / etc... - αʔόʔαΠυ: Node.js
@apollo/client v3 ͷ Entry points https://www.apollographql.com/blog/announcement/frontend/announcing-the-release-of-apollo-client-3-0/
@apollo/client v3 ͷ Entry points - React ͱҰॹʹ͍͍ͨਓ: - import
{ ApolloClient, ApolloProvider } from "@apollo/client" - npm i @apollo/client ͢Δ͚ͩͰࡁΜͰخ͍͠ - React ෆཁͳਓ: - import { ApolloClient } from "@apollo/client/core" - React ഉআ্ͨ͠Ͱ core ύοέʔδ͚ͩ͑ͯخ͍͠
@apollo/client v3 ͷ Entry points - React ͱҰॹʹ͍͍ͨਓ: - import
{ ApolloClient, ApolloProvider } from "@apollo/client" - npm i @apollo/client ͢Δ͚ͩͰࡁΜͰخ͍͠ - React ෆཁͳਓ: - import { ApolloClient } from "@apollo/client/core" - React ഉআ্ͨ͠Ͱ core ύοέʔδ͚ͩ͑ͯخ͍͠ ฏ͕๚Εͨ
@apollo/client v3 ͷ Entry points - React ͱҰॹʹ͍͍ͨਓ: - import
{ ApolloClient, ApolloProvider } from "@apollo/client" - npm i @apollo/client ͢Δ͚ͩͰࡁΜͰخ͍͠ - React ෆཁͳਓ: - import { ApolloClient } from "@apollo/client/core" - React ഉআ্ͨ͠Ͱ core ύοέʔδ͚ͩ͑ͯخ͍͠ ฏ͕๚Εͨ ͦΜͳ͜ͱͳ͔ͬͨͷͰ͋Δ
- import { ApolloClient } from "@apollo/client/core" - ͜ͷ import
จʮৗʹʯਖ਼͍͠ͷ͔ʁ
ͩΊ͡ΌΜ
͜ΕͩΊ
Default import ?
Ͳ͏ͯ͜͠͏ͳͬͪΌ͏ͷ - @apollo/client ͷαϒσΟϨΫτϦ (/coreͳͲ) Node.js Ͱར༻Մೳͳ ESM ͱͯ͠
Publish͞Ε͍ͯͳ͍ - ผͷ Node.js ESM ͳ ύοέʔδ͔Βڐ͞ΕΔ import จ import AC from "@apollo/client" ͷܗࣜͷΈ - @apollo/client શମΛ load ͢Δ͜ͱʹͳΓɺreact ύοέʔδ͕ແ͍ͱ "Cannot find module" ͷΤϥʔͰམͪΔ - ݁ہʮ react ͕͍Βͳ͍ਓ͚ʯͷखஈ͕ఏڙ͞Ε͍ͯͳ͍͜ͱʹͳͬͯ͠ ·͏
- import { ApolloClient } from "@apollo/client/core" - ͜ͷ import
จʮৗʹʯਖ਼͍͠ͷ͔ʁ - ʮϞδϡʔϧΛղऍ͢Δػߏ࣍ୈͰಈ࡞͕ҟͳΔʯ͕͑ - ྫ͑ɺwebpack Ͱόϯυϧ͢ΔͷͰ͋Ε্هͷ importจҙਤ ௨Γಈ࡞͢Δ - ҰํͰɺNode.js Ͱಈ࡞ͤ͞Δͱ Error ͱͳΔ
@apollo/client ͷґଘؔ - ྫ͑ɺ @graphql-tools Լͷύοέʔδʹ @apollo/client ͷґ ଘΛ͍࣋ͬͯΔͷ͕ଘࡏ͢Δ -
https://github.com/ardatan/graphql-tools/blob/master/packages/links/package.json - ͜ΕΒͷύοέʔδ͕ɺNative Node.js ESM ʹରԠ͢Δ߹ʹ͕ ੜ͡ಘΔ
ྫ: @graphql-tools ͷ ESM ରԠPR https://github.com/ardatan/graphql-tools/pull/4539/files#diff-642f0c35f55c254d08d17c88a9171eebbeb29dd090cc2badde6874a20258dab3
Native Node.js ESM - ͳͥ͜͏͍͏͜ͱ͕ى͖ͯ͠·͏ͷ͔ - npm ύοέʔδϝϯςφʹͱͬͯɺNode.js Native ESM
Λఏڙ͢Δ ͕͍ग़ͨͨ͠Ί - Node.js v14 Ҏ߱Ͱ͋Ε Native ESM ͕ར༻Մೳ - TypeScript 4.7.x ͕ Node.js ͚ ESM Λαϙʔτ - @graphql-tools ͷΑ͏ͳ ʮGraphQL ༻ͷ npm ύοέʔδΛఏڙ͢Δཱ ʯ͔Β͢ΔͱɺNode.js Native ͳ ESM ʹஔ͖͓͖͍͑ͯͨཉٻ͕Ұఆ ͋Δ
- ઌड़ͷ @graphql-tools/links ͷ ESM ରԠͷ݁Ռɺ react ͕ඞਢʹͳͬͯ͠· ͏݅ https://github.com/ardatan/graphql-tools/issues/4582
ʹڍ͛ΒΕͯ ͍Δ. - ٧·Δͱ͜ΖʮApollo Client ଆ͕దͳ export map Λॻ͍ͯ͘Εͳ͍ͱɺ ͜ͷঢ়گ٫Ͱ͖ͳ͍ʯͱ͍͏ͷ͕ Guild ଆͷҙݟ
Apollo Client / React / ESM ͷॴײ - @apollo/client Λ
Node.js ͷϓϩδΣΫτؾܰʹՃ͖͢Ͱͳ͍ - Node.js Native ESM ͕աظ - (ຊདྷෆཁͳͣͷ) react ΛґଘؔʹՃͯ͠·Ͱɺ @apollo/client ͕ඞཁͳέʔεͦ͏ͦ͏ແ͍ͣ
͓·͚ - Apollo Client v4 Ͱ࠶ͼ React ༻ͷϞδϡʔϧΛ opt-in ͳҐஔ͚ͮʹม
͑Α͏ͱ͍ͯ͠Δ https://github.com/apollographql/apollo-client/issues/8190