Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
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
440
上手に付き合うコンポーネントテスト
quramy
4
1.6k
Patched fetch did not work
quramy
6
550
GraphQL あるいは React における自律的なデータ取得について
quramy
17
4.3k
Next.js App Router
quramy
15
3k
Fragment Composition of GraphQL
quramy
16
3k
reg-viz VRT tools
quramy
4
1.2k
NoInfer
quramy
0
210
Precondition with schema directives
quramy
0
1.4k
Other Decks in Programming
See All in Programming
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
3
350
WebAssembly Unleashed: Powering Server-Side Applications
chrisft25
0
1.9k
Arm移行タイムアタック
qnighy
0
390
PipeCDの歩き方
kuro_kurorrr
3
130
[FlutterKaigi2024] Effective Form 〜Flutterによる複雑なフォーム開発の実践〜
chocoyama
0
3.9k
Cognitoが大型アップデート!Managed Loginとパスワードレスログインを実際に使ってみた@しむそくRadio Special Day1
tmhirai
2
130
Develop iOS apps with Neovim / vimconf_2024
uhooi
1
120
Contemporary Test Cases
maaretp
0
150
macOS なしで iOS アプリを開発する(※ただし xxx に限る)
mitsuharu
1
150
subpath importsで始めるモック生活
10tera
0
380
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
3
820
Micro Frontends Unmasked Opportunities, Challenges, Alternatives
manfredsteyer
PRO
0
180
Featured
See All Featured
The Cost Of JavaScript in 2023
addyosmani
45
6.9k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
How to Ace a Technical Interview
jacobian
276
23k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
17k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Designing for Performance
lara
604
68k
RailsConf 2023
tenderlove
29
910
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
Designing the Hi-DPI Web
ddemaree
280
34k
For a Future-Friendly Web
brad_frost
175
9.4k
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