@graphcommerce/magento-cart 10.0.0 → 10.0.1-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -290
- package/hooks/useCartQuery.ts +3 -3
- package/hooks/useFormGqlMutationCart.ts +4 -7
- package/link/cartLink.ts +4 -11
- package/package.json +15 -15
- package/typePolicies.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 10.0.1-canary.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#2571](https://github.com/graphcommerce-org/graphcommerce/pull/2571) [`78a2a8a`](https://github.com/graphcommerce-org/graphcommerce/commit/78a2a8a919346e1f9bccddf7e52682f4adb9a4e0) - Solve issue where the @client fields could not be resolved correctly. ([@paales](https://github.com/paales))
|
|
8
|
+
|
|
9
|
+
## 10.0.1-canary.0
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#2568](https://github.com/graphcommerce-org/graphcommerce/pull/2568) [`f1b60ac`](https://github.com/graphcommerce-org/graphcommerce/commit/f1b60accf5e8fdbcba15b7567dce7ff68f37db88) - Solve issue where the cache wasn't available from the context anymore in @apollo/client@4 now uses the operation.client.cache ([@paales](https://github.com/paales))
|
|
14
|
+
|
|
3
15
|
## 10.0.0
|
|
4
16
|
|
|
5
17
|
### Major Changes
|
|
@@ -124,296 +136,6 @@
|
|
|
124
136
|
|
|
125
137
|
- [#2493](https://github.com/graphcommerce-org/graphcommerce/pull/2493) [`b6f76b6`](https://github.com/graphcommerce-org/graphcommerce/commit/b6f76b61f235d3336d8d296f1bed61c9f5daf325) - Solve issue where available_payment_methods would give an apollo client error that it couldn’t be properly merged ([@paales](https://github.com/paales))
|
|
126
138
|
|
|
127
|
-
## 10.0.0-canary.72
|
|
128
|
-
|
|
129
|
-
## 10.0.0-canary.71
|
|
130
|
-
|
|
131
|
-
## 10.0.0-canary.70
|
|
132
|
-
|
|
133
|
-
### Major Changes
|
|
134
|
-
|
|
135
|
-
- [#2565](https://github.com/graphcommerce-org/graphcommerce/pull/2565) [`c96dfcd`](https://github.com/graphcommerce-org/graphcommerce/commit/c96dfcdca981baca387c270ad9e2b9515cdd00cc) - Updated to Apollo Client 4 ([@paales](https://github.com/paales))
|
|
136
|
-
|
|
137
|
-
## 10.0.0-canary.69
|
|
138
|
-
|
|
139
|
-
## 10.0.0-canary.68
|
|
140
|
-
|
|
141
|
-
### Major Changes
|
|
142
|
-
|
|
143
|
-
- [#2557](https://github.com/graphcommerce-org/graphcommerce/pull/2557) [`ceaadd8`](https://github.com/graphcommerce-org/graphcommerce/commit/ceaadd87f0648982a068a3b07b1fa149c9127f49) - ## Material UI v5 → v7 Migration
|
|
144
|
-
|
|
145
|
-
This release upgrades Material UI from v5 to v7 with full CSS variables support. ([@paales](https://github.com/paales))
|
|
146
|
-
|
|
147
|
-
## 10.0.0-canary.67
|
|
148
|
-
|
|
149
|
-
### Patch Changes
|
|
150
|
-
|
|
151
|
-
- [#2540](https://github.com/graphcommerce-org/graphcommerce/pull/2540) [`36e2bac`](https://github.com/graphcommerce-org/graphcommerce/commit/36e2bacb4fe765ce1fcd24dc36736e90bb17a7dc) - Add billingAddress permission (EDITABLE | READONLY) that controls whether the end user can update their billing address in the account section and checkout. ([@Giovanni-Schroevers](https://github.com/Giovanni-Schroevers))
|
|
152
|
-
|
|
153
|
-
## 10.0.0-canary.66
|
|
154
|
-
|
|
155
|
-
## 10.0.0-canary.65
|
|
156
|
-
|
|
157
|
-
## 10.0.0-canary.64
|
|
158
|
-
|
|
159
|
-
## 10.0.0-canary.63
|
|
160
|
-
|
|
161
|
-
## 10.0.0-canary.62
|
|
162
|
-
|
|
163
|
-
## 10.0.0-canary.61
|
|
164
|
-
|
|
165
|
-
## 10.0.0-canary.60
|
|
166
|
-
|
|
167
|
-
## 10.0.0-canary.59
|
|
168
|
-
|
|
169
|
-
## 10.0.0-canary.58
|
|
170
|
-
|
|
171
|
-
### Patch Changes
|
|
172
|
-
|
|
173
|
-
- [`d7ad6a3`](https://github.com/graphcommerce-org/graphcommerce/commit/d7ad6a32acdd0c9540656feae9fbb1d5f5f3dbf9) - Additional export for GetCartTotals ([@paales](https://github.com/paales))
|
|
174
|
-
|
|
175
|
-
## 10.0.0-canary.57
|
|
176
|
-
|
|
177
|
-
## 10.0.0-canary.56
|
|
178
|
-
|
|
179
|
-
### Major Changes
|
|
180
|
-
|
|
181
|
-
- [#2546](https://github.com/graphcommerce-org/graphcommerce/pull/2546) [`ed9332a`](https://github.com/graphcommerce-org/graphcommerce/commit/ed9332a7f78966d932041d9a7725641edc92b28d) - ## GraphCommerce 10 - Turbopack Support
|
|
182
|
-
|
|
183
|
-
This major release brings full Turbopack compatibility, dramatically improving development speed.
|
|
184
|
-
|
|
185
|
-
### 🚀 Turbopack-Compatible Interceptor System
|
|
186
|
-
|
|
187
|
-
The entire plugin/interceptor system has been rewritten to work with Turbopack:
|
|
188
|
-
|
|
189
|
-
- **No more Webpack plugins** - Removed `InterceptorPlugin` webpack plugin entirely
|
|
190
|
-
- **File-based interception** - Original files are moved to `.original.tsx` and replaced with interceptor content
|
|
191
|
-
- **Direct imports** - Interceptors import from `.original` files instead of embedding source
|
|
192
|
-
- **New CLI commands**:
|
|
193
|
-
- `graphcommerce codegen-interceptors` - Generate interceptor files
|
|
194
|
-
- `graphcommerce cleanup-interceptors` - Reset interceptor system, restore original files
|
|
195
|
-
- **Stable file hashing** - Deterministic interceptor generation for better caching
|
|
196
|
-
|
|
197
|
-
### ⚙️ Treeshakable Configuration System
|
|
198
|
-
|
|
199
|
-
Replaced Webpack `DefinePlugin`-based `import.meta.graphCommerce` with a new generated configuration system:
|
|
200
|
-
|
|
201
|
-
- **New `codegen-config-values` command** - Generates TypeScript files with precise typing
|
|
202
|
-
- **Schema-driven** - Dynamically introspects Zod schemas to determine all available properties
|
|
203
|
-
- **Fully treeshakable** - Unused config values are eliminated from the bundle
|
|
204
|
-
- **Type-safe** - Uses `Get<GraphCommerceConfig, 'path'>` for nested property access
|
|
205
|
-
- **Separate files for nested objects** - Optimal treeshaking for complex configurations
|
|
206
|
-
|
|
207
|
-
### 🔧 withGraphCommerce Changes
|
|
208
|
-
|
|
209
|
-
- **Removed** `InterceptorPlugin` - No longer needed with file-based interception
|
|
210
|
-
- **Removed** `DefinePlugin` for `import.meta.graphCommerce` - Replaced with generated config
|
|
211
|
-
- **Removed** `@mui/*` alias rewrites - No longer required
|
|
212
|
-
- **Added** Turbopack loader rules for `.yaml`, `.yml`, and `.po` files
|
|
213
|
-
- **Added** `serverExternalPackages` for all `@whatwg-node/*` packages
|
|
214
|
-
- **Added** `optimizePackageImports` for better bundle optimization
|
|
215
|
-
- **Added** `images.qualities: [52, 75]` for Next.js image optimization
|
|
216
|
-
|
|
217
|
-
### 📦 Lingui Configuration
|
|
218
|
-
|
|
219
|
-
- **Renamed** `lingui.config.js` → `lingui.config.ts` with TypeScript support
|
|
220
|
-
- **Updated** `@graphcommerce/lingui-next/config` to TypeScript with proper exports
|
|
221
|
-
- **Simplified** formatter options
|
|
222
|
-
|
|
223
|
-
### ⚛️ React 19 & Next.js 16 Compatibility
|
|
224
|
-
|
|
225
|
-
- Updated `RefObject<T>` types for React 19 (now includes `null` by default)
|
|
226
|
-
- Replaced deprecated `React.VFC` with `React.FC`
|
|
227
|
-
- Fixed `useRef` calls to require explicit initial values
|
|
228
|
-
- Updated `MutableRefObject` usage in `framer-scroller`
|
|
229
|
-
|
|
230
|
-
### 📋 ESLint 9 Flat Config
|
|
231
|
-
|
|
232
|
-
- Migrated from legacy `.eslintrc` to new flat config format (`eslint.config.mjs`)
|
|
233
|
-
- Updated `@typescript-eslint/*` packages to v8
|
|
234
|
-
- Fixed AST selector for `SxProps` rule (`typeParameters` → `typeArguments`)
|
|
235
|
-
|
|
236
|
-
### 🔄 Apollo Client
|
|
237
|
-
|
|
238
|
-
- Fixed deprecated `name` option → `clientAwareness: { name: 'ssr' }`
|
|
239
|
-
- Updated error handling types to accept `ApolloError | null | undefined`
|
|
240
|
-
|
|
241
|
-
### ⚠️ Breaking Changes
|
|
242
|
-
|
|
243
|
-
- **Node.js 24.x not supported** - Restricted to `>=20 <24.0.0` due to [nodejs/undici#4290](https://github.com/nodejs/undici/issues/4290)
|
|
244
|
-
- **Interceptor files changed** - Original components now at `.original.tsx`
|
|
245
|
-
- **Config access changed** - Use generated config values instead of `import.meta.graphCommerce`
|
|
246
|
-
- **ESLint config format** - Must use flat config (`eslint.config.mjs`)
|
|
247
|
-
- **Lingui config** - Rename `lingui.config.js` to `lingui.config.ts`
|
|
248
|
-
|
|
249
|
-
### 🗑️ Removed
|
|
250
|
-
|
|
251
|
-
- `InterceptorPlugin` webpack plugin
|
|
252
|
-
- `configToImportMeta` utility
|
|
253
|
-
- Webpack `DefinePlugin` usage for config
|
|
254
|
-
- `@mui/*` modern alias rewrites
|
|
255
|
-
- Debug plugins (`CircularDependencyPlugin`, `DuplicatesPlugin`) ([@paales](https://github.com/paales))
|
|
256
|
-
|
|
257
|
-
## 9.1.0-canary.55
|
|
258
|
-
|
|
259
|
-
### Patch Changes
|
|
260
|
-
|
|
261
|
-
- [#2539](https://github.com/graphcommerce-org/graphcommerce/pull/2539) [`cf44b1f`](https://github.com/graphcommerce-org/graphcommerce/commit/cf44b1f723b7f2073a21abd6821768427cb95315) - Added hideTotals to MultiCartStartCheckout ([@paales](https://github.com/paales))
|
|
262
|
-
|
|
263
|
-
- [#2539](https://github.com/graphcommerce-org/graphcommerce/pull/2539) [`af4463d`](https://github.com/graphcommerce-org/graphcommerce/commit/af4463dcbc6903241c8804ffba2f43b2b8e1a00b) - When running a cart mutation and the cartId is already passed to the form we use that value instead of retrieving the current cart again. ([@paales](https://github.com/paales))
|
|
264
|
-
|
|
265
|
-
- [#2539](https://github.com/graphcommerce-org/graphcommerce/pull/2539) [`415f9fb`](https://github.com/graphcommerce-org/graphcommerce/commit/415f9fb50454fb20cb533235969dd9ab4ffc134b) - Allow setting the cartId in the form for useFormGqlMutationCart by setting the cartId in the form AND allow setting the cartId for a whole context by wrapping with CartIdProvider ([@paales](https://github.com/paales))
|
|
266
|
-
|
|
267
|
-
- [#2539](https://github.com/graphcommerce-org/graphcommerce/pull/2539) [`4e3f3f2`](https://github.com/graphcommerce-org/graphcommerce/commit/4e3f3f2df58638ba8ffc68ee9f274cdd6c45d6d4) - Allow setting the redirect value in the AddProductsToCartForm as a form value. ([@paales](https://github.com/paales))
|
|
268
|
-
|
|
269
|
-
- [#2539](https://github.com/graphcommerce-org/graphcommerce/pull/2539) [`af4463d`](https://github.com/graphcommerce-org/graphcommerce/commit/af4463dcbc6903241c8804ffba2f43b2b8e1a00b) - Solve issue where if the onBeforeSubmit would return false, it would still error if submitted while the cart is locked. ([@paales](https://github.com/paales))
|
|
270
|
-
|
|
271
|
-
- [#2539](https://github.com/graphcommerce-org/graphcommerce/pull/2539) [`1a06135`](https://github.com/graphcommerce-org/graphcommerce/commit/1a061357f4ccb430dd13194f755815474e140520) - Allow awaitable async requests for onStart on checkout button ([@paales](https://github.com/paales))
|
|
272
|
-
|
|
273
|
-
## 9.1.0-canary.54
|
|
274
|
-
|
|
275
|
-
## 9.1.0-canary.53
|
|
276
|
-
|
|
277
|
-
## 9.1.0-canary.52
|
|
278
|
-
|
|
279
|
-
## 9.1.0-canary.51
|
|
280
|
-
|
|
281
|
-
### Patch Changes
|
|
282
|
-
|
|
283
|
-
- [#2537](https://github.com/graphcommerce-org/graphcommerce/pull/2537) [`1f37f05`](https://github.com/graphcommerce-org/graphcommerce/commit/1f37f05200e3015bf36d450bffff40c5d551ec54) - Forwarded ref to AddProductsToCartButton ([@paales](https://github.com/paales))
|
|
284
|
-
|
|
285
|
-
## 9.1.0-canary.50
|
|
286
|
-
|
|
287
|
-
## 9.1.0-canary.49
|
|
288
|
-
|
|
289
|
-
## 9.1.0-canary.48
|
|
290
|
-
|
|
291
|
-
## 9.1.0-canary.47
|
|
292
|
-
|
|
293
|
-
## 9.1.0-canary.46
|
|
294
|
-
|
|
295
|
-
## 9.1.0-canary.45
|
|
296
|
-
|
|
297
|
-
## 9.1.0-canary.44
|
|
298
|
-
|
|
299
|
-
## 9.1.0-canary.43
|
|
300
|
-
|
|
301
|
-
## 9.1.0-canary.42
|
|
302
|
-
|
|
303
|
-
## 9.1.0-canary.41
|
|
304
|
-
|
|
305
|
-
## 9.1.0-canary.40
|
|
306
|
-
|
|
307
|
-
### Patch Changes
|
|
308
|
-
|
|
309
|
-
- [#2529](https://github.com/graphcommerce-org/graphcommerce/pull/2529) [`b331f4d`](https://github.com/graphcommerce-org/graphcommerce/commit/b331f4d060c1385569fbbe1592ac245832de55bc) - Remove all usages of the NoSsr component as the GraphQL layer already handles this. ([@paales](https://github.com/paales))
|
|
310
|
-
|
|
311
|
-
## 9.1.0-canary.39
|
|
312
|
-
|
|
313
|
-
## 9.1.0-canary.38
|
|
314
|
-
|
|
315
|
-
## 9.1.0-canary.37
|
|
316
|
-
|
|
317
|
-
## 9.1.0-canary.36
|
|
318
|
-
|
|
319
|
-
## 9.1.0-canary.35
|
|
320
|
-
|
|
321
|
-
## 9.1.0-canary.34
|
|
322
|
-
|
|
323
|
-
## 9.1.0-canary.33
|
|
324
|
-
|
|
325
|
-
## 9.1.0-canary.32
|
|
326
|
-
|
|
327
|
-
## 9.1.0-canary.31
|
|
328
|
-
|
|
329
|
-
## 9.1.0-canary.30
|
|
330
|
-
|
|
331
|
-
## 9.1.0-canary.29
|
|
332
|
-
|
|
333
|
-
## 9.1.0-canary.28
|
|
334
|
-
|
|
335
|
-
## 9.1.0-canary.27
|
|
336
|
-
|
|
337
|
-
## 9.1.0-canary.26
|
|
338
|
-
|
|
339
|
-
## 9.1.0-canary.25
|
|
340
|
-
|
|
341
|
-
## 9.1.0-canary.24
|
|
342
|
-
|
|
343
|
-
## 9.1.0-canary.23
|
|
344
|
-
|
|
345
|
-
### Patch Changes
|
|
346
|
-
|
|
347
|
-
- [#2521](https://github.com/graphcommerce-org/graphcommerce/pull/2521) [`6847259`](https://github.com/graphcommerce-org/graphcommerce/commit/6847259715b0cebcc3f7415ed06cc38814663811) - Solve typescript issue were product types were added incorrectly. ([@paales](https://github.com/paales))
|
|
348
|
-
|
|
349
|
-
## 9.1.0-canary.22
|
|
350
|
-
|
|
351
|
-
## 9.1.0-canary.21
|
|
352
|
-
|
|
353
|
-
## 9.1.0-canary.20
|
|
354
|
-
|
|
355
|
-
## 9.1.0-canary.19
|
|
356
|
-
|
|
357
|
-
### Patch Changes
|
|
358
|
-
|
|
359
|
-
- [#2499](https://github.com/graphcommerce-org/graphcommerce/pull/2499) [`35fdadd`](https://github.com/graphcommerce-org/graphcommerce/commit/35fdadd8896619a2c84e91e39279f5928c0c9007) - Removed deprecated fields from AddProductsToCartForm ([@paales](https://github.com/paales))
|
|
360
|
-
|
|
361
|
-
- [#2499](https://github.com/graphcommerce-org/graphcommerce/pull/2499) [`b26f573`](https://github.com/graphcommerce-org/graphcommerce/commit/b26f57307ab1d08f628183dd86e487ec9aa1e5cf) - Moved all functionality from the @graphcommerce/magento-cart-billing-address package to the @graphcommerce/magento-cart package. All occurences of @graphcommerce/magento-cart-billing-address should be removed for your codebase. ([@paales](https://github.com/paales))
|
|
362
|
-
|
|
363
|
-
## 9.1.0-canary.18
|
|
364
|
-
|
|
365
|
-
## 9.1.0-canary.17
|
|
366
|
-
|
|
367
|
-
## 9.1.0-canary.16
|
|
368
|
-
|
|
369
|
-
## 9.1.0-canary.15
|
|
370
|
-
|
|
371
|
-
### Patch Changes
|
|
372
|
-
|
|
373
|
-
- [#2493](https://github.com/graphcommerce-org/graphcommerce/pull/2493) [`4cde990`](https://github.com/graphcommerce-org/graphcommerce/commit/4cde990dbeecdba8a00d0e34a1095fb14d8a0ad6) - When the cart totals are updated via a mutation, make sure to also fetch the id when the query is used so that automatically updates. ([@paales](https://github.com/paales))
|
|
374
|
-
|
|
375
|
-
- [#2493](https://github.com/graphcommerce-org/graphcommerce/pull/2493) [`7ae2909`](https://github.com/graphcommerce-org/graphcommerce/commit/7ae2909d57e58f00f18acb198028c601ccd857c5) - CartTotals now accepts a readOnly prop to handle plugins showing information based on that prop ([@paales](https://github.com/paales))
|
|
376
|
-
|
|
377
|
-
- [#2493](https://github.com/graphcommerce-org/graphcommerce/pull/2493) [`b6f76b6`](https://github.com/graphcommerce-org/graphcommerce/commit/b6f76b61f235d3336d8d296f1bed61c9f5daf325) - Solve issue where available_payment_methods would give an apollo client error that it couldn’t be properly merged ([@paales](https://github.com/paales))
|
|
378
|
-
|
|
379
|
-
## 9.0.4-canary.14
|
|
380
|
-
|
|
381
|
-
## 9.0.4-canary.13
|
|
382
|
-
|
|
383
|
-
## 9.0.4-canary.12
|
|
384
|
-
|
|
385
|
-
## 9.0.4-canary.11
|
|
386
|
-
|
|
387
|
-
### Patch Changes
|
|
388
|
-
|
|
389
|
-
- [#2485](https://github.com/graphcommerce-org/graphcommerce/pull/2485) [`6533728`](https://github.com/graphcommerce-org/graphcommerce/commit/65337280c6f4291cf4354e6ed9659f03388ca8d4) - When ordering a virtual product the checkout would still reference a Track & Trace ([@paales](https://github.com/paales))
|
|
390
|
-
|
|
391
|
-
## 9.0.4-canary.10
|
|
392
|
-
|
|
393
|
-
## 9.0.4-canary.9
|
|
394
|
-
|
|
395
|
-
## 9.0.4-canary.8
|
|
396
|
-
|
|
397
|
-
## 9.0.4-canary.7
|
|
398
|
-
|
|
399
|
-
### Patch Changes
|
|
400
|
-
|
|
401
|
-
- [#2479](https://github.com/graphcommerce-org/graphcommerce/pull/2479) [`ae5e72c`](https://github.com/graphcommerce-org/graphcommerce/commit/ae5e72ccf1c8218ace3cca1c4e52ec8d46821a27) - Solve issue where the total of the cart was zero due to discount or store credit the user couldn't proceed to the checkout. We now check for items and errors instead of the total. ([@Giovanni-Schroevers](https://github.com/Giovanni-Schroevers))
|
|
402
|
-
|
|
403
|
-
## 9.0.4-canary.6
|
|
404
|
-
|
|
405
|
-
## 9.0.4-canary.5
|
|
406
|
-
|
|
407
|
-
## 9.0.4-canary.4
|
|
408
|
-
|
|
409
|
-
## 9.0.4-canary.3
|
|
410
|
-
|
|
411
|
-
## 9.0.4-canary.2
|
|
412
|
-
|
|
413
|
-
## 9.0.4-canary.1
|
|
414
|
-
|
|
415
|
-
## 9.0.4-canary.0
|
|
416
|
-
|
|
417
139
|
## 9.0.0
|
|
418
140
|
|
|
419
141
|
### Major Changes
|
package/hooks/useCartQuery.ts
CHANGED
|
@@ -3,9 +3,9 @@ import type {
|
|
|
3
3
|
TypedDocumentNode,
|
|
4
4
|
WatchQueryFetchPolicy,
|
|
5
5
|
} from '@graphcommerce/graphql'
|
|
6
|
-
import { useQuery } from '@graphcommerce/graphql'
|
|
7
|
-
import { CombinedGraphQLErrors } from '@apollo/client/errors'
|
|
6
|
+
import { CombinedGraphQLErrors, useQuery } from '@graphcommerce/graphql'
|
|
8
7
|
import type { useQuery as useQueryType } from '@apollo/client/react'
|
|
8
|
+
import { t } from '@lingui/core/macro'
|
|
9
9
|
import { GraphQLError } from 'graphql'
|
|
10
10
|
import { useRouter } from 'next/router'
|
|
11
11
|
import { useCartShouldLoginToContinue } from './useCartPermissions'
|
|
@@ -61,7 +61,7 @@ export function useCartQuery<
|
|
|
61
61
|
...query,
|
|
62
62
|
error: new CombinedGraphQLErrors({
|
|
63
63
|
errors: [
|
|
64
|
-
new GraphQLError(
|
|
64
|
+
new GraphQLError(t`You must be logged in to view your cart.`, {
|
|
65
65
|
extensions: { category: 'graphql-authorization' },
|
|
66
66
|
}),
|
|
67
67
|
],
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
TypedDocumentNode,
|
|
4
|
-
useApolloClient,
|
|
5
|
-
useMutation,
|
|
6
|
-
} from '@graphcommerce/graphql'
|
|
1
|
+
import type { TypedDocumentNode, useMutation } from '@graphcommerce/graphql'
|
|
2
|
+
import { CombinedGraphQLErrors, useApolloClient } from '@graphcommerce/graphql'
|
|
7
3
|
import type {
|
|
8
4
|
UseFormGqlMutationReturn,
|
|
9
5
|
UseFormGraphQlOptions,
|
|
10
6
|
} from '@graphcommerce/react-hook-form'
|
|
11
7
|
import { useFormGqlMutation } from '@graphcommerce/react-hook-form'
|
|
8
|
+
import { t } from '@lingui/core/macro'
|
|
12
9
|
import { GraphQLError, Kind } from 'graphql'
|
|
13
10
|
import { useCartIdContext } from '../components/CartIdContext'
|
|
14
11
|
import { isProtectedCartOperation } from '../link/isProtectedCartOperation'
|
|
@@ -69,7 +66,7 @@ export function useFormGqlMutationCart<
|
|
|
69
66
|
...result,
|
|
70
67
|
error: new CombinedGraphQLErrors({
|
|
71
68
|
errors: [
|
|
72
|
-
new GraphQLError(
|
|
69
|
+
new GraphQLError(t`You must be logged in to modify your cart.`, {
|
|
73
70
|
extensions: { category: 'graphql-authorization' },
|
|
74
71
|
}),
|
|
75
72
|
],
|
package/link/cartLink.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { globalApolloClient } from '@graphcommerce/graphql'
|
|
2
1
|
import { ApolloLink, CombinedGraphQLErrors, ErrorLink } from '@graphcommerce/graphql/apollo'
|
|
3
2
|
import { filter, from, of, switchMap } from '@graphcommerce/graphql/rxjs'
|
|
4
3
|
import { CustomerTokenDocument, getCustomerAccountCanSignIn } from '@graphcommerce/magento-customer'
|
|
@@ -25,11 +24,6 @@ function errorIsIncluded(errorPath: readonly (string | number)[] | undefined, ke
|
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
const cartErrorLink = new ErrorLink(({ error, operation, forward }) => {
|
|
28
|
-
if (!globalApolloClient.current) return undefined
|
|
29
|
-
|
|
30
|
-
const client = globalApolloClient.current
|
|
31
|
-
const { cache } = client
|
|
32
|
-
|
|
33
27
|
// Check if this is a GraphQL error
|
|
34
28
|
if (!CombinedGraphQLErrors.is(error)) return undefined
|
|
35
29
|
|
|
@@ -66,13 +60,13 @@ const cartErrorLink = new ErrorLink(({ error, operation, forward }) => {
|
|
|
66
60
|
if (urlParams.get('cart_id')) return forward(operation)
|
|
67
61
|
}
|
|
68
62
|
|
|
69
|
-
return from(client
|
|
63
|
+
return from(operation.client.mutate({ mutation: CreateEmptyCartDocument })).pipe(
|
|
70
64
|
filter((value) => Boolean(value)),
|
|
71
65
|
switchMap((cartData) => {
|
|
72
66
|
const cartId = cartData.data?.createEmptyCart
|
|
73
67
|
if (!cartId) return forward(operation)
|
|
74
68
|
|
|
75
|
-
writeCartId(cache, cartId)
|
|
69
|
+
writeCartId(operation.client.cache, cartId)
|
|
76
70
|
operation.variables = { ...operation.variables, cartId }
|
|
77
71
|
|
|
78
72
|
// retry the request, returning the new observable
|
|
@@ -84,11 +78,10 @@ const cartErrorLink = new ErrorLink(({ error, operation, forward }) => {
|
|
|
84
78
|
const cartPermissionLink = (router: PushRouter) =>
|
|
85
79
|
new ApolloLink((operation, forward) => {
|
|
86
80
|
const { locale } = router
|
|
87
|
-
const { cache } = operation.getContext()
|
|
88
81
|
|
|
89
82
|
if (!isProtectedCartOperation(operation.operationName ?? '')) return forward(operation)
|
|
90
83
|
|
|
91
|
-
const check = () => Boolean(cache
|
|
84
|
+
const check = () => Boolean(operation.client.cache.readQuery({ query: CustomerTokenDocument }))
|
|
92
85
|
if (getCartEnabledForUser(locale, check)) return forward(operation)
|
|
93
86
|
|
|
94
87
|
if (!getCustomerAccountCanSignIn(locale))
|
|
@@ -101,7 +94,7 @@ const cartPermissionLink = (router: PushRouter) =>
|
|
|
101
94
|
|
|
102
95
|
return from(signInAgainPromise).pipe(
|
|
103
96
|
switchMap(() => {
|
|
104
|
-
const tokenQuery = cache
|
|
97
|
+
const tokenQuery = operation.client.cache.readQuery({ query: CustomerTokenDocument })
|
|
105
98
|
|
|
106
99
|
if (tokenQuery?.customerToken?.valid) {
|
|
107
100
|
// Customer is authenticated, retrying request.
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/magento-cart",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "10.0.
|
|
5
|
+
"version": "10.0.1-canary.1",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -20,20 +20,20 @@
|
|
|
20
20
|
"./plugins/useSignInFormMergeCart": "./plugins/useSignInFormMergeCart.ts"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"@graphcommerce/ecommerce-ui": "^10.0.
|
|
24
|
-
"@graphcommerce/eslint-config-pwa": "^10.0.
|
|
25
|
-
"@graphcommerce/framer-next-pages": "^10.0.
|
|
26
|
-
"@graphcommerce/framer-scroller": "^10.0.
|
|
27
|
-
"@graphcommerce/framer-utils": "^10.0.
|
|
28
|
-
"@graphcommerce/graphql": "^10.0.
|
|
29
|
-
"@graphcommerce/image": "^10.0.
|
|
30
|
-
"@graphcommerce/magento-customer": "^10.0.
|
|
31
|
-
"@graphcommerce/magento-graphql": "^10.0.
|
|
32
|
-
"@graphcommerce/magento-store": "^10.0.
|
|
33
|
-
"@graphcommerce/next-ui": "^10.0.
|
|
34
|
-
"@graphcommerce/prettier-config-pwa": "^10.0.
|
|
35
|
-
"@graphcommerce/react-hook-form": "^10.0.
|
|
36
|
-
"@graphcommerce/typescript-config-pwa": "^10.0.
|
|
23
|
+
"@graphcommerce/ecommerce-ui": "^10.0.1-canary.1",
|
|
24
|
+
"@graphcommerce/eslint-config-pwa": "^10.0.1-canary.1",
|
|
25
|
+
"@graphcommerce/framer-next-pages": "^10.0.1-canary.1",
|
|
26
|
+
"@graphcommerce/framer-scroller": "^10.0.1-canary.1",
|
|
27
|
+
"@graphcommerce/framer-utils": "^10.0.1-canary.1",
|
|
28
|
+
"@graphcommerce/graphql": "^10.0.1-canary.1",
|
|
29
|
+
"@graphcommerce/image": "^10.0.1-canary.1",
|
|
30
|
+
"@graphcommerce/magento-customer": "^10.0.1-canary.1",
|
|
31
|
+
"@graphcommerce/magento-graphql": "^10.0.1-canary.1",
|
|
32
|
+
"@graphcommerce/magento-store": "^10.0.1-canary.1",
|
|
33
|
+
"@graphcommerce/next-ui": "^10.0.1-canary.1",
|
|
34
|
+
"@graphcommerce/prettier-config-pwa": "^10.0.1-canary.1",
|
|
35
|
+
"@graphcommerce/react-hook-form": "^10.0.1-canary.1",
|
|
36
|
+
"@graphcommerce/typescript-config-pwa": "^10.0.1-canary.1",
|
|
37
37
|
"@lingui/core": "^5",
|
|
38
38
|
"@lingui/macro": "^5",
|
|
39
39
|
"@lingui/react": "^5",
|
package/typePolicies.ts
CHANGED
|
@@ -35,6 +35,8 @@ export const cartTypePolicies: StrictTypedTypePolicies = {
|
|
|
35
35
|
fields: {
|
|
36
36
|
cart: (_, { args, toReference }) =>
|
|
37
37
|
toReference({ __typename: 'Cart', id: (args as QuerycartArgs)?.cart_id }),
|
|
38
|
+
// https://github.com/apollographql/apollo-client/issues/12930
|
|
39
|
+
currentCartId: { merge: (existing, incoming) => incoming ?? existing },
|
|
38
40
|
},
|
|
39
41
|
},
|
|
40
42
|
Mutation: {
|