@graphql-mesh/http 1.0.0-alpha-20230524144709-24ad76be9 → 1.0.0-alpha-20230524151151-439b8293d
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/index.js +25 -22
- package/esm/index.js +25 -22
- package/package.json +5 -5
package/cjs/index.js
CHANGED
|
@@ -16,7 +16,7 @@ function createMeshHTTPHandler({ baseDir, getBuiltMesh, rawServeConfig = {}, pla
|
|
|
16
16
|
return (0, server_1.createServerAdapter)((0, graphqlHandler_js_1.graphqlHandler)(() => mesh$, playgroundTitle, playgroundEnabled, graphqlPath, corsConfig), {
|
|
17
17
|
plugins: [
|
|
18
18
|
{
|
|
19
|
-
|
|
19
|
+
onRequest({ request, url, endResponse }) {
|
|
20
20
|
if (!mesh$) {
|
|
21
21
|
mesh$ = getBuiltMesh().then(mesh => {
|
|
22
22
|
readyFlag = true;
|
|
@@ -37,21 +37,22 @@ function createMeshHTTPHandler({ baseDir, getBuiltMesh, rawServeConfig = {}, pla
|
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
39
|
if (readyFlag) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
40
|
+
return mesh$.then(async (mesh) => {
|
|
41
|
+
for (const eventName of mesh.pubsub.getEventNames()) {
|
|
42
|
+
if (eventName === `webhook:${request.method.toLowerCase()}:${url.pathname}`) {
|
|
43
|
+
const body = await request.text();
|
|
44
|
+
logger.debug(`Received webhook request for ${url.pathname}`, body);
|
|
45
|
+
mesh.pubsub.publish(eventName, request.headers.get('content-type') === 'application/json'
|
|
46
|
+
? JSON.parse(body)
|
|
47
|
+
: body);
|
|
48
|
+
endResponse(new server_1.Response(null, {
|
|
49
|
+
status: 204,
|
|
50
|
+
statusText: 'OK',
|
|
51
|
+
}));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
53
54
|
}
|
|
54
|
-
}
|
|
55
|
+
});
|
|
55
56
|
}
|
|
56
57
|
if (staticFiles && request.method === 'GET') {
|
|
57
58
|
let relativePath = url.pathname;
|
|
@@ -60,13 +61,15 @@ function createMeshHTTPHandler({ baseDir, getBuiltMesh, rawServeConfig = {}, pla
|
|
|
60
61
|
}
|
|
61
62
|
const absoluteStaticFilesPath = cross_helpers_1.path.join(baseDir, staticFiles);
|
|
62
63
|
const absolutePath = cross_helpers_1.path.join(absoluteStaticFilesPath, relativePath);
|
|
63
|
-
if (absolutePath.startsWith(absoluteStaticFilesPath)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
if (absolutePath.startsWith(absoluteStaticFilesPath)) {
|
|
65
|
+
return (0, utils_1.pathExists)(absolutePath).then(exists => {
|
|
66
|
+
if (exists) {
|
|
67
|
+
const readStream = cross_helpers_1.fs.createReadStream(absolutePath);
|
|
68
|
+
endResponse(new server_1.Response(readStream, {
|
|
69
|
+
status: 200,
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
});
|
|
70
73
|
}
|
|
71
74
|
}
|
|
72
75
|
else if (graphqlPath !== '/' && url.pathname === '/') {
|
package/esm/index.js
CHANGED
|
@@ -13,7 +13,7 @@ export function createMeshHTTPHandler({ baseDir, getBuiltMesh, rawServeConfig =
|
|
|
13
13
|
return createServerAdapter(graphqlHandler(() => mesh$, playgroundTitle, playgroundEnabled, graphqlPath, corsConfig), {
|
|
14
14
|
plugins: [
|
|
15
15
|
{
|
|
16
|
-
|
|
16
|
+
onRequest({ request, url, endResponse }) {
|
|
17
17
|
if (!mesh$) {
|
|
18
18
|
mesh$ = getBuiltMesh().then(mesh => {
|
|
19
19
|
readyFlag = true;
|
|
@@ -34,21 +34,22 @@ export function createMeshHTTPHandler({ baseDir, getBuiltMesh, rawServeConfig =
|
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
36
|
if (readyFlag) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
37
|
+
return mesh$.then(async (mesh) => {
|
|
38
|
+
for (const eventName of mesh.pubsub.getEventNames()) {
|
|
39
|
+
if (eventName === `webhook:${request.method.toLowerCase()}:${url.pathname}`) {
|
|
40
|
+
const body = await request.text();
|
|
41
|
+
logger.debug(`Received webhook request for ${url.pathname}`, body);
|
|
42
|
+
mesh.pubsub.publish(eventName, request.headers.get('content-type') === 'application/json'
|
|
43
|
+
? JSON.parse(body)
|
|
44
|
+
: body);
|
|
45
|
+
endResponse(new Response(null, {
|
|
46
|
+
status: 204,
|
|
47
|
+
statusText: 'OK',
|
|
48
|
+
}));
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
50
51
|
}
|
|
51
|
-
}
|
|
52
|
+
});
|
|
52
53
|
}
|
|
53
54
|
if (staticFiles && request.method === 'GET') {
|
|
54
55
|
let relativePath = url.pathname;
|
|
@@ -57,13 +58,15 @@ export function createMeshHTTPHandler({ baseDir, getBuiltMesh, rawServeConfig =
|
|
|
57
58
|
}
|
|
58
59
|
const absoluteStaticFilesPath = path.join(baseDir, staticFiles);
|
|
59
60
|
const absolutePath = path.join(absoluteStaticFilesPath, relativePath);
|
|
60
|
-
if (absolutePath.startsWith(absoluteStaticFilesPath)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
61
|
+
if (absolutePath.startsWith(absoluteStaticFilesPath)) {
|
|
62
|
+
return pathExists(absolutePath).then(exists => {
|
|
63
|
+
if (exists) {
|
|
64
|
+
const readStream = fs.createReadStream(absolutePath);
|
|
65
|
+
endResponse(new Response(readStream, {
|
|
66
|
+
status: 200,
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
});
|
|
67
70
|
}
|
|
68
71
|
}
|
|
69
72
|
else if (graphqlPath !== '/' && url.pathname === '/') {
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/http",
|
|
3
|
-
"version": "1.0.0-alpha-
|
|
3
|
+
"version": "1.0.0-alpha-20230524151151-439b8293d",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@graphql-mesh/cross-helpers": "0.4.0-alpha-
|
|
7
|
-
"@graphql-mesh/runtime": "1.0.0-alpha-
|
|
8
|
-
"@graphql-mesh/types": "1.0.0-alpha-
|
|
9
|
-
"@graphql-mesh/utils": "1.0.0-alpha-
|
|
6
|
+
"@graphql-mesh/cross-helpers": "0.4.0-alpha-20230524151151-439b8293d",
|
|
7
|
+
"@graphql-mesh/runtime": "1.0.0-alpha-20230524151151-439b8293d",
|
|
8
|
+
"@graphql-mesh/types": "1.0.0-alpha-20230524151151-439b8293d",
|
|
9
|
+
"@graphql-mesh/utils": "1.0.0-alpha-20230524151151-439b8293d",
|
|
10
10
|
"graphql": "*",
|
|
11
11
|
"tslib": "^2.4.0"
|
|
12
12
|
},
|