@graphcommerce/graphql 6.2.0-canary.7 → 6.2.0-canary.71

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,151 @@
1
1
  # Change Log
2
2
 
3
+ ## 6.2.0-canary.71
4
+
5
+ ## 6.2.0-canary.70
6
+
7
+ ## 6.2.0-canary.69
8
+
9
+ ### Patch Changes
10
+
11
+ - [#2012](https://github.com/graphcommerce-org/graphcommerce/pull/2012) [`1dbb3ae13`](https://github.com/graphcommerce-org/graphcommerce/commit/1dbb3ae13553992ee1ed77f375375560f28c418c) - Upgrade graphql to 16.7.1, add graphql as peer dependency ([@Giovanni-Schroevers](https://github.com/Giovanni-Schroevers))
12
+
13
+ ## 6.2.0-canary.68
14
+
15
+ ## 6.2.0-canary.67
16
+
17
+ ### Patch Changes
18
+
19
+ - [#2002](https://github.com/graphcommerce-org/graphcommerce/pull/2002) [`1234bb61f`](https://github.com/graphcommerce-org/graphcommerce/commit/1234bb61f8332da8a9e4dd7262b0c70beaed8c91) - Updated next and apollo/client ([@paales](https://github.com/paales))
20
+
21
+ ## 6.2.0-canary.66
22
+
23
+ ## 6.2.0-canary.65
24
+
25
+ ## 6.2.0-canary.64
26
+
27
+ ## 6.2.0-canary.63
28
+
29
+ ## 6.2.0-canary.62
30
+
31
+ ## 6.2.0-canary.61
32
+
33
+ ## 6.2.0-canary.60
34
+
35
+ ## 6.2.0-canary.59
36
+
37
+ ## 6.2.0-canary.58
38
+
39
+ ## 6.2.0-canary.57
40
+
41
+ ## 6.2.0-canary.56
42
+
43
+ ## 6.2.0-canary.55
44
+
45
+ ## 6.2.0-canary.54
46
+
47
+ ## 6.2.0-canary.53
48
+
49
+ ## 6.2.0-canary.52
50
+
51
+ ## 6.2.0-canary.51
52
+
53
+ ## 6.2.0-canary.50
54
+
55
+ ## 6.2.0-canary.49
56
+
57
+ ## 6.2.0-canary.48
58
+
59
+ ## 6.2.0-canary.47
60
+
61
+ ## 6.2.0-canary.46
62
+
63
+ ## 6.2.0-canary.45
64
+
65
+ ## 6.2.0-canary.44
66
+
67
+ ## 6.2.0-canary.43
68
+
69
+ ## 6.2.0-canary.42
70
+
71
+ ## 6.2.0-canary.41
72
+
73
+ ### Patch Changes
74
+
75
+ - [#1960](https://github.com/graphcommerce-org/graphcommerce/pull/1960) [`f78caf5a8`](https://github.com/graphcommerce-org/graphcommerce/commit/f78caf5a83683f1ae4b901fb94bd22d50943fa2f) - Updated packages @apollo/client, react-hook-form, @emotion/\*, @lingui/\*, @mui/\* and various others. ([@paales](https://github.com/paales))
76
+
77
+ - [#1960](https://github.com/graphcommerce-org/graphcommerce/pull/1960) [`86e14569b`](https://github.com/graphcommerce-org/graphcommerce/commit/86e14569b1f68f73be7f93b614e36b382c5debff) - Updated to the latest release of GraphQL codegen and solve compatibility issues with our own generator ([@paales](https://github.com/paales))
78
+
79
+ ## 6.2.0-canary.40
80
+
81
+ ## 6.2.0-canary.39
82
+
83
+ ## 6.2.0-canary.38
84
+
85
+ ## 6.2.0-canary.37
86
+
87
+ ## 6.2.0-canary.36
88
+
89
+ ## 6.2.0-canary.35
90
+
91
+ ## 6.2.0-canary.34
92
+
93
+ ## 6.2.0-canary.33
94
+
95
+ ## 6.2.0-canary.32
96
+
97
+ ## 6.2.0-canary.31
98
+
99
+ ## 6.2.0-canary.30
100
+
101
+ ### Patch Changes
102
+
103
+ - [#1942](https://github.com/graphcommerce-org/graphcommerce/pull/1942) [`df2b3efb2`](https://github.com/graphcommerce-org/graphcommerce/commit/df2b3efb2f906232a302218678c1524753c5a32c) - Customer related information was stored in the users local storage indefintely causing cache mismatches: 1. It stores a lot less by using the newly created _persistenceMapper_. 2. The 'createCacheReviver' would recreate the ApolloClient-cache on each navigation, it wont do that anymore. 3. The _persistenceMapper_ now has a hard coded blacklist of entries that aren't allowed to be stored in the local storage. In a future PR we'll make this blacklist configurable. ([@paales](https://github.com/paales))
104
+
105
+ ## 6.2.0-canary.29
106
+
107
+ ## 6.2.0-canary.28
108
+
109
+ ## 6.2.0-canary.27
110
+
111
+ ## 6.2.0-canary.26
112
+
113
+ ## 6.2.0-canary.25
114
+
115
+ ## 6.2.0-canary.24
116
+
117
+ ## 6.2.0-canary.23
118
+
119
+ ## 6.2.0-canary.22
120
+
121
+ ## 6.2.0-canary.21
122
+
123
+ ## 6.2.0-canary.20
124
+
125
+ ## 6.2.0-canary.19
126
+
127
+ ## 6.2.0-canary.18
128
+
129
+ ## 6.2.0-canary.17
130
+
131
+ ## 6.2.0-canary.16
132
+
133
+ ## 6.2.0-canary.15
134
+
135
+ ## 6.2.0-canary.14
136
+
137
+ ## 6.2.0-canary.13
138
+
139
+ ## 6.2.0-canary.12
140
+
141
+ ## 6.2.0-canary.11
142
+
143
+ ## 6.2.0-canary.10
144
+
145
+ ## 6.2.0-canary.9
146
+
147
+ ## 6.2.0-canary.8
148
+
3
149
  ## 6.2.0-canary.7
4
150
 
5
151
  ## 6.2.0-canary.6
@@ -2,6 +2,7 @@ import { LocalStorageWrapper, CachePersistor } from 'apollo3-cache-persist'
2
2
  import { mergeDeep, ApolloCache, ApolloClient, NormalizedCacheObject } from '../../apollo'
3
3
  import { ApolloClientConfig } from '../../config'
4
4
  import { migrateCacheHandler } from './migrateCache'
5
+ import { persistenceMapper } from './persistenceMapper'
5
6
  import { getTypePoliciesVersion } from './typePolicies'
6
7
 
7
8
  const APOLLO_CACHE_PERSIST = 'apollo-cache-persist'
@@ -23,24 +24,26 @@ export async function createCacheReviver(
23
24
  try {
24
25
  const { cache } = client
25
26
 
26
- if (persistor) await persistor.persist()
27
- // todo https://github.com/apollographql/apollo-cache-persist/tree/master/examples/react-native/src/utils/persistence
27
+ if (persistor) {
28
+ await persistor.persist()
29
+ return
30
+ }
31
+
28
32
  persistor = new CachePersistor({
29
33
  cache,
30
34
  storage: new LocalStorageWrapper(window.localStorage),
31
35
  maxSize: false,
32
36
  key: APOLLO_CACHE_PERSIST,
37
+ debounce: 10,
38
+ persistenceMapper,
33
39
  })
34
40
 
35
- client.onClearStore(async () => {
36
- client.cache.restore(incomingState)
37
- await persistor?.persist()
38
- })
39
-
40
- client.onResetStore(async () => {
41
+ const reset = async () => {
41
42
  client.cache.restore(incomingState)
42
43
  await persistor?.persist()
43
- })
44
+ }
45
+ client.onClearStore(reset)
46
+ client.onResetStore(reset)
44
47
 
45
48
  const storedState = window.localStorage[APOLLO_CACHE_PERSIST] as string | undefined
46
49
  const currentVersion = window.localStorage[APOLLO_CACHE_VERSION] as string | undefined
@@ -68,14 +71,12 @@ export async function createCacheReviver(
68
71
  }
69
72
  }
70
73
  window.localStorage[APOLLO_CACHE_VERSION] = typePoliciesVersion
71
- window.localStorage[APOLLO_CACHE_PERSIST] = JSON.stringify(state)
72
-
73
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
74
- persistor.restore()
75
74
  } catch (e) {
76
75
  console.error(e)
77
76
  }
78
77
  }
79
78
 
80
- if (state) client.cache.restore(state)
79
+ if (state) {
80
+ client.cache.restore(state)
81
+ }
81
82
  }
@@ -0,0 +1,43 @@
1
+ import { InMemoryCache, NormalizedCacheObject } from '@apollo/client'
2
+
3
+ function pruneKey(cacheValue: unknown, path: string[]) {
4
+ if (typeof cacheValue !== 'object' || cacheValue === null) return
5
+
6
+ const [segment, ...rest] = path
7
+ const regexp = new RegExp(
8
+ segment.replace(/\*/g, '.*?').replace(/\(/g, '\\(').replace(/\)/g, '\\)').replace(/=/g, '\\='),
9
+ )
10
+
11
+ Object.keys(cacheValue).forEach((key) => {
12
+ if (!regexp.test(key)) return
13
+
14
+ if (rest.length === 0) {
15
+ delete cacheValue[key]
16
+ } else pruneKey(cacheValue[key], rest)
17
+ })
18
+ }
19
+
20
+ function pruneCache(cacheObject: object, patterns: string[]) {
21
+ patterns.forEach((pattern) => pruneKey(cacheObject, pattern.split('.')))
22
+ }
23
+
24
+ export const persistenceMapper = (data: string): Promise<string> => {
25
+ const parsedCache = JSON.parse(data) as NormalizedCacheObject
26
+
27
+ pruneCache(parsedCache, [
28
+ 'ROOT_MUTATION',
29
+ 'ROOT_QUERY.products*',
30
+ 'ROOT_QUERY.countries',
31
+ 'ROOT_QUERY.checkoutAgreements',
32
+ 'ROOT_QUERY.storeConfig',
33
+ 'ROOT_QUERY.__type*',
34
+ 'ConfigurableProduct:*.configurable_product_options_selection*',
35
+ '*Product:{"uid":"*"}.crosssell_products',
36
+ ])
37
+
38
+ const cache = new InMemoryCache({})
39
+ cache.restore(parsedCache)
40
+ cache.gc()
41
+ const newCache = cache.extract()
42
+ return Promise.resolve(JSON.stringify(newCache))
43
+ }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/graphql",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "6.2.0-canary.7",
5
+ "version": "6.2.0-canary.71",
6
6
  "sideEffects": false,
7
7
  "main": "index.ts",
8
8
  "prettier": "@graphcommerce/prettier-config-pwa",
@@ -13,28 +13,28 @@
13
13
  }
14
14
  },
15
15
  "dependencies": {
16
- "@apollo/client": "^3.7.10",
17
- "@graphcommerce/graphql-codegen-near-operation-file": "6.2.0-canary.7",
18
- "@graphcommerce/graphql-codegen-relay-optimizer-plugin": "6.2.0-canary.7",
19
- "@graphql-codegen/add": "4.0.1",
20
- "@graphql-codegen/fragment-matcher": "4.0.1",
21
- "@graphql-codegen/introspection": "3.0.1",
22
- "@graphql-codegen/schema-ast": "3.0.1",
23
- "@graphql-codegen/typed-document-node": "3.0.2",
24
- "@graphql-codegen/typescript": "3.0.2",
16
+ "@apollo/client": "^3.7.17",
17
+ "@graphcommerce/graphql-codegen-near-operation-file": "6.2.0-canary.71",
18
+ "@graphcommerce/graphql-codegen-relay-optimizer-plugin": "6.2.0-canary.71",
19
+ "@graphql-codegen/add": "5.0.0",
20
+ "@graphql-codegen/fragment-matcher": "5.0.0",
21
+ "@graphql-codegen/introspection": "4.0.0",
22
+ "@graphql-codegen/schema-ast": "4.0.0",
23
+ "@graphql-codegen/typed-document-node": "5.0.0",
24
+ "@graphql-codegen/typescript": "4.0.0",
25
25
  "@graphql-codegen/typescript-apollo-client-helpers": "2.2.6",
26
- "@graphql-codegen/typescript-document-nodes": "3.0.2",
27
- "@graphql-codegen/typescript-operations": "3.0.2",
28
- "apollo3-cache-persist": "^0.14.1",
29
- "graphql": "16.6.0"
26
+ "@graphql-codegen/typescript-document-nodes": "4.0.0",
27
+ "@graphql-codegen/typescript-operations": "4.0.0",
28
+ "apollo3-cache-persist": "^0.14.1"
30
29
  },
31
30
  "devDependencies": {
32
- "@graphcommerce/eslint-config-pwa": "6.2.0-canary.7",
33
- "@graphcommerce/prettier-config-pwa": "6.2.0-canary.7",
34
- "@graphcommerce/typescript-config-pwa": "6.2.0-canary.7"
31
+ "@graphcommerce/eslint-config-pwa": "6.2.0-canary.71",
32
+ "@graphcommerce/prettier-config-pwa": "6.2.0-canary.71",
33
+ "@graphcommerce/typescript-config-pwa": "6.2.0-canary.71"
35
34
  },
36
35
  "peerDependencies": {
37
36
  "react": "^18.2.0",
38
- "react-dom": "^18.2.0"
37
+ "react-dom": "^18.2.0",
38
+ "graphql": "^16.7.1"
39
39
  }
40
40
  }