@graphcommerce/graphql-mesh 9.0.0-canary.57 → 9.0.0-canary.59

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,17 @@
1
1
  # Change Log
2
2
 
3
+ ## 9.0.0-canary.59
4
+
5
+ ### Minor Changes
6
+
7
+ - [#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))
8
+
9
+ ## 9.0.0-canary.58
10
+
11
+ ### Minor Changes
12
+
13
+ - [#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))
14
+
3
15
  ## 9.0.0-canary.57
4
16
 
5
17
  ## 9.0.0-canary.56
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": "9.0.0-canary.57",
5
+ "version": "9.0.0-canary.59",
6
6
  "main": "index.ts",
7
7
  "dependencies": {
8
8
  "@graphql-mesh/apollo-link": "latest",
@@ -10,11 +10,20 @@
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
29
  "@graphql-tools/utils": "^10.3.2",
@@ -26,9 +35,9 @@
26
35
  },
27
36
  "peerDependencies": {
28
37
  "@apollo/client": "^3",
29
- "@graphcommerce/eslint-config-pwa": "^9.0.0-canary.57",
30
- "@graphcommerce/prettier-config-pwa": "^9.0.0-canary.57",
31
- "@graphcommerce/typescript-config-pwa": "^9.0.0-canary.57",
38
+ "@graphcommerce/eslint-config-pwa": "^9.0.0-canary.59",
39
+ "@graphcommerce/prettier-config-pwa": "^9.0.0-canary.59",
40
+ "@graphcommerce/typescript-config-pwa": "^9.0.0-canary.59",
32
41
  "graphql": "^16.7.1"
33
42
  },
34
43
  "devDependencies": {
@@ -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)