@graphcommerce/graphql 3.4.7 → 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 +18 -0
- package/createCacheReviver.ts +15 -2
- package/measurePerformanceLink.ts +79 -80
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
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
|
+
|
|
15
|
+
## 3.4.8
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [#1622](https://github.com/graphcommerce-org/graphcommerce/pull/1622) [`396b5de5d`](https://github.com/graphcommerce-org/graphcommerce/commit/396b5de5d50c7b8f59bf636807e7a4b50f14e0b2) Thanks [@paales](https://github.com/paales)! - Make sure the measurePerformanceLink only gets included on the server and flush the current timings.
|
|
20
|
+
|
|
3
21
|
## 3.4.7
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/createCacheReviver.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
|
-
import { text } from 'stream/consumers'
|
|
3
2
|
import { ApolloLink } from '@apollo/client'
|
|
4
3
|
|
|
5
4
|
const running = new Map<
|
|
@@ -50,91 +49,91 @@ const renderLine = (line: {
|
|
|
50
49
|
return ['', ...line.additional, result]
|
|
51
50
|
}
|
|
52
51
|
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
if (
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
52
|
+
export const flushMeasurePerf = () => {
|
|
53
|
+
const entries = Array.from(running.entries())
|
|
54
|
+
if (entries.length === 0 || !entries.every(([k, v]) => v.end)) return
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Print to the console a timeline that gives a visual reprentation of the starting time and
|
|
58
|
+
* duration of each operation like so;
|
|
59
|
+
*
|
|
60
|
+
* ╞═════════ QueryOne (250ms) ═════════╡ ╞══════════════════ Query Two (450ms)
|
|
61
|
+
* ══════════════════╡ ╞═════════ QueryThree ═════════╡
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
let start = Number.MAX_VALUE
|
|
65
|
+
let end = 0
|
|
66
|
+
entries.forEach(([_, value]) => {
|
|
67
|
+
if (value.start.getTime() < start) start = value.start.getTime()
|
|
68
|
+
if (value.end && value.end.getTime() > end) end = value.end.getTime()
|
|
69
|
+
})
|
|
70
|
+
end -= start
|
|
71
|
+
|
|
72
|
+
const colDivider = Math.max(Math.floor(end / 150), 20)
|
|
73
|
+
|
|
74
|
+
const lines = entries.map(([_, value]) => {
|
|
75
|
+
const requestStart = value.start.getTime() - start
|
|
76
|
+
const requestEnd = value.end ? value.end.getTime() - start : 0
|
|
77
|
+
const duration = requestEnd - requestStart
|
|
78
|
+
|
|
79
|
+
const serverStart = value.internalStart
|
|
80
|
+
? value.internalStart.getTime() - value.start.getTime()
|
|
81
|
+
: 0
|
|
82
|
+
|
|
83
|
+
return renderLine({
|
|
84
|
+
serverStart,
|
|
85
|
+
requestStart,
|
|
86
|
+
requestEnd,
|
|
87
|
+
additional: [
|
|
88
|
+
value.operationName,
|
|
89
|
+
`${duration - (duration - serverStart)}ms`,
|
|
90
|
+
`${duration - serverStart}ms`,
|
|
91
|
+
],
|
|
92
|
+
colDivider,
|
|
75
93
|
})
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
`${duration - serverStart}ms`,
|
|
97
|
-
],
|
|
98
|
-
colDivider,
|
|
99
|
-
})
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
const items = [
|
|
97
|
+
['', 'GraphQL requests', 'Bootup', 'Mesh', 'Waterfall'],
|
|
98
|
+
['', '', '', '', ''],
|
|
99
|
+
...lines,
|
|
100
|
+
renderLine({
|
|
101
|
+
serverStart: 0,
|
|
102
|
+
requestStart: 0,
|
|
103
|
+
requestEnd: end,
|
|
104
|
+
additional: [`Total time`, '', `${end}ms`],
|
|
105
|
+
colDivider,
|
|
106
|
+
}),
|
|
107
|
+
]
|
|
108
|
+
|
|
109
|
+
// Rewrite the above so it can handle abritraty columns
|
|
110
|
+
const colWidths: number[] = Array(items[0].length).fill(0)
|
|
111
|
+
items.forEach((item) => {
|
|
112
|
+
item.forEach((t, index) => {
|
|
113
|
+
colWidths[index] = Math.max(colWidths[index], t.length)
|
|
100
114
|
})
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
requestEnd: end,
|
|
110
|
-
additional: [`Total time`, '', `${end}ms`],
|
|
111
|
-
colDivider,
|
|
112
|
-
}),
|
|
113
|
-
]
|
|
114
|
-
|
|
115
|
-
// Rewrite the above so it can handle abritraty columns
|
|
116
|
-
const colWidths: number[] = Array(items[0].length).fill(0)
|
|
117
|
-
items.forEach((item) => {
|
|
118
|
-
item.forEach((t, index) => {
|
|
119
|
-
colWidths[index] = Math.max(colWidths[index], t.length)
|
|
120
|
-
})
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
// padd the items to the max length
|
|
118
|
+
items.forEach((item) => {
|
|
119
|
+
item.forEach((_, index) => {
|
|
120
|
+
item[index] = `${item[index].padEnd(colWidths[index], ' ')}${
|
|
121
|
+
index !== item.length - 1 ? ` │ ` : ''
|
|
122
|
+
}`
|
|
121
123
|
})
|
|
124
|
+
})
|
|
122
125
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
item[index] = `${item[index].padEnd(colWidths[index], ' ')}${
|
|
127
|
-
index !== item.length - 1 ? ` │ ` : ''
|
|
128
|
-
}`
|
|
129
|
-
})
|
|
130
|
-
})
|
|
126
|
+
// render the items to a string
|
|
127
|
+
const output = [[''], ...items].map((item) => item.join(' ')).join('\n')
|
|
128
|
+
console.log(output)
|
|
131
129
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
console.log(output)
|
|
130
|
+
running.clear()
|
|
131
|
+
}
|
|
135
132
|
|
|
136
|
-
|
|
137
|
-
|
|
133
|
+
let timeout: NodeJS.Timeout | undefined
|
|
134
|
+
const markTimeout = () => {
|
|
135
|
+
if (timeout) clearTimeout(timeout)
|
|
136
|
+
timeout = setTimeout(flushMeasurePerf, 1000)
|
|
138
137
|
}
|
|
139
138
|
|
|
140
139
|
/**
|
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.
|
|
5
|
+
"version": "3.5.0",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "index.ts",
|
|
8
8
|
"prettier": "@graphcommerce/prettier-config-pwa",
|