@graphcommerce/graphql-mesh 9.0.0-canary.56 → 9.0.0-canary.58

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,13 @@
1
1
  # Change Log
2
2
 
3
+ ## 9.0.0-canary.58
4
+
5
+ ### Minor Changes
6
+
7
+ - [#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))
8
+
9
+ ## 9.0.0-canary.57
10
+
3
11
  ## 9.0.0-canary.56
4
12
 
5
13
  ## 9.0.0-canary.55
@@ -58,8 +66,7 @@
58
66
 
59
67
  ### Patch Changes
60
68
 
61
- - [#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
62
- ([@JoshuaS98](https://github.com/JoshuaS98))
69
+ - [#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))
63
70
 
64
71
  ## 8.1.0-canary.28
65
72
 
@@ -105,8 +112,7 @@
105
112
 
106
113
  ### Patch Changes
107
114
 
108
- - [#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
109
- ([@paales](https://github.com/paales))
115
+ - [#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))
110
116
 
111
117
  ## 8.1.0-canary.7
112
118
 
@@ -196,8 +202,7 @@
196
202
 
197
203
  ### Patch Changes
198
204
 
199
- - [#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
200
- ([@paales](https://github.com/paales))
205
+ - [#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))
201
206
 
202
207
  ## 8.0.0-canary.100
203
208
 
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": "9.0.0-canary.56",
5
+ "version": "9.0.0-canary.58",
6
6
  "main": "index.ts",
7
7
  "dependencies": {
8
8
  "@graphql-mesh/apollo-link": "latest",
@@ -17,23 +17,23 @@
17
17
  "@graphql-mesh/transform-prune": "latest",
18
18
  "@graphql-mesh/types": "latest",
19
19
  "@graphql-mesh/utils": "latest",
20
- "@graphql-tools/utils": "^10.0.12",
21
- "@whatwg-node/fetch": "^0.9.15",
20
+ "@graphql-tools/utils": "^10.3.2",
21
+ "@whatwg-node/fetch": "^0.9.18",
22
22
  "fetch-retry": "^5.0.6",
23
23
  "long": "^5.2.3",
24
- "tslib": "^2.6.2",
25
- "uglify-es": "3.3.9"
24
+ "tslib": "^2.6.3",
25
+ "uglify-es": "3.3.10"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "@apollo/client": "^3",
29
- "@graphcommerce/eslint-config-pwa": "^9.0.0-canary.56",
30
- "@graphcommerce/prettier-config-pwa": "^9.0.0-canary.56",
31
- "@graphcommerce/typescript-config-pwa": "^9.0.0-canary.56",
29
+ "@graphcommerce/eslint-config-pwa": "^9.0.0-canary.58",
30
+ "@graphcommerce/prettier-config-pwa": "^9.0.0-canary.58",
31
+ "@graphcommerce/typescript-config-pwa": "^9.0.0-canary.58",
32
32
  "graphql": "^16.7.1"
33
33
  },
34
34
  "devDependencies": {
35
- "@types/uglify-es": "^3",
36
- "typescript": "5.3.3"
35
+ "@types/uglify-es": "^3.0.3",
36
+ "typescript": "5.5.3"
37
37
  },
38
38
  "sideEffects": false,
39
39
  "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
+ }