@graphcommerce/graphql-mesh 8.1.0-canary.8 → 9.0.0-canary.100

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,11 +1,214 @@
1
1
  # Change Log
2
2
 
3
+ ## 9.0.0-canary.100
4
+
5
+ ## 9.0.0-canary.99
6
+
7
+ ## 9.0.0-canary.98
8
+
9
+ ## 9.0.0-canary.97
10
+
11
+ ## 9.0.0-canary.96
12
+
13
+ ## 9.0.0-canary.95
14
+
15
+ ## 9.0.0-canary.94
16
+
17
+ ## 9.0.0-canary.93
18
+
19
+ ## 9.0.0-canary.92
20
+
21
+ ## 9.0.0-canary.91
22
+
23
+ ## 9.0.0-canary.90
24
+
25
+ ## 9.0.0-canary.89
26
+
27
+ ## 9.0.0-canary.88
28
+
29
+ ## 9.0.0-canary.87
30
+
31
+ ## 9.0.0-canary.86
32
+
33
+ ## 9.0.0-canary.85
34
+
35
+ ## 9.0.0-canary.84
36
+
37
+ ## 9.0.0-canary.83
38
+
39
+ ## 9.0.0-canary.82
40
+
41
+ ## 9.0.0-canary.81
42
+
43
+ ## 9.0.0-canary.80
44
+
45
+ ## 9.0.0-canary.79
46
+
47
+ ## 9.0.0-canary.78
48
+
49
+ ## 9.0.0-canary.77
50
+
51
+ ## 9.0.0-canary.76
52
+
53
+ ## 9.0.0-canary.75
54
+
55
+ ## 9.0.0-canary.74
56
+
57
+ ## 9.0.0-canary.73
58
+
59
+ ## 9.0.0-canary.72
60
+
61
+ ## 9.0.0-canary.71
62
+
63
+ ### Patch Changes
64
+
65
+ - [#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))
66
+
67
+ ## 9.0.0-canary.70
68
+
69
+ ## 9.0.0-canary.69
70
+
71
+ ## 9.0.0-canary.68
72
+
73
+ ## 9.0.0-canary.67
74
+
75
+ ### Patch Changes
76
+
77
+ - [#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))
78
+
79
+ ## 9.0.0-canary.66
80
+
81
+ ## 9.0.0-canary.65
82
+
83
+ ## 9.0.0-canary.64
84
+
85
+ ## 9.0.0-canary.63
86
+
87
+ ## 9.0.0-canary.62
88
+
89
+ ## 9.0.0-canary.61
90
+
91
+ ## 9.0.0-canary.60
92
+
93
+ ## 9.0.0-canary.59
94
+
95
+ ### Minor Changes
96
+
97
+ - [#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))
98
+
99
+ ## 9.0.0-canary.58
100
+
101
+ ### Minor Changes
102
+
103
+ - [#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))
104
+
105
+ ## 9.0.0-canary.57
106
+
107
+ ## 9.0.0-canary.56
108
+
109
+ ## 9.0.0-canary.55
110
+
111
+ ## 9.0.0-canary.54
112
+
113
+ ## 8.1.0-canary.53
114
+
115
+ ## 8.1.0-canary.52
116
+
117
+ ## 8.1.0-canary.51
118
+
119
+ ## 8.1.0-canary.50
120
+
121
+ ## 8.1.0-canary.49
122
+
123
+ ## 8.1.0-canary.48
124
+
125
+ ## 8.1.0-canary.47
126
+
127
+ ## 8.1.0-canary.46
128
+
129
+ ## 8.1.0-canary.45
130
+
131
+ ## 8.1.0-canary.44
132
+
133
+ ## 8.1.0-canary.43
134
+
135
+ ## 8.1.0-canary.42
136
+
137
+ ## 8.1.0-canary.41
138
+
139
+ ## 8.1.0-canary.40
140
+
141
+ ## 8.1.0-canary.39
142
+
143
+ ## 8.1.0-canary.38
144
+
145
+ ## 8.1.0-canary.37
146
+
147
+ ## 8.1.0-canary.36
148
+
149
+ ## 8.1.0-canary.35
150
+
151
+ ## 8.1.0-canary.34
152
+
153
+ ## 8.1.0-canary.33
154
+
155
+ ## 8.1.0-canary.32
156
+
157
+ ## 8.1.0-canary.31
158
+
159
+ ## 8.1.0-canary.30
160
+
161
+ ## 8.1.0-canary.29
162
+
163
+ ### Patch Changes
164
+
165
+ - [#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))
166
+
167
+ ## 8.1.0-canary.28
168
+
169
+ ## 8.1.0-canary.27
170
+
171
+ ## 8.1.0-canary.26
172
+
173
+ ## 8.1.0-canary.25
174
+
175
+ ## 8.1.0-canary.24
176
+
177
+ ## 8.1.0-canary.23
178
+
179
+ ## 8.1.0-canary.22
180
+
181
+ ## 8.1.0-canary.21
182
+
183
+ ## 8.1.0-canary.20
184
+
185
+ ## 8.1.0-canary.19
186
+
187
+ ## 8.1.0-canary.18
188
+
189
+ ## 8.1.0-canary.17
190
+
191
+ ## 8.1.0-canary.16
192
+
193
+ ## 8.1.0-canary.15
194
+
195
+ ## 8.1.0-canary.14
196
+
197
+ ## 8.1.0-canary.13
198
+
199
+ ## 8.1.0-canary.12
200
+
201
+ ## 8.1.0-canary.11
202
+
203
+ ## 8.1.0-canary.10
204
+
205
+ ## 8.1.0-canary.9
206
+
3
207
  ## 8.1.0-canary.8
4
208
 
5
209
  ### Patch Changes
6
210
 
7
- - [#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
8
- ([@paales](https://github.com/paales))
211
+ - [#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))
9
212
 
10
213
  ## 8.1.0-canary.7
11
214
 
@@ -95,8 +298,7 @@
95
298
 
96
299
  ### Patch Changes
97
300
 
98
- - [#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
99
- ([@paales](https://github.com/paales))
301
+ - [#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))
100
302
 
101
303
  ## 8.0.0-canary.100
102
304
 
@@ -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,8 @@
1
+ import type { GraphCommerceConfig } from '@graphcommerce/next-config'
2
+ import type { Config } from '@graphql-mesh/types/typings/config'
3
+
4
+ export type MeshConfigFunction = typeof meshConfig
5
+
6
+ export function meshConfig(config: Config, graphCommerceConfig: GraphCommerceConfig): Config {
7
+ return config
8
+ }
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.8",
5
+ "version": "9.0.0-canary.100",
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.18",
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.6.3",
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.8",
30
- "@graphcommerce/prettier-config-pwa": "^8.1.0-canary.8",
31
- "@graphcommerce/typescript-config-pwa": "^8.1.0-canary.8",
38
+ "@graphcommerce/eslint-config-pwa": "^9.0.0-canary.100",
39
+ "@graphcommerce/prettier-config-pwa": "^9.0.0-canary.100",
40
+ "@graphcommerce/typescript-config-pwa": "^9.0.0-canary.100",
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.5.3"
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
+ }