@graphcommerce/graphql-mesh 8.1.0-canary.9 → 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,13 +1,225 @@
1
1
  # Change Log
2
2
 
3
+ ## 9.0.0-canary.101
4
+
5
+ ### Minor Changes
6
+
7
+ - [#2380](https://github.com/graphcommerce-org/graphcommerce/pull/2380) [`3710d8b`](https://github.com/graphcommerce-org/graphcommerce/commit/3710d8bf1cceb5a991e5cfdfc15d42e462704c6d) - Solves the issue `TypeError: url?.startsWith is not a function`. The generated `.mesh/index.ts` would be generated as a requirejs module while next.js expects an esm module. In the end we properly generated the mesh correctly and now there is an `import.meta.url` instead of using `require('node:url')`. To solve this we needed to solve a chain of issues:
8
+
9
+ 1. The generation of the mesh is based on the version of the mesh that is imported (esm or commonjs). See [source](https://github.com/ardatan/graphql-mesh/blob/bf588d372c0078378aaa24beea2da794af7949e6/scripts/replace-import-meta-url-in-cjs.ts#L9-L10) for the lines that need to be different. This meant that we needed to change the @graphcommerce/cli package to be of type:module instead of a commonjs module.
10
+
11
+ 2) To properly convert the module to an esm module we've migrated the build of the cli package to use 'pkgroll' instead of tsc, because tsc is limited in what it outputs and can't really convert classic imports to esm.
12
+ 3) To load possible mesh plugins we require additional .ts files to be loaded with [tsx](https://tsx.is/). To get the tsx loader to work properly in combination with esm modules, we need at least [node 18.19.0](https://nodejs.org/en/blog/release/v18.19.0#new-nodemodule-api-register-for-module-customization-hooks-new-initialize-hook). Minimal Node version upped to 18.19.0 and add support for node 22. ([@paales](https://github.com/paales))
13
+
14
+ ## 9.0.0-canary.100
15
+
16
+ ## 9.0.0-canary.99
17
+
18
+ ## 9.0.0-canary.98
19
+
20
+ ## 9.0.0-canary.97
21
+
22
+ ## 9.0.0-canary.96
23
+
24
+ ## 9.0.0-canary.95
25
+
26
+ ## 9.0.0-canary.94
27
+
28
+ ## 9.0.0-canary.93
29
+
30
+ ## 9.0.0-canary.92
31
+
32
+ ## 9.0.0-canary.91
33
+
34
+ ## 9.0.0-canary.90
35
+
36
+ ## 9.0.0-canary.89
37
+
38
+ ## 9.0.0-canary.88
39
+
40
+ ## 9.0.0-canary.87
41
+
42
+ ## 9.0.0-canary.86
43
+
44
+ ## 9.0.0-canary.85
45
+
46
+ ## 9.0.0-canary.84
47
+
48
+ ## 9.0.0-canary.83
49
+
50
+ ## 9.0.0-canary.82
51
+
52
+ ## 9.0.0-canary.81
53
+
54
+ ## 9.0.0-canary.80
55
+
56
+ ## 9.0.0-canary.79
57
+
58
+ ## 9.0.0-canary.78
59
+
60
+ ## 9.0.0-canary.77
61
+
62
+ ## 9.0.0-canary.76
63
+
64
+ ## 9.0.0-canary.75
65
+
66
+ ## 9.0.0-canary.74
67
+
68
+ ## 9.0.0-canary.73
69
+
70
+ ## 9.0.0-canary.72
71
+
72
+ ## 9.0.0-canary.71
73
+
74
+ ### Patch Changes
75
+
76
+ - [#2345](https://github.com/graphcommerce-org/graphcommerce/pull/2345) [`d4ae30b`](https://github.com/graphcommerce-org/graphcommerce/commit/d4ae30ba28815ccb9d3a0478da995b7c609618e5) - Solve issue where customFetch coudn’t be loaded correctly ([@paales](https://github.com/paales))
77
+
78
+ ## 9.0.0-canary.70
79
+
80
+ ## 9.0.0-canary.69
81
+
82
+ ## 9.0.0-canary.68
83
+
84
+ ## 9.0.0-canary.67
85
+
86
+ ### Patch Changes
87
+
88
+ - [#2336](https://github.com/graphcommerce-org/graphcommerce/pull/2336) [`214bc56`](https://github.com/graphcommerce-org/graphcommerce/commit/214bc56950f397727d2c5417741dc62419080dfa) - Added traverseSelectionSet utility function to extract a child selection set from the parent. ([@Renzovh](https://github.com/Renzovh))
89
+
90
+ ## 9.0.0-canary.66
91
+
92
+ ## 9.0.0-canary.65
93
+
94
+ ## 9.0.0-canary.64
95
+
96
+ ## 9.0.0-canary.63
97
+
98
+ ## 9.0.0-canary.62
99
+
100
+ ## 9.0.0-canary.61
101
+
102
+ ## 9.0.0-canary.60
103
+
104
+ ## 9.0.0-canary.59
105
+
106
+ ### Minor Changes
107
+
108
+ - [#2309](https://github.com/graphcommerce-org/graphcommerce/pull/2309) [`b46e17e`](https://github.com/graphcommerce-org/graphcommerce/commit/b46e17ebe390b4d0040639dfdac33c36a60576ac) - When generating the mesh the configuration is passed through `@graphcommerce/graphql-mesh/meshConfig` allowing plugins to modify the mesh configuration without having to change the `.meshrc.yaml` itself. ([@Renzovh](https://github.com/Renzovh))
109
+
110
+ ## 9.0.0-canary.58
111
+
112
+ ### Minor Changes
113
+
114
+ - [#2330](https://github.com/graphcommerce-org/graphcommerce/pull/2330) [`bc3ec5e`](https://github.com/graphcommerce-org/graphcommerce/commit/bc3ec5e439b97cea4a2cef23e4008c7e0cfd6797) - Created a new @graphql-mesh plugin to forward headers from backends as forwardedHeaders in extensions ([@paales](https://github.com/paales))
115
+
116
+ ## 9.0.0-canary.57
117
+
118
+ ## 9.0.0-canary.56
119
+
120
+ ## 9.0.0-canary.55
121
+
122
+ ## 9.0.0-canary.54
123
+
124
+ ## 8.1.0-canary.53
125
+
126
+ ## 8.1.0-canary.52
127
+
128
+ ## 8.1.0-canary.51
129
+
130
+ ## 8.1.0-canary.50
131
+
132
+ ## 8.1.0-canary.49
133
+
134
+ ## 8.1.0-canary.48
135
+
136
+ ## 8.1.0-canary.47
137
+
138
+ ## 8.1.0-canary.46
139
+
140
+ ## 8.1.0-canary.45
141
+
142
+ ## 8.1.0-canary.44
143
+
144
+ ## 8.1.0-canary.43
145
+
146
+ ## 8.1.0-canary.42
147
+
148
+ ## 8.1.0-canary.41
149
+
150
+ ## 8.1.0-canary.40
151
+
152
+ ## 8.1.0-canary.39
153
+
154
+ ## 8.1.0-canary.38
155
+
156
+ ## 8.1.0-canary.37
157
+
158
+ ## 8.1.0-canary.36
159
+
160
+ ## 8.1.0-canary.35
161
+
162
+ ## 8.1.0-canary.34
163
+
164
+ ## 8.1.0-canary.33
165
+
166
+ ## 8.1.0-canary.32
167
+
168
+ ## 8.1.0-canary.31
169
+
170
+ ## 8.1.0-canary.30
171
+
172
+ ## 8.1.0-canary.29
173
+
174
+ ### Patch Changes
175
+
176
+ - [#2290](https://github.com/graphcommerce-org/graphcommerce/pull/2290) [`21f2ac0`](https://github.com/graphcommerce-org/graphcommerce/commit/21f2ac06b95cfc9b51febe19e6859cbba2b578b4) - Fix cors issues with Dynamic Row Property Picker App ([@JoshuaS98](https://github.com/JoshuaS98))
177
+
178
+ ## 8.1.0-canary.28
179
+
180
+ ## 8.1.0-canary.27
181
+
182
+ ## 8.1.0-canary.26
183
+
184
+ ## 8.1.0-canary.25
185
+
186
+ ## 8.1.0-canary.24
187
+
188
+ ## 8.1.0-canary.23
189
+
190
+ ## 8.1.0-canary.22
191
+
192
+ ## 8.1.0-canary.21
193
+
194
+ ## 8.1.0-canary.20
195
+
196
+ ## 8.1.0-canary.19
197
+
198
+ ## 8.1.0-canary.18
199
+
200
+ ## 8.1.0-canary.17
201
+
202
+ ## 8.1.0-canary.16
203
+
204
+ ## 8.1.0-canary.15
205
+
206
+ ## 8.1.0-canary.14
207
+
208
+ ## 8.1.0-canary.13
209
+
210
+ ## 8.1.0-canary.12
211
+
212
+ ## 8.1.0-canary.11
213
+
214
+ ## 8.1.0-canary.10
215
+
3
216
  ## 8.1.0-canary.9
4
217
 
5
218
  ## 8.1.0-canary.8
6
219
 
7
220
  ### Patch Changes
8
221
 
9
- - [#2247](https://github.com/graphcommerce-org/graphcommerce/pull/2247) [`6831040`](https://github.com/graphcommerce-org/graphcommerce/commit/68310401448b7b42b53757db4a84de4a01e35aa2) - Suppress warning where a dependency is an expression, Added uglify-es and long as the dependencies couldn’t be found
10
- ([@paales](https://github.com/paales))
222
+ - [#2247](https://github.com/graphcommerce-org/graphcommerce/pull/2247) [`6831040`](https://github.com/graphcommerce-org/graphcommerce/commit/68310401448b7b42b53757db4a84de4a01e35aa2) - Suppress warning where a dependency is an expression, Added uglify-es and long as the dependencies couldn’t be found ([@paales](https://github.com/paales))
11
223
 
12
224
  ## 8.1.0-canary.7
13
225
 
@@ -97,8 +309,7 @@
97
309
 
98
310
  ### Patch Changes
99
311
 
100
- - [#2113](https://github.com/graphcommerce-org/graphcommerce/pull/2113) [`bf5ae89`](https://github.com/graphcommerce-org/graphcommerce/commit/bf5ae8979b145e7a96303f839ef2b1238712531a) - Remove requirement of toplevelAwait for graphqlSsrClient and solve logging issue in cli
101
- ([@paales](https://github.com/paales))
312
+ - [#2113](https://github.com/graphcommerce-org/graphcommerce/pull/2113) [`bf5ae89`](https://github.com/graphcommerce-org/graphcommerce/commit/bf5ae8979b145e7a96303f839ef2b1238712531a) - Remove requirement of toplevelAwait for graphqlSsrClient and solve logging issue in cli ([@paales](https://github.com/paales))
102
313
 
103
314
  ## 8.0.0-canary.100
104
315
 
@@ -7,5 +7,19 @@ const handler = createBuiltMeshHTTPHandler()
7
7
  export const createServer = async (endpoint: string) => {
8
8
  if (endpoint !== '/api/graphql')
9
9
  throw Error('Moving the GraphQL Endpoint is not supported at the moment')
10
- return (req: NextApiRequest, res: NextApiResponse) => handler(req, res)
10
+ return (req: NextApiRequest, res: NextApiResponse) => {
11
+ res.setHeader('Access-Control-Allow-Origin', req.headers.origin || '*')
12
+ const requestedHeaders = req.headers['access-control-request-headers']
13
+ if (requestedHeaders) {
14
+ res.setHeader('Access-Control-Allow-Headers', requestedHeaders)
15
+ }
16
+
17
+ if (req.method === 'OPTIONS') {
18
+ res.status(200)
19
+ res.end()
20
+ return
21
+ }
22
+
23
+ handler(req, res)
24
+ }
11
25
  }
@@ -1,9 +1,7 @@
1
- /* eslint-disable no-underscore-dangle */
2
- /* eslint-disable @typescript-eslint/no-var-requires */
3
- const fetchRetry = require('fetch-retry')
1
+ import fetchRetry from 'fetch-retry'
4
2
 
5
- /** @type {fetchRetry.default} */
6
3
  const fetcher = fetchRetry(
4
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, no-underscore-dangle, @typescript-eslint/no-var-requires
7
5
  process.env.__NEXT_PROCESSED_ENV ? fetch : require('@whatwg-node/fetch').fetch,
8
6
  )
9
7
 
@@ -12,8 +10,10 @@ const fetcher = fetchRetry(
12
10
  * @param {import('fetch-retry').RequestInitWithRetry | undefined} options
13
11
  * @returns {Promise<Response>}
14
12
  */
15
- module.exports = (url, options) => {
16
- /** @type {RequestInit['headers']} */
13
+ export default (
14
+ url: RequestInfo | URL,
15
+ options: import('fetch-retry').RequestInitWithRetry | undefined,
16
+ ): Promise<Response> => {
17
17
  const headers = Object.fromEntries(
18
18
  Object.entries(options?.headers ?? {}).filter(([_, value]) => value !== ''),
19
19
  )
package/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './api/createEnvelop'
2
2
  export * from './api/apolloLink'
3
3
  export * from './.mesh'
4
+ export * from './utils/traverseSelectionSet'
package/meshConfig.ts ADDED
@@ -0,0 +1,11 @@
1
+ import type { GraphCommerceConfig } from '@graphcommerce/next-config'
2
+ import type { YamlConfig } from '@graphql-mesh/types'
3
+
4
+ export type MeshConfigFunction = typeof meshConfig
5
+
6
+ export function meshConfig(
7
+ config: YamlConfig.Config,
8
+ graphCommerceConfig: GraphCommerceConfig,
9
+ ): YamlConfig.Config {
10
+ return config
11
+ }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/graphql-mesh",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "8.1.0-canary.9",
5
+ "version": "9.0.0-canary.101",
6
6
  "main": "index.ts",
7
7
  "dependencies": {
8
8
  "@graphql-mesh/apollo-link": "latest",
@@ -10,30 +10,39 @@
10
10
  "@graphql-mesh/cross-helpers": "latest",
11
11
  "@graphql-mesh/graphql": "latest",
12
12
  "@graphql-mesh/http": "latest",
13
+ "@graphql-mesh/json-schema": "latest",
14
+ "@graphql-mesh/openapi": "latest",
13
15
  "@graphql-mesh/plugin-http-details-extensions": "latest",
14
16
  "@graphql-mesh/runtime": "latest",
15
17
  "@graphql-mesh/store": "latest",
18
+ "@graphql-mesh/transform-encapsulate": "latest",
16
19
  "@graphql-mesh/transform-filter-schema": "latest",
20
+ "@graphql-mesh/transform-hoist-field": "latest",
21
+ "@graphql-mesh/transform-naming-convention": "latest",
22
+ "@graphql-mesh/transform-prefix": "latest",
17
23
  "@graphql-mesh/transform-prune": "latest",
24
+ "@graphql-mesh/transform-rename": "latest",
25
+ "@graphql-mesh/transform-replace-field": "latest",
26
+ "@graphql-mesh/transform-type-merging": "latest",
18
27
  "@graphql-mesh/types": "latest",
19
28
  "@graphql-mesh/utils": "latest",
20
- "@graphql-tools/utils": "^10.0.12",
21
- "@whatwg-node/fetch": "^0.9.15",
29
+ "@graphql-tools/utils": "^10.3.2",
30
+ "@whatwg-node/fetch": "^0.9.21",
22
31
  "fetch-retry": "^5.0.6",
23
32
  "long": "^5.2.3",
24
- "tslib": "^2.6.2",
25
- "uglify-es": "3.3.9"
33
+ "tslib": "^2.7.0",
34
+ "uglify-es": "3.3.10"
26
35
  },
27
36
  "peerDependencies": {
28
37
  "@apollo/client": "^3",
29
- "@graphcommerce/eslint-config-pwa": "^8.1.0-canary.9",
30
- "@graphcommerce/prettier-config-pwa": "^8.1.0-canary.9",
31
- "@graphcommerce/typescript-config-pwa": "^8.1.0-canary.9",
38
+ "@graphcommerce/eslint-config-pwa": "^9.0.0-canary.101",
39
+ "@graphcommerce/prettier-config-pwa": "^9.0.0-canary.101",
40
+ "@graphcommerce/typescript-config-pwa": "^9.0.0-canary.101",
32
41
  "graphql": "^16.7.1"
33
42
  },
34
43
  "devDependencies": {
35
- "@types/uglify-es": "^3",
36
- "typescript": "5.3.3"
44
+ "@types/uglify-es": "^3.0.3",
45
+ "typescript": "5.6.2"
37
46
  },
38
47
  "sideEffects": false,
39
48
  "prettier": "@graphcommerce/prettier-config-pwa",
@@ -0,0 +1,73 @@
1
+ import { isAsyncIterable } from '@envelop/core'
2
+ import { MeshPlugin, MeshPluginOptions } from '@graphql-mesh/types'
3
+ import type { MeshContext } from '../.mesh'
4
+
5
+ interface ForwardHeaderConfig {
6
+ forwardHeaders?: string[]
7
+ }
8
+
9
+ /**
10
+ * Configure in your meshrc.yaml:
11
+ *
12
+ * ```yaml
13
+ * plugins:
14
+ * - '@graphcommerce/graphql-mesh/plugin/forward-headers':
15
+ * forwardHeaders:
16
+ * - X-Magento-Cache-Id
17
+ * ```
18
+ *
19
+ * On your GraphQL response, you will have a new `forwardedHeaders` field in the `extensions` object (always lower case).
20
+ *
21
+ * ```json
22
+ * {
23
+ * "data": {},
24
+ * "extensions": {
25
+ * "forwardedHeaders": {
26
+ * "x-magento-cache-id": "homeHash"
27
+ * }
28
+ * }
29
+ * }
30
+ * ```
31
+ */
32
+ export default function useForwardHeadersPlugin(
33
+ config: MeshPluginOptions<ForwardHeaderConfig>,
34
+ ): MeshPlugin<MeshContext> {
35
+ const forwardHeaders = config.forwardHeaders?.map((header) => header.toLowerCase())
36
+
37
+ const store = new WeakMap<any, Map<string, string>>()
38
+ function getStoredForContext(context: MeshContext) {
39
+ let stored = store.get(context)
40
+ if (!stored) {
41
+ stored = new Map()
42
+ store.set(context, stored)
43
+ }
44
+ return stored
45
+ }
46
+
47
+ return {
48
+ onFetch({ context }) {
49
+ if (!context) return undefined
50
+ return ({ response }) => {
51
+ const stored = getStoredForContext(context)
52
+ response.headers.forEach((value, headerName) => {
53
+ if (forwardHeaders?.includes(headerName)) stored.set(headerName, value)
54
+ })
55
+ }
56
+ },
57
+
58
+ onExecute({ args: { contextValue } }) {
59
+ return {
60
+ onExecuteDone({ result, setResult }) {
61
+ if (isAsyncIterable(result)) return
62
+ const stored = store.get(contextValue)
63
+ if (stored) {
64
+ setResult({
65
+ ...result,
66
+ extensions: { ...result.extensions, forwardedHeaders: Object.fromEntries(stored) },
67
+ })
68
+ }
69
+ },
70
+ }
71
+ },
72
+ }
73
+ }
@@ -0,0 +1,12 @@
1
+ import type { MeshConfigFunction } from '@graphcommerce/graphql-mesh/meshConfig'
2
+ import type { FunctionPlugin, PluginConfig } from '@graphcommerce/next-config'
3
+
4
+ export const config: PluginConfig = {
5
+ module: '@graphcommerce/graphql-mesh/meshConfig',
6
+ type: 'function',
7
+ }
8
+
9
+ /**
10
+ * This plugin does not apply any changes to the Mesh configuration, but solely exists to generate the meshConfig.interceptor.ts file.
11
+ */
12
+ export const meshConfig: FunctionPlugin<MeshConfigFunction> = (prev, ...args) => prev(...args)
@@ -0,0 +1,46 @@
1
+ import { Kind, SelectionNode, SelectionSetNode } from 'graphql'
2
+ import type { Path } from 'react-hook-form'
3
+
4
+ function isNumeric(n: string) {
5
+ return !Number.isNaN(parseFloat(n))
6
+ }
7
+
8
+ export function traverseSelectionSet<Q>(incomingSelectionSet: SelectionSetNode, path: Path<Q>) {
9
+ const pathArray = path.split(/[,[\].]+?/)
10
+ let selectionSet = incomingSelectionSet
11
+ let pathIndex = 0
12
+
13
+ while (pathIndex < pathArray.length) {
14
+ let currentValue = pathArray[pathIndex]
15
+ const isNegation = currentValue.startsWith('!')
16
+ currentValue = isNegation ? currentValue.slice(1) : currentValue
17
+
18
+ if (!isNumeric(currentValue)) {
19
+ const newSelections: SelectionNode[] = []
20
+
21
+ for (const selection of selectionSet.selections) {
22
+ if (selection.kind === Kind.FIELD) {
23
+ if (!isNegation && selection.name.value === currentValue) {
24
+ newSelections.push(...(selection.selectionSet?.selections ?? []))
25
+ }
26
+ if (isNegation && selection.name.value !== currentValue) {
27
+ newSelections.push(...(selection.selectionSet?.selections ?? []))
28
+ }
29
+ }
30
+ }
31
+
32
+ selectionSet = {
33
+ kind: Kind.SELECTION_SET,
34
+ selections: newSelections,
35
+ }
36
+ }
37
+
38
+ pathIndex++
39
+ }
40
+
41
+ return selectionSet
42
+ }
43
+
44
+ export function hasSelectionSetPath<Q>(selectionSet: SelectionSetNode, path: Path<Q>): boolean {
45
+ return traverseSelectionSet<Q>(selectionSet, path).selections.length > 0
46
+ }