@graphcommerce/graphql 3.4.7 → 3.4.8

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,11 @@
1
1
  # Change Log
2
2
 
3
+ ## 3.4.8
4
+
5
+ ### Patch Changes
6
+
7
+ - [#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.
8
+
3
9
  ## 3.4.7
4
10
 
5
11
  ### Patch Changes
@@ -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
- let timeout: NodeJS.Timeout | undefined
54
- const markTimeout = () => {
55
- if (timeout) {
56
- clearTimeout(timeout)
57
- }
58
- timeout = setTimeout(() => {
59
- const entries = Array.from(running.entries())
60
- if (!entries.every(([k, v]) => v.end)) return
61
-
62
- /**
63
- * Print to the console a timeline that gives a visual reprentation of the starting time and
64
- * duration of each operation like so;
65
- *
66
- * ╞═════════ QueryOne (250ms) ═════════╡ ╞══════════════════ Query Two (450ms)
67
- * ══════════════════╡ ╞═════════ QueryThree ═════════╡
68
- */
69
-
70
- let start = Number.MAX_VALUE
71
- let end = 0
72
- entries.forEach(([key, value]) => {
73
- if (value.start.getTime() < start) start = value.start.getTime()
74
- if (value.end && value.end.getTime() > end) end = value.end.getTime()
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
- end -= start
77
-
78
- const colDivider = Math.max(Math.floor(end / 150), 20)
79
-
80
- const lines = entries.map(([key, value]) => {
81
- const requestStart = value.start.getTime() - start
82
- const requestEnd = value.end ? value.end.getTime() - start : 0
83
- const duration = requestEnd - requestStart
84
-
85
- const serverStart = value.internalStart
86
- ? value.internalStart.getTime() - value.start.getTime()
87
- : 0
88
-
89
- return renderLine({
90
- serverStart,
91
- requestStart,
92
- requestEnd,
93
- additional: [
94
- value.operationName,
95
- `${duration - (duration - serverStart)}ms`,
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
- const items = [
103
- ['', 'GraphQL requests', 'Bootup', 'Mesh', 'Waterfall'],
104
- ['', '', '', '', ''],
105
- ...lines,
106
- renderLine({
107
- serverStart: 0,
108
- requestStart: 0,
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
- // padd the items to the max length
124
- items.forEach((item) => {
125
- item.forEach((t, index) => {
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
- // render the items to a string
133
- const output = [[''], ...items].map((item) => item.join(' ')).join('\n')
134
- console.log(output)
130
+ running.clear()
131
+ }
135
132
 
136
- running.clear()
137
- }, 1000)
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.4.7",
5
+ "version": "3.4.8",
6
6
  "sideEffects": false,
7
7
  "main": "index.ts",
8
8
  "prettier": "@graphcommerce/prettier-config-pwa",