@graphcommerce/graphql-mesh 3.0.8 → 3.1.0

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
@@ -3,6 +3,40 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.1.0](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphql-mesh@3.0.11...@graphcommerce/graphql-mesh@3.1.0) (2021-10-20)
7
+
8
+
9
+ ### Features
10
+
11
+ * **graphql-mesh:** simplified the handler to use less code in the project ([f62b752](https://github.com/ho-nl/m2-pwa/commit/f62b75249492f40c5972deede529a25a17c8a617))
12
+
13
+
14
+
15
+
16
+
17
+ ## [3.0.11](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphql-mesh@3.0.10...@graphcommerce/graphql-mesh@3.0.11) (2021-10-20)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * **recaptcha:** allow and forward the the X-ReCaptcha to Magento ([2f3170e](https://github.com/ho-nl/m2-pwa/commit/2f3170e0f1652d84948b69a446634ffe02f08f80))
23
+
24
+
25
+
26
+
27
+
28
+ ## [3.0.9](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphql-mesh@3.0.8...@graphcommerce/graphql-mesh@3.0.9) (2021-10-18)
29
+
30
+
31
+ ### Bug Fixes
32
+
33
+ * add cache-inmemory-lru ([2cd23a4](https://github.com/ho-nl/m2-pwa/commit/2cd23a40c8a2b02175b160aa9ce0b695c88c12f7))
34
+ * graphql-mesh missing inmemory lru ([6c71c25](https://github.com/ho-nl/m2-pwa/commit/6c71c256911072ace19037616e0ce2ab478bf070))
35
+
36
+
37
+
38
+
39
+
6
40
  ## [3.0.1](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/graphql-mesh@3.0.0...@graphcommerce/graphql-mesh@3.0.1) (2021-09-27)
7
41
 
8
42
  **Note:** Version bump only for package @graphcommerce/graphql-mesh
package/createHandler.ts CHANGED
@@ -1,4 +1,6 @@
1
- import { MeshInstance } from '@graphql-mesh/runtime'
1
+ import { processConfig } from '@graphql-mesh/config'
2
+ import { getMesh as getGraphQLMesh, MeshInstance } from '@graphql-mesh/runtime'
3
+ import { MeshStore, InMemoryStoreStorageAdapter } from '@graphql-mesh/store'
2
4
  import { YamlConfig } from '@graphql-mesh/types'
3
5
  import { ApolloServerPluginLandingPageGraphQLPlayground } from 'apollo-server-core'
4
6
  import { ApolloServer } from 'apollo-server-micro'
@@ -6,41 +8,14 @@ import '@graphql-mesh/transform-filter-schema'
6
8
  import '@graphql-mesh/graphql'
7
9
  import '@graphql-mesh/merger-stitching'
8
10
  import '@graphql-mesh/transform-cache'
11
+ import '@graphql-mesh/cache-inmemory-lru'
9
12
  import 'ts-tiny-invariant'
10
13
  import 'micro'
11
14
  import cors from 'micro-cors'
12
15
 
13
- export function injectEnv(json: YamlConfig.Config & { $schema?: string }): YamlConfig.Config {
14
- delete json.$schema
15
- let content = JSON.stringify(json)
16
-
17
- if (typeof process === 'undefined' || 'env' in process === false) {
18
- throw new Error('Process process.env not available')
19
- }
20
-
21
- content = content.replace(/\$\{(.*?)\}/g, (_, variable) => {
22
- let varName = variable
23
- let defaultValue = ''
24
-
25
- if (variable.includes(':')) {
26
- const spl = variable.split(':')
27
- varName = spl.shift()
28
- defaultValue = spl.join(':')
29
- }
30
-
31
- if (!process.env[varName]) {
32
- throw new Error(`Env variable ${varName} not defined`)
33
- }
34
-
35
- return process.env[varName] || defaultValue
36
- })
37
-
38
- return JSON.parse(content)
39
- }
40
-
41
- export async function createHandler(meshInstance: MeshInstance, path: string) {
16
+ export async function createApolloHandlerForMesh(meshInstance: MeshInstance, path: string) {
42
17
  const apolloServer = new ApolloServer({
43
- context: meshInstance.contextBuilder,
18
+ context: ({ req }) => req,
44
19
  introspection: true,
45
20
  plugins: [
46
21
  ApolloServerPluginLandingPageGraphQLPlayground({
@@ -52,6 +27,29 @@ export async function createHandler(meshInstance: MeshInstance, path: string) {
52
27
  })
53
28
  await apolloServer.start()
54
29
 
30
+ const apolloHandler = apolloServer.createHandler({ path })
31
+
32
+ return apolloHandler
33
+ }
34
+
35
+ export async function getMesh(config: YamlConfig.Config): Promise<MeshInstance> {
36
+ const store = new MeshStore('.mesh', new InMemoryStoreStorageAdapter(), {
37
+ validate: true,
38
+ readonly: false,
39
+ })
40
+ return getGraphQLMesh(await processConfig(config, { dir: process.cwd(), store }))
41
+ }
42
+
43
+ export async function createServer(config: unknown, path: string) {
44
+ const meshConfig = config as YamlConfig.Config
45
+
46
+ const store = new MeshStore('.mesh', new InMemoryStoreStorageAdapter(), {
47
+ validate: true,
48
+ readonly: false,
49
+ })
50
+ const mesh = await getGraphQLMesh(await processConfig(meshConfig, { dir: process.cwd(), store }))
51
+ const apolloHandler = await createApolloHandlerForMesh(mesh, path)
52
+
55
53
  const corsHandler = cors({
56
54
  allowMethods: ['GET', 'POST', 'OPTIONS'],
57
55
  allowHeaders: [
@@ -66,16 +64,16 @@ export async function createHandler(meshInstance: MeshInstance, path: string) {
66
64
  'X-Api-Version',
67
65
  'Access-Control-Allow-Origin',
68
66
  'X-HTTP-Method-Override',
67
+ 'x-apollo-tracing',
68
+ 'apollographql-client-name',
69
+
70
+ // Magento 2 related headers
69
71
  'Authorization',
70
72
  'Store',
71
73
  'Preview-Version',
72
74
  'Content-Currency',
73
- 'X-Captcha',
74
- 'x-apollo-tracing',
75
- 'apollographql-client-name',
75
+ 'X-ReCaptcha',
76
76
  ],
77
77
  })
78
-
79
- const apolloHandler = apolloServer.createHandler({ path })
80
78
  return corsHandler((req, res) => (req.method === 'OPTIONS' ? res.end() : apolloHandler(req, res)))
81
79
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphcommerce/graphql-mesh",
3
- "version": "3.0.8",
3
+ "version": "3.1.0",
4
4
  "author": "",
5
5
  "license": "MIT",
6
6
  "scripts": {
@@ -9,15 +9,17 @@
9
9
  "start": "next start"
10
10
  },
11
11
  "dependencies": {
12
- "@graphql-mesh/cli": "^0.42.0",
13
- "@graphql-mesh/config": "^0.24.0",
14
- "@graphql-mesh/graphql": "^0.18.17",
15
- "@graphql-mesh/merger-stitching": "^0.13.0",
16
- "@graphql-mesh/runtime": "^0.23.0",
17
- "@graphql-mesh/transform-cache": "^0.9.19",
18
- "@graphql-mesh/transform-federation": "^0.6.9",
19
- "@graphql-mesh/transform-filter-schema": "^0.12.0",
20
- "@graphql-mesh/types": "^0.52.0",
12
+ "@graphql-mesh/cache-inmemory-lru": "^0.5.24",
13
+ "@graphql-mesh/cli": "^0.42.3",
14
+ "@graphql-mesh/config": "^0.24.2",
15
+ "@graphql-mesh/graphql": "^0.18.18",
16
+ "@graphql-mesh/merger-stitching": "^0.13.1",
17
+ "@graphql-mesh/runtime": "^0.23.1",
18
+ "@graphql-mesh/store": "^0.1.18",
19
+ "@graphql-mesh/transform-cache": "^0.9.20",
20
+ "@graphql-mesh/transform-federation": "^0.6.10",
21
+ "@graphql-mesh/transform-filter-schema": "^0.12.1",
22
+ "@graphql-mesh/types": "^0.53.0",
21
23
  "apollo-server-core": "^3.4.0",
22
24
  "apollo-server-micro": "^3.4.0",
23
25
  "graphql": "^15.6.1",
@@ -27,7 +29,7 @@
27
29
  },
28
30
  "devDependencies": {
29
31
  "@graphcommerce/browserslist-config-pwa": "^3.0.2",
30
- "@graphcommerce/eslint-config-pwa": "^3.0.7",
32
+ "@graphcommerce/eslint-config-pwa": "^3.0.8",
31
33
  "@graphcommerce/prettier-config-pwa": "^3.0.3",
32
34
  "@graphcommerce/typescript-config-pwa": "^3.1.1",
33
35
  "@playwright/test": "^1.15.2",
@@ -49,5 +51,5 @@
49
51
  "project": "./tsconfig.json"
50
52
  }
51
53
  },
52
- "gitHead": "5e31b902147a68bfce513451e4e10d1c74d23823"
54
+ "gitHead": "491a0fc0ea281263fe5c133aaabc23ab671a7b3d"
53
55
  }