@graphql-mesh/http 0.2.15 → 0.2.16-alpha-20221124121048-e923140d9
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/graphqlHandler.d.ts +1 -1
- package/index.js +39 -32
- package/index.mjs +39 -32
- package/package.json +5 -5
package/graphqlHandler.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { MeshInstance } from '@graphql-mesh/runtime';
|
|
2
2
|
import { CORSOptions } from 'graphql-yoga';
|
|
3
|
-
export declare const graphqlHandler: (
|
|
3
|
+
export declare const graphqlHandler: (getBuiltMesh: () => Promise<MeshInstance>, playgroundTitle: string, playgroundEnabled: boolean, graphqlEndpoint: string, corsConfig: CORSOptions) => (request: Request, ...args: any[]) => Promise<Response>;
|
package/index.js
CHANGED
|
@@ -10,49 +10,56 @@ const ittyRouterExtras = require('itty-router-extras');
|
|
|
10
10
|
const graphqlYoga = require('graphql-yoga');
|
|
11
11
|
const fetch = require('@whatwg-node/fetch');
|
|
12
12
|
|
|
13
|
-
const graphqlHandler = (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
13
|
+
const graphqlHandler = (getBuiltMesh, playgroundTitle, playgroundEnabled, graphqlEndpoint, corsConfig) => {
|
|
14
|
+
let yoga$;
|
|
15
|
+
return (request, ...args) => {
|
|
16
|
+
if (!yoga$) {
|
|
17
|
+
yoga$ = getBuiltMesh().then(mesh => graphqlYoga.createYoga({
|
|
18
|
+
parserCache: false,
|
|
19
|
+
validationCache: false,
|
|
20
|
+
plugins: [
|
|
21
|
+
...mesh.plugins,
|
|
22
|
+
graphqlYoga.useLogger({
|
|
23
|
+
skipIntrospection: true,
|
|
24
|
+
logFn: (eventName, { args }) => {
|
|
25
|
+
if (eventName.endsWith('-start')) {
|
|
26
|
+
mesh.logger.debug(`\t headers: `, args.contextValue.headers);
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
}),
|
|
30
|
+
],
|
|
31
|
+
logging: mesh.logger,
|
|
32
|
+
maskedErrors: false,
|
|
33
|
+
graphiql: playgroundEnabled && {
|
|
34
|
+
title: playgroundTitle,
|
|
25
35
|
},
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
},
|
|
33
|
-
cors: corsConfig,
|
|
34
|
-
graphqlEndpoint,
|
|
35
|
-
landingPage: false,
|
|
36
|
-
}));
|
|
37
|
-
return async (request, ...args) => {
|
|
38
|
-
const yoga = await yoga$;
|
|
39
|
-
return yoga.handle(request, ...args);
|
|
36
|
+
cors: corsConfig,
|
|
37
|
+
graphqlEndpoint,
|
|
38
|
+
landingPage: false,
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
return yoga$.then(yoga => yoga(request, ...args));
|
|
40
42
|
};
|
|
41
43
|
};
|
|
42
44
|
|
|
43
45
|
function createMeshHTTPHandler({ baseDir, getBuiltMesh, rawServeConfig = {}, playgroundTitle, }) {
|
|
44
46
|
let readyFlag = false;
|
|
45
47
|
let logger = new utils.DefaultLogger('Mesh HTTP');
|
|
46
|
-
|
|
47
|
-
readyFlag = true;
|
|
48
|
-
logger = mesh.logger.child('HTTP');
|
|
49
|
-
return mesh;
|
|
50
|
-
});
|
|
48
|
+
let mesh$;
|
|
51
49
|
const { cors: corsConfig, staticFiles, playground: playgroundEnabled, endpoint: graphqlPath = '/graphql',
|
|
52
50
|
// TODO
|
|
53
51
|
// trustProxy = 'loopback',
|
|
54
52
|
} = rawServeConfig;
|
|
55
53
|
const serverAdapter = server.createServerAdapter(ittyRouter.Router());
|
|
54
|
+
serverAdapter.all('*', () => {
|
|
55
|
+
if (!mesh$) {
|
|
56
|
+
mesh$ = getBuiltMesh().then(mesh => {
|
|
57
|
+
readyFlag = true;
|
|
58
|
+
logger = mesh.logger.child('HTTP');
|
|
59
|
+
return mesh;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
});
|
|
56
63
|
serverAdapter.all('/healthcheck', () => new fetch.Response(null, {
|
|
57
64
|
status: 200,
|
|
58
65
|
}));
|
|
@@ -108,7 +115,7 @@ function createMeshHTTPHandler({ baseDir, getBuiltMesh, rawServeConfig = {}, pla
|
|
|
108
115
|
},
|
|
109
116
|
}));
|
|
110
117
|
}
|
|
111
|
-
serverAdapter.all('*', ittyRouterExtras.withCookies, graphqlHandler(mesh$, playgroundTitle, playgroundEnabled, graphqlPath, corsConfig));
|
|
118
|
+
serverAdapter.all('*', ittyRouterExtras.withCookies, graphqlHandler(() => mesh$, playgroundTitle, playgroundEnabled, graphqlPath, corsConfig));
|
|
112
119
|
return serverAdapter;
|
|
113
120
|
}
|
|
114
121
|
|
package/index.mjs
CHANGED
|
@@ -6,49 +6,56 @@ import { withCookies } from 'itty-router-extras';
|
|
|
6
6
|
import { createYoga, useLogger } from 'graphql-yoga';
|
|
7
7
|
import { Response } from '@whatwg-node/fetch';
|
|
8
8
|
|
|
9
|
-
const graphqlHandler = (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
const graphqlHandler = (getBuiltMesh, playgroundTitle, playgroundEnabled, graphqlEndpoint, corsConfig) => {
|
|
10
|
+
let yoga$;
|
|
11
|
+
return (request, ...args) => {
|
|
12
|
+
if (!yoga$) {
|
|
13
|
+
yoga$ = getBuiltMesh().then(mesh => createYoga({
|
|
14
|
+
parserCache: false,
|
|
15
|
+
validationCache: false,
|
|
16
|
+
plugins: [
|
|
17
|
+
...mesh.plugins,
|
|
18
|
+
useLogger({
|
|
19
|
+
skipIntrospection: true,
|
|
20
|
+
logFn: (eventName, { args }) => {
|
|
21
|
+
if (eventName.endsWith('-start')) {
|
|
22
|
+
mesh.logger.debug(`\t headers: `, args.contextValue.headers);
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
}),
|
|
26
|
+
],
|
|
27
|
+
logging: mesh.logger,
|
|
28
|
+
maskedErrors: false,
|
|
29
|
+
graphiql: playgroundEnabled && {
|
|
30
|
+
title: playgroundTitle,
|
|
21
31
|
},
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
},
|
|
29
|
-
cors: corsConfig,
|
|
30
|
-
graphqlEndpoint,
|
|
31
|
-
landingPage: false,
|
|
32
|
-
}));
|
|
33
|
-
return async (request, ...args) => {
|
|
34
|
-
const yoga = await yoga$;
|
|
35
|
-
return yoga.handle(request, ...args);
|
|
32
|
+
cors: corsConfig,
|
|
33
|
+
graphqlEndpoint,
|
|
34
|
+
landingPage: false,
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
return yoga$.then(yoga => yoga(request, ...args));
|
|
36
38
|
};
|
|
37
39
|
};
|
|
38
40
|
|
|
39
41
|
function createMeshHTTPHandler({ baseDir, getBuiltMesh, rawServeConfig = {}, playgroundTitle, }) {
|
|
40
42
|
let readyFlag = false;
|
|
41
43
|
let logger = new DefaultLogger('Mesh HTTP');
|
|
42
|
-
|
|
43
|
-
readyFlag = true;
|
|
44
|
-
logger = mesh.logger.child('HTTP');
|
|
45
|
-
return mesh;
|
|
46
|
-
});
|
|
44
|
+
let mesh$;
|
|
47
45
|
const { cors: corsConfig, staticFiles, playground: playgroundEnabled, endpoint: graphqlPath = '/graphql',
|
|
48
46
|
// TODO
|
|
49
47
|
// trustProxy = 'loopback',
|
|
50
48
|
} = rawServeConfig;
|
|
51
49
|
const serverAdapter = createServerAdapter(Router());
|
|
50
|
+
serverAdapter.all('*', () => {
|
|
51
|
+
if (!mesh$) {
|
|
52
|
+
mesh$ = getBuiltMesh().then(mesh => {
|
|
53
|
+
readyFlag = true;
|
|
54
|
+
logger = mesh.logger.child('HTTP');
|
|
55
|
+
return mesh;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
});
|
|
52
59
|
serverAdapter.all('/healthcheck', () => new Response(null, {
|
|
53
60
|
status: 200,
|
|
54
61
|
}));
|
|
@@ -104,7 +111,7 @@ function createMeshHTTPHandler({ baseDir, getBuiltMesh, rawServeConfig = {}, pla
|
|
|
104
111
|
},
|
|
105
112
|
}));
|
|
106
113
|
}
|
|
107
|
-
serverAdapter.all('*', withCookies, graphqlHandler(mesh$, playgroundTitle, playgroundEnabled, graphqlPath, corsConfig));
|
|
114
|
+
serverAdapter.all('*', withCookies, graphqlHandler(() => mesh$, playgroundTitle, playgroundEnabled, graphqlPath, corsConfig));
|
|
108
115
|
return serverAdapter;
|
|
109
116
|
}
|
|
110
117
|
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/http",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.16-alpha-20221124121048-e923140d9",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"graphql": "*"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@graphql-mesh/cross-helpers": "0.2.10",
|
|
10
|
-
"@graphql-mesh/runtime": "0.44.
|
|
11
|
-
"@graphql-mesh/types": "0.
|
|
12
|
-
"@graphql-mesh/utils": "0.42.
|
|
10
|
+
"@graphql-mesh/runtime": "0.44.34-alpha-20221124121048-e923140d9",
|
|
11
|
+
"@graphql-mesh/types": "0.87.0-alpha-20221124121048-e923140d9",
|
|
12
|
+
"@graphql-mesh/utils": "0.42.8-alpha-20221124121048-e923140d9",
|
|
13
13
|
"@whatwg-node/fetch": "^0.5.0",
|
|
14
14
|
"@whatwg-node/server": "^0.4.10",
|
|
15
|
-
"graphql-yoga": "3.0.
|
|
15
|
+
"graphql-yoga": "3.0.2",
|
|
16
16
|
"itty-router": "2.6.6",
|
|
17
17
|
"itty-router-extras": "0.4.2",
|
|
18
18
|
"tslib": "^2.4.0"
|