@graphcommerce/graphql 9.0.0-canary.100 → 9.0.0-canary.101

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
+ ## 9.0.0-canary.101
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2380](https://github.com/graphcommerce-org/graphcommerce/pull/2380) [`2457ca2`](https://github.com/graphcommerce-org/graphcommerce/commit/2457ca25a737a1fdc8b1d0e1b4b6ddb69c5f420e) - measurePerformanceLink now reports queries made in the subgraph and is only included during development and not in production. ([@paales](https://github.com/paales))
8
+
3
9
  ## 9.0.0-canary.100
4
10
 
5
11
  ## 9.0.0-canary.99
package/apollo.ts CHANGED
@@ -4,5 +4,6 @@ export * from '@apollo/client'
4
4
  export * from '@apollo/client/link/schema'
5
5
  export * from '@apollo/client/link/context'
6
6
  export * from '@apollo/client/link/error'
7
+ export * from '@apollo/client/utilities'
7
8
 
8
9
  export { getOperationName } from '@apollo/client/utilities'
@@ -1,7 +1,8 @@
1
1
  /* eslint-disable no-console */
2
2
  import { ApolloLink } from '@apollo/client'
3
- import type { MeshFetchHTTPInformation } from '@graphql-mesh/plugin-http-details-extensions'
4
3
  import { print } from '@apollo/client/utilities'
4
+ import type { MeshFetchHTTPInformation } from '@graphql-mesh/plugin-http-details-extensions'
5
+ import { responsePathAsArray, stripIgnoredCharacters } from 'graphql'
5
6
  import { cliHyperlink } from '../../lib/hyperlinker'
6
7
 
7
8
  const running = new Map<
@@ -12,6 +13,7 @@ const running = new Map<
12
13
  internalStart?: Date
13
14
  operationName: [string, string]
14
15
  additional?: [string, string]
16
+ idx?: number
15
17
  }
16
18
  >()
17
19
 
@@ -87,7 +89,7 @@ export const flushMeasurePerf = () => {
87
89
  })
88
90
 
89
91
  const items = [
90
- ['Operation', 'Mesh', ' Source', 'Timeline'],
92
+ ['Operation', 'Mesh', '', 'Timeline'],
91
93
  ...lines,
92
94
  renderLine({
93
95
  serverStart: 0,
@@ -109,22 +111,20 @@ export const flushMeasurePerf = () => {
109
111
  // padd the items to the max length
110
112
  items.forEach((item) => {
111
113
  item.forEach((_, index) => {
112
- const [str] = (Array.isArray(item[index]) ? item[index] : [item[index], item[index]]) as [
113
- string,
114
- string,
115
- ]
114
+ const [str] = Array.isArray(item[index]) ? item[index] : [item[index], item[index]]
116
115
 
117
- const val = (Array.isArray(item[index]) ? item[index][1] : item[index]) as string
116
+ const val = Array.isArray(item[index]) ? item[index][1] : (item[index] as string)
118
117
 
119
118
  const padLength = colWidths[index] + (val.length - str.length)
120
119
 
121
120
  item[index] = `${val.padEnd(padLength, ' ')}${index !== item.length - 1 ? `` : ''}`
122
121
  })
123
122
  })
124
-
125
- // render the items to a string
126
- const output = [[''], ...items].map((item) => item.join(' ')).join('\n')
127
- console.log(output)
123
+ ;[[''], ...items]
124
+ .map((item) => item.join(' '))
125
+ .forEach((item) => {
126
+ console.log(item)
127
+ })
128
128
 
129
129
  running.clear()
130
130
  }
@@ -157,43 +157,72 @@ export const measurePerformanceLink = new ApolloLink((operation, forward) => {
157
157
  const httpDetails: MeshFetchHTTPInformation[] | undefined = data.extensions?.httpDetails
158
158
 
159
159
  let additional = [``, ``] as [string, string]
160
- if (httpDetails) {
161
- httpDetails.forEach((d) => {
162
- const requestUrl = new URL(d.request.url)
163
- requestUrl.searchParams.delete('extensions')
164
- const title = `${d.sourceName} ${d.responseTime}ms`
165
- additional = [
166
- `${additional[0]} ${title}`,
167
- `${additional[1]} ${cliHyperlink(title, requestUrl.toString().replace(/\+/g, '%20'))}`,
168
- ]
169
- })
170
- }
171
160
 
172
161
  // Called after server responds
173
162
  const query = [
174
163
  `# Variables: ${JSON.stringify(operation.variables)}`,
175
164
  `# Headers: ${JSON.stringify(operation.getContext().headers)}`,
176
- print(operation.query),
165
+ stripIgnoredCharacters(print(operation.query)),
177
166
  ].join('\n')
178
167
 
179
- const meshUrl = new URL(`${import.meta.graphCommerce.canonicalBaseUrl}/api/graphql`)
168
+ const meshUrl = new URL(
169
+ process.env.NODE_ENV === 'production'
170
+ ? `${import.meta.graphCommerce.canonicalBaseUrl}/api/graphql`
171
+ : 'http://localhost:3000/api/graphql',
172
+ )
173
+
180
174
  meshUrl.searchParams.set('query', query)
181
175
 
176
+ running.delete(operationString)
182
177
  running.set(operationString, {
183
178
  start: operation.getContext().measurePerformanceLinkStart as Date,
184
179
  end: new Date(),
185
- operationName: [operation.operationName, operation.operationName],
180
+ operationName: [
181
+ operation.operationName,
182
+ operation.operationName,
183
+ // cliHyperlink(operation.operationName, meshUrl.toString()),
184
+ ],
186
185
  additional,
187
- // [
188
- // operation.operationName,
189
- // cliHyperlink(operation.operationName, meshUrl.toString()),
190
- // ],
191
- // additional: [
192
- // `🔗 ${additional[0]}`,
193
- // `${cliHyperlink('🔗', meshUrl.toString())} ${additional[1]}`,
194
- // ],
186
+ idx: 0,
195
187
  })
196
188
 
189
+ if (httpDetails) {
190
+ running.forEach((_, key) => {
191
+ if (key.startsWith(operationString)) running.delete(key)
192
+ })
193
+
194
+ httpDetails.forEach((d) => {
195
+ const requestUrl = new URL(d.request.url)
196
+ requestUrl.searchParams.delete('extensions')
197
+
198
+ const sourceName =
199
+ !d.sourceName && URL.canParse(d.request.url)
200
+ ? new URL(d.request.url).hostname
201
+ : d.sourceName
202
+
203
+ const key = `${operationString}.${responsePathAsArray(d.path).join('.')}`
204
+ const name = `${operation.operationName}.${responsePathAsArray(d.path).join('.')} (${sourceName})`
205
+
206
+ let start = new Date(d.request.timestamp)
207
+ let end = new Date(d.response.timestamp)
208
+ let operationName: [string, string] = [name, name]
209
+ let idx = 0
210
+
211
+ if (running.has(key)) {
212
+ // Get the earliest start time and latest end time.
213
+ const existing = running.get(key)
214
+ if (existing) {
215
+ idx = (existing.idx ?? 0) + 1
216
+ start = existing.start < start ? existing.start : start
217
+ end = existing?.end ? (existing.end > end ? existing.end : end) : end
218
+ operationName = [`${name} ⨉ ${idx}`, `${name} ⨉ ${idx}`]
219
+ }
220
+ }
221
+
222
+ running.set(key, { start, end, operationName, idx })
223
+ })
224
+ }
225
+
197
226
  markTimeout()
198
227
 
199
228
  return data
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": "9.0.0-canary.100",
5
+ "version": "9.0.0-canary.101",
6
6
  "sideEffects": false,
7
7
  "main": "index.ts",
8
8
  "prettier": "@graphcommerce/prettier-config-pwa",
@@ -13,8 +13,8 @@
13
13
  }
14
14
  },
15
15
  "dependencies": {
16
- "@graphcommerce/graphql-codegen-near-operation-file": "9.0.0-canary.100",
17
- "@graphcommerce/graphql-codegen-relay-optimizer-plugin": "9.0.0-canary.100",
16
+ "@graphcommerce/graphql-codegen-near-operation-file": "9.0.0-canary.101",
17
+ "@graphcommerce/graphql-codegen-relay-optimizer-plugin": "9.0.0-canary.101",
18
18
  "@graphql-codegen/add": "5.0.3",
19
19
  "@graphql-codegen/fragment-matcher": "5.0.2",
20
20
  "@graphql-codegen/introspection": "4.0.3",
@@ -28,9 +28,9 @@
28
28
  },
29
29
  "peerDependencies": {
30
30
  "@apollo/client": "^3",
31
- "@graphcommerce/eslint-config-pwa": "^9.0.0-canary.100",
32
- "@graphcommerce/prettier-config-pwa": "^9.0.0-canary.100",
33
- "@graphcommerce/typescript-config-pwa": "^9.0.0-canary.100",
31
+ "@graphcommerce/eslint-config-pwa": "^9.0.0-canary.101",
32
+ "@graphcommerce/prettier-config-pwa": "^9.0.0-canary.101",
33
+ "@graphcommerce/typescript-config-pwa": "^9.0.0-canary.101",
34
34
  "graphql": "^16.7.1",
35
35
  "react": "^18.2.0",
36
36
  "react-dom": "^18.2.0"