@graphql-mesh/http 0.1.5 → 0.1.8
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/index.js +12 -6
- package/index.mjs +7 -1
- package/package.json +6 -6
package/index.js
CHANGED
|
@@ -8,6 +8,7 @@ const server = require('@whatwg-node/server');
|
|
|
8
8
|
const ittyRouter = require('itty-router');
|
|
9
9
|
const ittyRouterExtras = require('itty-router-extras');
|
|
10
10
|
const graphqlYoga = require('graphql-yoga');
|
|
11
|
+
const fetch = require('@whatwg-node/fetch');
|
|
11
12
|
|
|
12
13
|
const graphqlHandler = (mesh$, playgroundTitle, playgroundEnabled, graphqlEndpoint, corsConfig) => {
|
|
13
14
|
const yoga$ = mesh$.then(mesh => graphqlYoga.createYoga({
|
|
@@ -53,10 +54,10 @@ function createMeshHTTPHandler({ baseDir, getBuiltMesh, logger, rawServeConfig =
|
|
|
53
54
|
handleRequest: router.handle,
|
|
54
55
|
baseObject: router,
|
|
55
56
|
});
|
|
56
|
-
router.all('/healthcheck', () => new Response(null, {
|
|
57
|
+
router.all('/healthcheck', () => new fetch.Response(null, {
|
|
57
58
|
status: readyFlag ? 204 : 503,
|
|
58
59
|
}));
|
|
59
|
-
router.all('/readiness', () => new Response(null, {
|
|
60
|
+
router.all('/readiness', () => new fetch.Response(null, {
|
|
60
61
|
status: readyFlag ? 204 : 503,
|
|
61
62
|
}));
|
|
62
63
|
router.post('*', async (request) => {
|
|
@@ -68,7 +69,7 @@ function createMeshHTTPHandler({ baseDir, getBuiltMesh, logger, rawServeConfig =
|
|
|
68
69
|
const body = await request.text();
|
|
69
70
|
logger.debug(`Received webhook request for ${pathname}`, body);
|
|
70
71
|
pubsub.publish(eventName, request.headers.get('application/json') === 'application/json' ? JSON.parse(body) : body);
|
|
71
|
-
return new Response(null, {
|
|
72
|
+
return new fetch.Response(null, {
|
|
72
73
|
status: 204,
|
|
73
74
|
statusText: 'OK',
|
|
74
75
|
});
|
|
@@ -83,7 +84,7 @@ function createMeshHTTPHandler({ baseDir, getBuiltMesh, logger, rawServeConfig =
|
|
|
83
84
|
const url = new URL(request.url);
|
|
84
85
|
if (url.pathname === '/' && (await utils.pathExists(indexPath))) {
|
|
85
86
|
const indexFile = await crossHelpers.fs.promises.readFile(indexPath, 'utf-8');
|
|
86
|
-
router.get('/', () => new Response(indexFile, {
|
|
87
|
+
router.get('/', () => new fetch.Response(indexFile, {
|
|
87
88
|
status: 200,
|
|
88
89
|
headers: {
|
|
89
90
|
'Content-Type': 'text/html',
|
|
@@ -93,7 +94,7 @@ function createMeshHTTPHandler({ baseDir, getBuiltMesh, logger, rawServeConfig =
|
|
|
93
94
|
const filePath = crossHelpers.path.join(baseDir, staticFiles, url.pathname);
|
|
94
95
|
if (await utils.pathExists(filePath)) {
|
|
95
96
|
const body = await crossHelpers.fs.promises.readFile(filePath);
|
|
96
|
-
return new Response(body, {
|
|
97
|
+
return new fetch.Response(body, {
|
|
97
98
|
status: 200,
|
|
98
99
|
});
|
|
99
100
|
}
|
|
@@ -101,7 +102,12 @@ function createMeshHTTPHandler({ baseDir, getBuiltMesh, logger, rawServeConfig =
|
|
|
101
102
|
});
|
|
102
103
|
}
|
|
103
104
|
else {
|
|
104
|
-
router.get('/',
|
|
105
|
+
router.get('/', () => new fetch.Response(null, {
|
|
106
|
+
status: 302,
|
|
107
|
+
headers: {
|
|
108
|
+
Location: graphqlPath,
|
|
109
|
+
},
|
|
110
|
+
}));
|
|
105
111
|
}
|
|
106
112
|
router.all(graphqlPath, ittyRouterExtras.withCookies, graphqlHandler(mesh$, playgroundTitle, playgroundEnabled, graphqlPath, corsConfig));
|
|
107
113
|
return requestHandler;
|
package/index.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { createServerAdapter } from '@whatwg-node/server';
|
|
|
4
4
|
import { Router } from 'itty-router';
|
|
5
5
|
import { withCookies } from 'itty-router-extras';
|
|
6
6
|
import { createYoga, useLogger } from 'graphql-yoga';
|
|
7
|
+
import { Response } from '@whatwg-node/fetch';
|
|
7
8
|
|
|
8
9
|
const graphqlHandler = (mesh$, playgroundTitle, playgroundEnabled, graphqlEndpoint, corsConfig) => {
|
|
9
10
|
const yoga$ = mesh$.then(mesh => createYoga({
|
|
@@ -97,7 +98,12 @@ function createMeshHTTPHandler({ baseDir, getBuiltMesh, logger, rawServeConfig =
|
|
|
97
98
|
});
|
|
98
99
|
}
|
|
99
100
|
else {
|
|
100
|
-
router.get('/',
|
|
101
|
+
router.get('/', () => new Response(null, {
|
|
102
|
+
status: 302,
|
|
103
|
+
headers: {
|
|
104
|
+
Location: graphqlPath,
|
|
105
|
+
},
|
|
106
|
+
}));
|
|
101
107
|
}
|
|
102
108
|
router.all(graphqlPath, withCookies, graphqlHandler(mesh$, playgroundTitle, playgroundEnabled, graphqlPath, corsConfig));
|
|
103
109
|
return requestHandler;
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/http",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"graphql": "*"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@graphql-mesh/cross-helpers": "0.2.
|
|
10
|
-
"@graphql-mesh/runtime": "0.44.
|
|
11
|
-
"@graphql-mesh/utils": "0.41.
|
|
12
|
-
"@whatwg-node/fetch": "0.4.
|
|
13
|
-
"@whatwg-node/server": "0.
|
|
9
|
+
"@graphql-mesh/cross-helpers": "0.2.6",
|
|
10
|
+
"@graphql-mesh/runtime": "0.44.5",
|
|
11
|
+
"@graphql-mesh/utils": "0.41.10",
|
|
12
|
+
"@whatwg-node/fetch": "^0.4.3",
|
|
13
|
+
"@whatwg-node/server": "0.3.0",
|
|
14
14
|
"graphql-yoga": "3.0.0-alpha-20220905163021-e923bb34",
|
|
15
15
|
"itty-router": "2.6.1",
|
|
16
16
|
"itty-router-extras": "0.4.2",
|