@graphcommerce/graphql-mesh 3.0.11 → 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 +11 -0
- package/createHandler.ts +27 -32
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
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
|
+
|
|
6
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)
|
|
7
18
|
|
|
8
19
|
|
package/createHandler.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
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'
|
|
@@ -11,35 +13,7 @@ import 'ts-tiny-invariant'
|
|
|
11
13
|
import 'micro'
|
|
12
14
|
import cors from 'micro-cors'
|
|
13
15
|
|
|
14
|
-
export function
|
|
15
|
-
delete json.$schema
|
|
16
|
-
let content = JSON.stringify(json)
|
|
17
|
-
|
|
18
|
-
if (typeof process === 'undefined' || 'env' in process === false) {
|
|
19
|
-
throw new Error('Process process.env not available')
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
content = content.replace(/\$\{(.*?)\}/g, (_, variable) => {
|
|
23
|
-
let varName = variable
|
|
24
|
-
let defaultValue = ''
|
|
25
|
-
|
|
26
|
-
if (variable.includes(':')) {
|
|
27
|
-
const spl = variable.split(':')
|
|
28
|
-
varName = spl.shift()
|
|
29
|
-
defaultValue = spl.join(':')
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (!process.env[varName]) {
|
|
33
|
-
throw new Error(`Env variable ${varName} not defined`)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return process.env[varName] || defaultValue
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
return JSON.parse(content)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export async function createHandler(meshInstance: MeshInstance, path: string) {
|
|
16
|
+
export async function createApolloHandlerForMesh(meshInstance: MeshInstance, path: string) {
|
|
43
17
|
const apolloServer = new ApolloServer({
|
|
44
18
|
context: ({ req }) => req,
|
|
45
19
|
introspection: true,
|
|
@@ -53,6 +27,29 @@ export async function createHandler(meshInstance: MeshInstance, path: string) {
|
|
|
53
27
|
})
|
|
54
28
|
await apolloServer.start()
|
|
55
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
|
+
|
|
56
53
|
const corsHandler = cors({
|
|
57
54
|
allowMethods: ['GET', 'POST', 'OPTIONS'],
|
|
58
55
|
allowHeaders: [
|
|
@@ -78,7 +75,5 @@ export async function createHandler(meshInstance: MeshInstance, path: string) {
|
|
|
78
75
|
'X-ReCaptcha',
|
|
79
76
|
],
|
|
80
77
|
})
|
|
81
|
-
|
|
82
|
-
const apolloHandler = apolloServer.createHandler({ path })
|
|
83
78
|
return corsHandler((req, res) => (req.method === 'OPTIONS' ? res.end() : apolloHandler(req, res)))
|
|
84
79
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphcommerce/graphql-mesh",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"author": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"scripts": {
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"@graphql-mesh/graphql": "^0.18.18",
|
|
16
16
|
"@graphql-mesh/merger-stitching": "^0.13.1",
|
|
17
17
|
"@graphql-mesh/runtime": "^0.23.1",
|
|
18
|
+
"@graphql-mesh/store": "^0.1.18",
|
|
18
19
|
"@graphql-mesh/transform-cache": "^0.9.20",
|
|
19
20
|
"@graphql-mesh/transform-federation": "^0.6.10",
|
|
20
21
|
"@graphql-mesh/transform-filter-schema": "^0.12.1",
|
|
@@ -50,5 +51,5 @@
|
|
|
50
51
|
"project": "./tsconfig.json"
|
|
51
52
|
}
|
|
52
53
|
},
|
|
53
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "491a0fc0ea281263fe5c133aaabc23ab671a7b3d"
|
|
54
55
|
}
|