@graphql-mesh/http 1.0.0-alpha-20230424111644-b7c761da0 → 1.0.0-alpha-20230522105300-fe9c79867
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/cjs/graphqlHandler.js +0 -2
- package/cjs/index.js +87 -53
- package/esm/graphqlHandler.js +0 -2
- package/esm/index.js +86 -52
- package/package.json +7 -7
- package/typings/index.d.cts +3 -3
- package/typings/index.d.ts +3 -3
package/cjs/graphqlHandler.js
CHANGED
|
@@ -7,8 +7,6 @@ const graphqlHandler = (getBuiltMesh, playgroundTitle, playgroundEnabled, graphq
|
|
|
7
7
|
return (request, ...args) => {
|
|
8
8
|
if (!yoga$) {
|
|
9
9
|
yoga$ = getBuiltMesh().then(mesh => (0, graphql_yoga_1.createYoga)({
|
|
10
|
-
parserCache: false,
|
|
11
|
-
validationCache: false,
|
|
12
10
|
plugins: [
|
|
13
11
|
...mesh.plugins,
|
|
14
12
|
(0, graphql_yoga_1.useLogger)({
|
package/cjs/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createMeshHTTPHandler = void 0;
|
|
4
|
+
const fets_1 = require("fets");
|
|
4
5
|
const cross_helpers_1 = require("@graphql-mesh/cross-helpers");
|
|
5
6
|
const utils_1 = require("@graphql-mesh/utils");
|
|
6
|
-
const router_1 = require("@whatwg-node/router");
|
|
7
7
|
const graphqlHandler_js_1 = require("./graphqlHandler.js");
|
|
8
8
|
function createMeshHTTPHandler({ baseDir, getBuiltMesh, rawServeConfig = {}, playgroundTitle, }) {
|
|
9
9
|
let readyFlag = false;
|
|
@@ -13,67 +13,101 @@ function createMeshHTTPHandler({ baseDir, getBuiltMesh, rawServeConfig = {}, pla
|
|
|
13
13
|
// TODO
|
|
14
14
|
// trustProxy = 'loopback',
|
|
15
15
|
} = rawServeConfig;
|
|
16
|
-
const router = (0,
|
|
17
|
-
router
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
const router = (0, fets_1.createRouter)();
|
|
17
|
+
router
|
|
18
|
+
.route({
|
|
19
|
+
path: '*',
|
|
20
|
+
handler() {
|
|
21
|
+
if (!mesh$) {
|
|
22
|
+
mesh$ = getBuiltMesh().then(mesh => {
|
|
23
|
+
readyFlag = true;
|
|
24
|
+
logger = mesh.logger.child('HTTP');
|
|
25
|
+
return mesh;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
.route({
|
|
31
|
+
path: '/healthcheck',
|
|
32
|
+
handler() {
|
|
33
|
+
return new fets_1.Response(null, {
|
|
34
|
+
status: 200,
|
|
23
35
|
});
|
|
24
|
-
}
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
36
|
+
},
|
|
37
|
+
})
|
|
38
|
+
.route({
|
|
39
|
+
path: '/readiness',
|
|
40
|
+
handler() {
|
|
41
|
+
return new fets_1.Response(null, {
|
|
42
|
+
status: readyFlag ? 204 : 503,
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
.route({
|
|
47
|
+
path: '*',
|
|
48
|
+
method: 'POST',
|
|
49
|
+
async handler(request) {
|
|
50
|
+
if (readyFlag) {
|
|
51
|
+
const { pubsub } = await mesh$;
|
|
52
|
+
for (const eventName of pubsub.getEventNames()) {
|
|
53
|
+
const { pathname } = new URL(request.url);
|
|
54
|
+
if (eventName === `webhook:${request.method.toLowerCase()}:${pathname}`) {
|
|
55
|
+
const body = await request.text();
|
|
56
|
+
logger.debug(`Received webhook request for ${pathname}`, body);
|
|
57
|
+
pubsub.publish(eventName, request.headers.get('content-type') === 'application/json'
|
|
58
|
+
? JSON.parse(body)
|
|
59
|
+
: body);
|
|
60
|
+
return new fets_1.Response(null, {
|
|
61
|
+
status: 204,
|
|
62
|
+
statusText: 'OK',
|
|
63
|
+
});
|
|
64
|
+
}
|
|
45
65
|
}
|
|
46
66
|
}
|
|
47
|
-
|
|
48
|
-
|
|
67
|
+
return undefined;
|
|
68
|
+
},
|
|
49
69
|
});
|
|
50
70
|
if (staticFiles) {
|
|
51
|
-
router.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
71
|
+
router.route({
|
|
72
|
+
path: '/:relativePath+',
|
|
73
|
+
method: 'GET',
|
|
74
|
+
async handler(request) {
|
|
75
|
+
let { relativePath } = request.params;
|
|
76
|
+
if (!relativePath) {
|
|
77
|
+
relativePath = 'index.html';
|
|
78
|
+
}
|
|
79
|
+
const absoluteStaticFilesPath = cross_helpers_1.path.join(baseDir, staticFiles);
|
|
80
|
+
const absolutePath = cross_helpers_1.path.join(absoluteStaticFilesPath, relativePath);
|
|
81
|
+
if (absolutePath.startsWith(absoluteStaticFilesPath) && (await (0, utils_1.pathExists)(absolutePath))) {
|
|
82
|
+
const readStream = cross_helpers_1.fs.createReadStream(absolutePath);
|
|
83
|
+
return new fets_1.Response(readStream, {
|
|
84
|
+
status: 200,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return undefined;
|
|
88
|
+
},
|
|
65
89
|
});
|
|
66
90
|
}
|
|
67
91
|
else if (graphqlPath !== '/') {
|
|
68
|
-
router.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
92
|
+
router.route({
|
|
93
|
+
path: '/',
|
|
94
|
+
method: 'GET',
|
|
95
|
+
handler() {
|
|
96
|
+
return new fets_1.Response(null, {
|
|
97
|
+
status: 302,
|
|
98
|
+
headers: {
|
|
99
|
+
Location: graphqlPath,
|
|
100
|
+
},
|
|
101
|
+
});
|
|
72
102
|
},
|
|
73
|
-
})
|
|
103
|
+
});
|
|
74
104
|
}
|
|
75
|
-
router.
|
|
76
|
-
|
|
77
|
-
|
|
105
|
+
return router.route({
|
|
106
|
+
path: '*',
|
|
107
|
+
handler: [
|
|
108
|
+
utils_1.withCookies,
|
|
109
|
+
(0, graphqlHandler_js_1.graphqlHandler)(() => mesh$, playgroundTitle, playgroundEnabled, graphqlPath, corsConfig),
|
|
110
|
+
],
|
|
111
|
+
});
|
|
78
112
|
}
|
|
79
113
|
exports.createMeshHTTPHandler = createMeshHTTPHandler;
|
package/esm/graphqlHandler.js
CHANGED
|
@@ -4,8 +4,6 @@ export const graphqlHandler = (getBuiltMesh, playgroundTitle, playgroundEnabled,
|
|
|
4
4
|
return (request, ...args) => {
|
|
5
5
|
if (!yoga$) {
|
|
6
6
|
yoga$ = getBuiltMesh().then(mesh => createYoga({
|
|
7
|
-
parserCache: false,
|
|
8
|
-
validationCache: false,
|
|
9
7
|
plugins: [
|
|
10
8
|
...mesh.plugins,
|
|
11
9
|
useLogger({
|
package/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { createRouter, Response } from 'fets';
|
|
1
2
|
import { fs, path } from '@graphql-mesh/cross-helpers';
|
|
2
3
|
import { DefaultLogger, pathExists, withCookies } from '@graphql-mesh/utils';
|
|
3
|
-
import { createRouter, Response } from '@whatwg-node/router';
|
|
4
4
|
import { graphqlHandler } from './graphqlHandler.js';
|
|
5
5
|
export function createMeshHTTPHandler({ baseDir, getBuiltMesh, rawServeConfig = {}, playgroundTitle, }) {
|
|
6
6
|
let readyFlag = false;
|
|
@@ -11,65 +11,99 @@ export function createMeshHTTPHandler({ baseDir, getBuiltMesh, rawServeConfig =
|
|
|
11
11
|
// trustProxy = 'loopback',
|
|
12
12
|
} = rawServeConfig;
|
|
13
13
|
const router = createRouter();
|
|
14
|
-
router
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
router
|
|
15
|
+
.route({
|
|
16
|
+
path: '*',
|
|
17
|
+
handler() {
|
|
18
|
+
if (!mesh$) {
|
|
19
|
+
mesh$ = getBuiltMesh().then(mesh => {
|
|
20
|
+
readyFlag = true;
|
|
21
|
+
logger = mesh.logger.child('HTTP');
|
|
22
|
+
return mesh;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
.route({
|
|
28
|
+
path: '/healthcheck',
|
|
29
|
+
handler() {
|
|
30
|
+
return new Response(null, {
|
|
31
|
+
status: 200,
|
|
20
32
|
});
|
|
21
|
-
}
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
.route({
|
|
36
|
+
path: '/readiness',
|
|
37
|
+
handler() {
|
|
38
|
+
return new Response(null, {
|
|
39
|
+
status: readyFlag ? 204 : 503,
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
})
|
|
43
|
+
.route({
|
|
44
|
+
path: '*',
|
|
45
|
+
method: 'POST',
|
|
46
|
+
async handler(request) {
|
|
47
|
+
if (readyFlag) {
|
|
48
|
+
const { pubsub } = await mesh$;
|
|
49
|
+
for (const eventName of pubsub.getEventNames()) {
|
|
50
|
+
const { pathname } = new URL(request.url);
|
|
51
|
+
if (eventName === `webhook:${request.method.toLowerCase()}:${pathname}`) {
|
|
52
|
+
const body = await request.text();
|
|
53
|
+
logger.debug(`Received webhook request for ${pathname}`, body);
|
|
54
|
+
pubsub.publish(eventName, request.headers.get('content-type') === 'application/json'
|
|
55
|
+
? JSON.parse(body)
|
|
56
|
+
: body);
|
|
57
|
+
return new Response(null, {
|
|
58
|
+
status: 204,
|
|
59
|
+
statusText: 'OK',
|
|
60
|
+
});
|
|
61
|
+
}
|
|
42
62
|
}
|
|
43
63
|
}
|
|
44
|
-
|
|
45
|
-
|
|
64
|
+
return undefined;
|
|
65
|
+
},
|
|
46
66
|
});
|
|
47
67
|
if (staticFiles) {
|
|
48
|
-
router.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
68
|
+
router.route({
|
|
69
|
+
path: '/:relativePath+',
|
|
70
|
+
method: 'GET',
|
|
71
|
+
async handler(request) {
|
|
72
|
+
let { relativePath } = request.params;
|
|
73
|
+
if (!relativePath) {
|
|
74
|
+
relativePath = 'index.html';
|
|
75
|
+
}
|
|
76
|
+
const absoluteStaticFilesPath = path.join(baseDir, staticFiles);
|
|
77
|
+
const absolutePath = path.join(absoluteStaticFilesPath, relativePath);
|
|
78
|
+
if (absolutePath.startsWith(absoluteStaticFilesPath) && (await pathExists(absolutePath))) {
|
|
79
|
+
const readStream = fs.createReadStream(absolutePath);
|
|
80
|
+
return new Response(readStream, {
|
|
81
|
+
status: 200,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return undefined;
|
|
85
|
+
},
|
|
62
86
|
});
|
|
63
87
|
}
|
|
64
88
|
else if (graphqlPath !== '/') {
|
|
65
|
-
router.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
89
|
+
router.route({
|
|
90
|
+
path: '/',
|
|
91
|
+
method: 'GET',
|
|
92
|
+
handler() {
|
|
93
|
+
return new Response(null, {
|
|
94
|
+
status: 302,
|
|
95
|
+
headers: {
|
|
96
|
+
Location: graphqlPath,
|
|
97
|
+
},
|
|
98
|
+
});
|
|
69
99
|
},
|
|
70
|
-
})
|
|
100
|
+
});
|
|
71
101
|
}
|
|
72
|
-
router.
|
|
73
|
-
|
|
74
|
-
|
|
102
|
+
return router.route({
|
|
103
|
+
path: '*',
|
|
104
|
+
handler: [
|
|
105
|
+
withCookies,
|
|
106
|
+
graphqlHandler(() => mesh$, playgroundTitle, playgroundEnabled, graphqlPath, corsConfig),
|
|
107
|
+
],
|
|
108
|
+
});
|
|
75
109
|
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/http",
|
|
3
|
-
"version": "1.0.0-alpha-
|
|
3
|
+
"version": "1.0.0-alpha-20230522105300-fe9c79867",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@graphql-mesh/cross-helpers": "
|
|
7
|
-
"@graphql-mesh/
|
|
8
|
-
"@graphql-mesh/
|
|
6
|
+
"@graphql-mesh/cross-helpers": "0.4.0-alpha-20230522105300-fe9c79867",
|
|
7
|
+
"@graphql-mesh/runtime": "1.0.0-alpha-20230522105300-fe9c79867",
|
|
8
|
+
"@graphql-mesh/types": "1.0.0-alpha-20230522105300-fe9c79867",
|
|
9
|
+
"@graphql-mesh/utils": "1.0.0-alpha-20230522105300-fe9c79867",
|
|
9
10
|
"graphql": "*",
|
|
10
11
|
"tslib": "^2.4.0"
|
|
11
12
|
},
|
|
12
13
|
"dependencies": {
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"graphql-yoga": "3.9.1"
|
|
14
|
+
"fets": "^0.1.1",
|
|
15
|
+
"graphql-yoga": "^3.9.1"
|
|
16
16
|
},
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
package/typings/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Router } from 'fets';
|
|
2
|
+
import type { MeshInstance } from '@graphql-mesh/runtime';
|
|
2
3
|
import { YamlConfig } from '@graphql-mesh/types';
|
|
3
|
-
|
|
4
|
-
export type MeshHTTPHandler<TServerContext> = Router<TServerContext>;
|
|
4
|
+
export type MeshHTTPHandler<TServerContext> = Router<TServerContext, {}, {}>;
|
|
5
5
|
export declare function createMeshHTTPHandler<TServerContext>({ baseDir, getBuiltMesh, rawServeConfig, playgroundTitle, }: {
|
|
6
6
|
baseDir: string;
|
|
7
7
|
getBuiltMesh: () => Promise<MeshInstance>;
|
package/typings/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Router } from 'fets';
|
|
2
|
+
import type { MeshInstance } from '@graphql-mesh/runtime';
|
|
2
3
|
import { YamlConfig } from '@graphql-mesh/types';
|
|
3
|
-
|
|
4
|
-
export type MeshHTTPHandler<TServerContext> = Router<TServerContext>;
|
|
4
|
+
export type MeshHTTPHandler<TServerContext> = Router<TServerContext, {}, {}>;
|
|
5
5
|
export declare function createMeshHTTPHandler<TServerContext>({ baseDir, getBuiltMesh, rawServeConfig, playgroundTitle, }: {
|
|
6
6
|
baseDir: string;
|
|
7
7
|
getBuiltMesh: () => Promise<MeshInstance>;
|