@graphcommerce/graphql 3.4.8 → 3.5.0

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,17 @@
1
1
  # Change Log
2
2
 
3
+ ## 3.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#1670](https://github.com/graphcommerce-org/graphcommerce/pull/1670) [`8a34f8081`](https://github.com/graphcommerce-org/graphcommerce/commit/8a34f808186274a6fe1d4f309472f1a9c6d00efd) Thanks [@Jessevdpoel](https://github.com/Jessevdpoel)! - Added cache resetting when token expires and logging in with a different account than cached.
8
+
9
+ ### Patch Changes
10
+
11
+ - [#1675](https://github.com/graphcommerce-org/graphcommerce/pull/1675) [`cf3518499`](https://github.com/graphcommerce-org/graphcommerce/commit/cf351849999ad6fe73ce2bb258098a7dd301d517) Thanks [@paales](https://github.com/paales)! - ApolloClient is not persisted to localStorage before we restore from localStorage. Fixes a race condition where the current cartId wasn't persisted.
12
+
13
+ - [#1675](https://github.com/graphcommerce-org/graphcommerce/pull/1675) [`1b1504c9b`](https://github.com/graphcommerce-org/graphcommerce/commit/1b1504c9b0e51f2787bce91e1ff1940f540411d6) Thanks [@paales](https://github.com/paales)! - Added crosssel functionality
14
+
3
15
  ## 3.4.8
4
16
 
5
17
  ### Patch Changes
@@ -7,8 +7,10 @@ import { getTypePoliciesVersion } from './typePolicies'
7
7
  const APOLLO_CACHE_PERSIST = 'apollo-cache-persist'
8
8
  const APOLLO_CACHE_VERSION = 'apollo-cache-version'
9
9
 
10
+ let persistor: CachePersistor<NormalizedCacheObject> | null = null
11
+
10
12
  /** Revives the cache from the localStorage if it is available. */
11
- export function createCacheReviver(
13
+ export async function createCacheReviver(
12
14
  client: ApolloClient<NormalizedCacheObject>,
13
15
  createCache: () => ApolloCache<NormalizedCacheObject>,
14
16
  policies: StrictTypedTypePolicies[],
@@ -22,14 +24,25 @@ export function createCacheReviver(
22
24
  try {
23
25
  const { cache } = client
24
26
 
27
+ if (persistor) await persistor.persist()
25
28
  // todo https://github.com/apollographql/apollo-cache-persist/tree/master/examples/react-native/src/utils/persistence
26
- const persistor = new CachePersistor({
29
+ persistor = new CachePersistor({
27
30
  cache,
28
31
  storage: new LocalStorageWrapper(window.localStorage),
29
32
  maxSize: false,
30
33
  key: APOLLO_CACHE_PERSIST,
31
34
  })
32
35
 
36
+ client.onClearStore(async () => {
37
+ client.cache.restore(incommingState)
38
+ await persistor?.persist()
39
+ })
40
+
41
+ client.onResetStore(async () => {
42
+ client.cache.restore(incommingState)
43
+ await persistor?.persist()
44
+ })
45
+
33
46
  const storedState = window.localStorage[APOLLO_CACHE_PERSIST] as string | undefined
34
47
  const currentVersion = window.localStorage[APOLLO_CACHE_VERSION] as string | undefined
35
48
 
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": "3.4.8",
5
+ "version": "3.5.0",
6
6
  "sideEffects": false,
7
7
  "main": "index.ts",
8
8
  "prettier": "@graphcommerce/prettier-config-pwa",