@graphcommerce/magento-graphql 9.1.0-canary.33 → 9.1.0-canary.35

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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## 9.1.0-canary.35
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2528](https://github.com/graphcommerce-org/graphcommerce/pull/2528) [`529d7a8`](https://github.com/graphcommerce-org/graphcommerce/commit/529d7a88a4e010cb3e50c1358e2ac43e80e0bf38) - Solve issue where the ApolloClient cache wasn't scoped properly causing the wrong currency to be shown when switching currency. ([@paales](https://github.com/paales))
8
+
9
+ ## 9.1.0-canary.34
10
+
3
11
  ## 9.1.0-canary.33
4
12
 
5
13
  ## 9.1.0-canary.32
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/magento-graphql",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "9.1.0-canary.33",
5
+ "version": "9.1.0-canary.35",
6
6
  "sideEffects": false,
7
7
  "main": "index.ts",
8
8
  "prettier": "@graphcommerce/prettier-config-pwa",
@@ -13,10 +13,10 @@
13
13
  }
14
14
  },
15
15
  "peerDependencies": {
16
- "@graphcommerce/eslint-config-pwa": "^9.1.0-canary.33",
17
- "@graphcommerce/graphql": "^9.1.0-canary.33",
18
- "@graphcommerce/prettier-config-pwa": "^9.1.0-canary.33",
19
- "@graphcommerce/typescript-config-pwa": "^9.1.0-canary.33",
16
+ "@graphcommerce/eslint-config-pwa": "^9.1.0-canary.35",
17
+ "@graphcommerce/graphql": "^9.1.0-canary.35",
18
+ "@graphcommerce/prettier-config-pwa": "^9.1.0-canary.35",
19
+ "@graphcommerce/typescript-config-pwa": "^9.1.0-canary.35",
20
20
  "graphql": "^16.0.0",
21
21
  "next": "*",
22
22
  "react": "^18.2.0",
@@ -1,6 +1,9 @@
1
- import type { graphqlConfig as graphqlConfigType } from '@graphcommerce/graphql'
1
+ import type {
2
+ dataIdFromObject as baseDataIdFromObject,
3
+ graphqlConfig as graphqlConfigType,
4
+ } from '@graphcommerce/graphql'
2
5
  import type { FunctionPlugin, PluginConfig } from '@graphcommerce/next-config'
3
- import { magentoTypePolicies } from '../typePolicies'
6
+ import { magentoDataIdFromObject, magentoTypePolicies } from '../typePolicies'
4
7
 
5
8
  export const config: PluginConfig = {
6
9
  type: 'function',
@@ -11,3 +14,12 @@ export const graphqlConfig: FunctionPlugin<typeof graphqlConfigType> = (prev, co
11
14
  const results = prev(conf)
12
15
  return { ...results, policies: [magentoTypePolicies, ...results.policies] }
13
16
  }
17
+
18
+ export const dataIdFromObject: FunctionPlugin<typeof baseDataIdFromObject> = (
19
+ prev,
20
+ object,
21
+ context,
22
+ ) => {
23
+ const results = prev(object, context)
24
+ return results ?? magentoDataIdFromObject(object, context)
25
+ }
package/typePolicies.ts CHANGED
@@ -1,6 +1,25 @@
1
- import type { TypedTypePolicies } from '@graphcommerce/graphql'
1
+ import {
2
+ getPrivateQueryContext,
3
+ globalApolloClient,
4
+ type TypedTypePolicies,
5
+ } from '@graphcommerce/graphql'
6
+ import type { KeyFieldsFunction } from '@apollo/client/cache/inmemory/policies'
7
+
8
+ /**
9
+ * This method automatically creates a typePolicy for all types that have a `uid` field. Secondly,
10
+ * it allows scoping of this value based on the current private context.
11
+ */
12
+ export const magentoDataIdFromObject: KeyFieldsFunction = (object) => {
13
+ const { uid, __typename } = object
14
+ const client = globalApolloClient.current
15
+
16
+ if (!uid || !__typename || typeof uid !== 'string' || !client?.cache) return ''
17
+
18
+ const ctx = getPrivateQueryContext(client)
19
+ const queryContext = ctx ? `@(${JSON.stringify(ctx)})` : ''
20
+ return `${__typename}:${uid}${queryContext}`
21
+ }
2
22
 
3
- /// /todooooo
4
23
  /**
5
24
  * By default we don't need to do anything for types with an `id` or without anything to identify.
6
25
  *
@@ -29,13 +48,13 @@ export const magentoTypePolicies: TypedTypePolicies = {
29
48
  AvailableShippingMethod: { keyFields: ['carrier_code', 'method_code'] },
30
49
  // BillingCartAddress: { keyFields: false },
31
50
  // Breadcrumb: { keyFields: ['category_uid'] },
32
- BundleCartItem: { keyFields: ['uid'] },
51
+ // BundleCartItem: { keyFields: ['uid'] },
33
52
  // BundleCreditMemoItem: { keyFields: ['id'] },
34
53
  // BundleInvoiceItem: { keyFields: ['id'] },
35
- BundleItem: { keyFields: ['uid'] },
36
- BundleItemOption: { keyFields: ['uid'] },
54
+ // BundleItem: { keyFields: ['uid'] },
55
+ // BundleItemOption: { keyFields: ['uid'] },
37
56
  // BundleOrderItem: { keyFields: ['id'] },
38
- BundleProduct: { keyFields: ['uid'] },
57
+ // BundleProduct: { keyFields: ['uid'] },
39
58
  // BundleShipmentItem: { keyFields: ['id'] },
40
59
  // BundleWishlistItem: { keyFields: ['id'] },
41
60
  // Cart: { keyFields: ['id'] },
@@ -43,17 +62,17 @@ export const magentoTypePolicies: TypedTypePolicies = {
43
62
  // CartAddressInterface: { keyFields: false },
44
63
  // CartAddressRegion: { keyFields: false },
45
64
  // CartDiscount: { keyFields: false },
46
- CartItemInterface: { keyFields: ['uid'] },
65
+ // CartItemInterface: { keyFields: ['uid'] },
47
66
  // CartItemPrices: { keyFields: false },
48
67
  CartItemQuantity: { keyFields: ['cart_item_id'] },
49
68
  // CartItemSelectedOptionValuePrice: { keyFields: false },
50
69
  // CartPrices: { keyFields: false },
51
70
  // CartTaxItem: { keyFields: false },
52
71
  // CartUserInputError: { keyFields: false },
53
- CategoryInterface: { keyFields: ['uid'] },
72
+ // CategoryInterface: { keyFields: ['uid'] },
54
73
  // CategoryProducts: { keyFields: false },
55
74
  // CategoryResult: { keyFields: false },
56
- CategoryTree: { keyFields: ['uid'] },
75
+ // CategoryTree: { keyFields: ['uid'] },
57
76
  CheckoutAgreement: { keyFields: ['agreement_id'] },
58
77
  // CheckoutUserInputError: { keyFields: false },
59
78
  CmsBlock: { keyFields: ['identifier'] },
@@ -61,16 +80,15 @@ export const magentoTypePolicies: TypedTypePolicies = {
61
80
  CmsPage: { keyFields: ['identifier'] },
62
81
  // ColorSwatchData: { keyFields: false },
63
82
  // ComparableAttribute: { keyFields: false },
64
- ComparableItem: { keyFields: ['uid'] },
65
- CompareList: { keyFields: ['uid'] },
83
+ // ComparableItem: { keyFields: ['uid'] },
84
+ // CompareList: { keyFields: ['uid'] },
66
85
  // ComplexTextValue: { keyFields: false },
67
- ConfigurableAttributeOption: { keyFields: ['uid'] },
68
- ConfigurableCartItem: { keyFields: ['uid'] },
86
+ // ConfigurableAttributeOption: { keyFields: ['uid'] },
87
+ // ConfigurableCartItem: { keyFields: ['uid'] },
69
88
  // ConfigurableOptionAvailableForSelection: { keyFields: false },
70
- ConfigurableProduct: { keyFields: ['uid'] },
71
- ConfigurableProductOptions: { keyFields: ['uid'] },
89
+ // ConfigurableProductOptions: { keyFields: ['uid'] },
72
90
  // ConfigurableProductOptionsSelection: { keyFields: false },
73
- ConfigurableProductOptionsValues: { keyFields: ['uid'] },
91
+ // ConfigurableProductOptionsValues: { keyFields: ['uid'] },
74
92
  // ConfigurableVariant: { keyFields: false },
75
93
  // ConfigurableWishlistItem: { keyFields: ['id'] },
76
94
  // Country: { keyFields: ['id'] },
@@ -114,18 +132,18 @@ export const magentoTypePolicies: TypedTypePolicies = {
114
132
  // CustomizableMultipleValue: { keyFields: ['uid'] },
115
133
  // CustomizableOptionInterface: { keyFields: ['uid'] },
116
134
  // CustomizableProductInterface: { keyFields: false },
117
- CustomizableRadioOption: { keyFields: ['uid'] },
118
- CustomizableRadioValue: { keyFields: ['uid'] },
135
+ // CustomizableRadioOption: { keyFields: ['uid'] },
136
+ // CustomizableRadioValue: { keyFields: ['uid'] },
119
137
  // DeleteCompareListOutput: { keyFields: false },
120
138
  // DeletePaymentTokenOutput: { keyFields: false },
121
139
  // Discount: { keyFields: false },
122
- DownloadableCartItem: { keyFields: ['uid'] },
140
+ // DownloadableCartItem: { keyFields: ['uid'] },
123
141
  // DownloadableCreditMemoItem: { keyFields: ['id'] },
124
142
  // DownloadableInvoiceItem: { keyFields: ['id'] },
125
- DownloadableItemsLinks: { keyFields: ['uid'] },
143
+ // DownloadableItemsLinks: { keyFields: ['uid'] },
126
144
  // DownloadableOrderItem: { keyFields: ['id'] },
127
- DownloadableProduct: { keyFields: ['uid'] },
128
- DownloadableProductLinks: { keyFields: ['uid'] },
145
+ // DownloadableProduct: { keyFields: ['uid'] },
146
+ // DownloadableProductLinks: { keyFields: ['uid'] },
129
147
  // DownloadableProductSamples: { keyFields: ['id'] },
130
148
  // DownloadableWishlistItem: { keyFields: ['id'] },
131
149
  // EntityUrl: { keyFields: ['id'] },
@@ -133,7 +151,7 @@ export const magentoTypePolicies: TypedTypePolicies = {
133
151
  // FixedProductTax: { keyFields: false },
134
152
  // GenerateCustomerTokenAsAdminOutput: { keyFields: false },
135
153
  // GiftMessage: { keyFields: false },
136
- GroupedProduct: { keyFields: ['uid'] },
154
+ // GroupedProduct: { keyFields: ['uid'] },
137
155
  // GroupedProductItem: { keyFields: false },
138
156
  // GroupedProductWishlistItem: { keyFields: ['id'] },
139
157
  // HostedProUrl: { keyFields: false },
@@ -150,7 +168,7 @@ export const magentoTypePolicies: TypedTypePolicies = {
150
168
  // LayerFilter: { keyFields: false },
151
169
  // LayerFilterItem: { keyFields: false },
152
170
  // LayerFilterItemInterface: { keyFields: false },
153
- MediaGalleryEntry: { keyFields: ['uid'] },
171
+ // MediaGalleryEntry: { keyFields: ['uid'] },
154
172
  // MediaGalleryInterface: { keyFields: false },
155
173
  // Money: { keyFields: false },
156
174
  Order: { keyFields: ['order_number'] },
@@ -178,7 +196,7 @@ export const magentoTypePolicies: TypedTypePolicies = {
178
196
  // ProductAttribute: { keyFields: false },
179
197
  // ProductDiscount: { keyFields: false },
180
198
  // ProductImage: { keyFields: false },
181
- ProductInterface: { keyFields: ['uid'] },
199
+ // ProductInterface: { keyFields: ['uid'] }, // Handled by dataIdFromObject
182
200
  // ProductLinks: { keyFields: false },
183
201
  // ProductLinksInterface: { keyFields: false },
184
202
  // ProductMediaGalleryEntriesContent: { keyFields: false },
@@ -226,7 +244,7 @@ export const magentoTypePolicies: TypedTypePolicies = {
226
244
  // ShippingDiscount: { keyFields: false },
227
245
  // ShippingHandling: { keyFields: false },
228
246
  // SimpleCartItem: { keyFields: ['id'] },
229
- SimpleProduct: { keyFields: ['uid'] },
247
+ // SimpleProduct: { keyFields: ['uid'] },
230
248
  // SimpleWishlistItem: { keyFields: ['id'] },
231
249
  // SortField: { keyFields: false },
232
250
  // SortFields: { keyFields: false },
@@ -242,8 +260,8 @@ export const magentoTypePolicies: TypedTypePolicies = {
242
260
  // UpdateCartItemsOutput: { keyFields: false },
243
261
  // UpdateProductsInWishlistOutput: { keyFields: false },
244
262
  // UrlRewrite: { keyFields: false },
245
- VirtualCartItem: { keyFields: ['uid'] },
246
- VirtualProduct: { keyFields: ['uid'] },
263
+ // VirtualCartItem: { keyFields: ['uid'] },
264
+ // VirtualProduct: { keyFields: ['uid'] },
247
265
  // VirtualWishlistItem: { keyFields: ['id'] },
248
266
  // Website: { keyFields: ['id'] },
249
267
  // WishListUserInputError: { keyFields: false },