graphql-http 1.18.0 → 1.20.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/README.md +92 -5
- package/lib/client.d.mts +2 -2
- package/lib/client.d.ts +2 -2
- package/lib/common.d.mts +4 -4
- package/lib/common.d.ts +4 -4
- package/lib/handler.d.mts +30 -38
- package/lib/handler.d.ts +30 -38
- package/lib/handler.js +130 -133
- package/lib/handler.mjs +131 -131
- package/lib/use/express.js +1 -18
- package/lib/use/express.mjs +1 -18
- package/lib/use/fastify.js +1 -19
- package/lib/use/fastify.mjs +1 -19
- package/lib/use/fetch.d.mts +1 -1
- package/lib/use/fetch.d.ts +1 -1
- package/lib/use/fetch.js +2 -22
- package/lib/use/fetch.mjs +2 -22
- package/lib/use/http.d.mts +1 -1
- package/lib/use/http.d.ts +1 -1
- package/lib/use/http.js +2 -19
- package/lib/use/http.mjs +2 -19
- package/lib/use/http2.d.mts +1 -1
- package/lib/use/http2.d.ts +1 -1
- package/lib/use/http2.js +2 -19
- package/lib/use/http2.mjs +2 -19
- package/lib/use/koa.js +0 -14
- package/lib/use/koa.mjs +0 -14
- package/lib/use/node.d.mts +1 -1
- package/lib/use/node.d.ts +1 -1
- package/lib/use/node.js +1 -1
- package/lib/use/node.mjs +1 -1
- package/lib/use/uWebSockets.d.mts +36 -0
- package/lib/use/uWebSockets.d.ts +36 -0
- package/lib/use/uWebSockets.js +84 -0
- package/lib/use/uWebSockets.mjs +80 -0
- package/lib/utils.js +3 -1
- package/lib/utils.mjs +3 -1
- package/package.json +44 -37
package/lib/use/http.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { createHandler as createRawHandler, } from '../handler.mjs';
|
|
|
6
6
|
* ```js
|
|
7
7
|
* import http from 'http';
|
|
8
8
|
* import { createHandler } from 'graphql-http/lib/use/http';
|
|
9
|
-
* import { schema } from './my-graphql-
|
|
9
|
+
* import { schema } from './my-graphql-schema/index.mjs';
|
|
10
10
|
*
|
|
11
11
|
* const server = http.createServer(createHandler({ schema }));
|
|
12
12
|
*
|
|
@@ -17,7 +17,6 @@ import { createHandler as createRawHandler, } from '../handler.mjs';
|
|
|
17
17
|
* @category Server/http
|
|
18
18
|
*/
|
|
19
19
|
export function createHandler(options) {
|
|
20
|
-
const isProd = process.env.NODE_ENV === 'production';
|
|
21
20
|
const handle = createRawHandler(options);
|
|
22
21
|
return async function requestListener(req, res) {
|
|
23
22
|
try {
|
|
@@ -46,23 +45,7 @@ export function createHandler(options) {
|
|
|
46
45
|
// If you wish to handle them differently, consider implementing your own request handler.
|
|
47
46
|
console.error('Internal error occurred during request handling. ' +
|
|
48
47
|
'Please check your implementation.', err);
|
|
49
|
-
|
|
50
|
-
res.writeHead(500).end();
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
res
|
|
54
|
-
.writeHead(500, { 'content-type': 'application/json; charset=utf-8' })
|
|
55
|
-
.end(JSON.stringify({
|
|
56
|
-
errors: [
|
|
57
|
-
err instanceof Error
|
|
58
|
-
? {
|
|
59
|
-
message: err.message,
|
|
60
|
-
stack: err.stack,
|
|
61
|
-
}
|
|
62
|
-
: err,
|
|
63
|
-
],
|
|
64
|
-
}));
|
|
65
|
-
}
|
|
48
|
+
res.writeHead(500).end();
|
|
66
49
|
}
|
|
67
50
|
};
|
|
68
51
|
}
|
package/lib/use/http2.d.mts
CHANGED
|
@@ -28,7 +28,7 @@ export type HandlerOptions<Context extends OperationContext = undefined> = RawHa
|
|
|
28
28
|
* import fs from 'fs';
|
|
29
29
|
* import http2 from 'http2';
|
|
30
30
|
* import { createHandler } from 'graphql-http/lib/use/http2';
|
|
31
|
-
* import { schema } from './my-graphql-
|
|
31
|
+
* import { schema } from './my-graphql-schema/index.mjs';
|
|
32
32
|
*
|
|
33
33
|
* const server = http2.createSecureServer(
|
|
34
34
|
* {
|
package/lib/use/http2.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export type HandlerOptions<Context extends OperationContext = undefined> = RawHa
|
|
|
28
28
|
* import fs from 'fs';
|
|
29
29
|
* import http2 from 'http2';
|
|
30
30
|
* import { createHandler } from 'graphql-http/lib/use/http2';
|
|
31
|
-
* import { schema } from './my-graphql-
|
|
31
|
+
* import { schema } from './my-graphql-schema';
|
|
32
32
|
*
|
|
33
33
|
* const server = http2.createSecureServer(
|
|
34
34
|
* {
|
package/lib/use/http2.js
CHANGED
|
@@ -15,7 +15,7 @@ const handler_1 = require("../handler");
|
|
|
15
15
|
* import fs from 'fs';
|
|
16
16
|
* import http2 from 'http2';
|
|
17
17
|
* import { createHandler } from 'graphql-http/lib/use/http2';
|
|
18
|
-
* import { schema } from './my-graphql-
|
|
18
|
+
* import { schema } from './my-graphql-schema';
|
|
19
19
|
*
|
|
20
20
|
* const server = http2.createSecureServer(
|
|
21
21
|
* {
|
|
@@ -32,7 +32,6 @@ const handler_1 = require("../handler");
|
|
|
32
32
|
* @category Server/http2
|
|
33
33
|
*/
|
|
34
34
|
function createHandler(options) {
|
|
35
|
-
const isProd = process.env.NODE_ENV === 'production';
|
|
36
35
|
const handle = (0, handler_1.createHandler)(options);
|
|
37
36
|
return async function requestListener(req, res) {
|
|
38
37
|
try {
|
|
@@ -67,23 +66,7 @@ function createHandler(options) {
|
|
|
67
66
|
// If you wish to handle them differently, consider implementing your own request handler.
|
|
68
67
|
console.error('Internal error occurred during request handling. ' +
|
|
69
68
|
'Please check your implementation.', err);
|
|
70
|
-
|
|
71
|
-
res.writeHead(500).end();
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
res
|
|
75
|
-
.writeHead(500, { 'content-type': 'application/json; charset=utf-8' })
|
|
76
|
-
.end(JSON.stringify({
|
|
77
|
-
errors: [
|
|
78
|
-
err instanceof Error
|
|
79
|
-
? {
|
|
80
|
-
message: err.message,
|
|
81
|
-
stack: err.stack,
|
|
82
|
-
}
|
|
83
|
-
: err,
|
|
84
|
-
],
|
|
85
|
-
}));
|
|
86
|
-
}
|
|
69
|
+
res.writeHead(500).end();
|
|
87
70
|
}
|
|
88
71
|
};
|
|
89
72
|
}
|
package/lib/use/http2.mjs
CHANGED
|
@@ -12,7 +12,7 @@ import { createHandler as createRawHandler, } from '../handler.mjs';
|
|
|
12
12
|
* import fs from 'fs';
|
|
13
13
|
* import http2 from 'http2';
|
|
14
14
|
* import { createHandler } from 'graphql-http/lib/use/http2';
|
|
15
|
-
* import { schema } from './my-graphql-
|
|
15
|
+
* import { schema } from './my-graphql-schema/index.mjs';
|
|
16
16
|
*
|
|
17
17
|
* const server = http2.createSecureServer(
|
|
18
18
|
* {
|
|
@@ -29,7 +29,6 @@ import { createHandler as createRawHandler, } from '../handler.mjs';
|
|
|
29
29
|
* @category Server/http2
|
|
30
30
|
*/
|
|
31
31
|
export function createHandler(options) {
|
|
32
|
-
const isProd = process.env.NODE_ENV === 'production';
|
|
33
32
|
const handle = createRawHandler(options);
|
|
34
33
|
return async function requestListener(req, res) {
|
|
35
34
|
try {
|
|
@@ -64,23 +63,7 @@ export function createHandler(options) {
|
|
|
64
63
|
// If you wish to handle them differently, consider implementing your own request handler.
|
|
65
64
|
console.error('Internal error occurred during request handling. ' +
|
|
66
65
|
'Please check your implementation.', err);
|
|
67
|
-
|
|
68
|
-
res.writeHead(500).end();
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
res
|
|
72
|
-
.writeHead(500, { 'content-type': 'application/json; charset=utf-8' })
|
|
73
|
-
.end(JSON.stringify({
|
|
74
|
-
errors: [
|
|
75
|
-
err instanceof Error
|
|
76
|
-
? {
|
|
77
|
-
message: err.message,
|
|
78
|
-
stack: err.stack,
|
|
79
|
-
}
|
|
80
|
-
: err,
|
|
81
|
-
],
|
|
82
|
-
}));
|
|
83
|
-
}
|
|
66
|
+
res.writeHead(500).end();
|
|
84
67
|
}
|
|
85
68
|
};
|
|
86
69
|
}
|
package/lib/use/koa.js
CHANGED
|
@@ -22,7 +22,6 @@ const handler_1 = require("../handler");
|
|
|
22
22
|
* @category Server/koa
|
|
23
23
|
*/
|
|
24
24
|
function createHandler(options) {
|
|
25
|
-
const isProd = process.env.NODE_ENV === 'production';
|
|
26
25
|
const handle = (0, handler_1.createHandler)(options);
|
|
27
26
|
return async function requestListener(ctx) {
|
|
28
27
|
try {
|
|
@@ -59,19 +58,6 @@ function createHandler(options) {
|
|
|
59
58
|
console.error('Internal error occurred during request handling. ' +
|
|
60
59
|
'Please check your implementation.', err);
|
|
61
60
|
ctx.response.status = 500;
|
|
62
|
-
if (!isProd) {
|
|
63
|
-
ctx.response.set('content-type', 'application/json; charset=utf-8');
|
|
64
|
-
ctx.body = {
|
|
65
|
-
errors: [
|
|
66
|
-
err instanceof Error
|
|
67
|
-
? {
|
|
68
|
-
message: err.message,
|
|
69
|
-
stack: err.stack,
|
|
70
|
-
}
|
|
71
|
-
: err,
|
|
72
|
-
],
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
61
|
}
|
|
76
62
|
};
|
|
77
63
|
}
|
package/lib/use/koa.mjs
CHANGED
|
@@ -19,7 +19,6 @@ import { createHandler as createRawHandler, } from '../handler.mjs';
|
|
|
19
19
|
* @category Server/koa
|
|
20
20
|
*/
|
|
21
21
|
export function createHandler(options) {
|
|
22
|
-
const isProd = process.env.NODE_ENV === 'production';
|
|
23
22
|
const handle = createRawHandler(options);
|
|
24
23
|
return async function requestListener(ctx) {
|
|
25
24
|
try {
|
|
@@ -56,19 +55,6 @@ export function createHandler(options) {
|
|
|
56
55
|
console.error('Internal error occurred during request handling. ' +
|
|
57
56
|
'Please check your implementation.', err);
|
|
58
57
|
ctx.response.status = 500;
|
|
59
|
-
if (!isProd) {
|
|
60
|
-
ctx.response.set('content-type', 'application/json; charset=utf-8');
|
|
61
|
-
ctx.body = {
|
|
62
|
-
errors: [
|
|
63
|
-
err instanceof Error
|
|
64
|
-
? {
|
|
65
|
-
message: err.message,
|
|
66
|
-
stack: err.stack,
|
|
67
|
-
}
|
|
68
|
-
: err,
|
|
69
|
-
],
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
58
|
}
|
|
73
59
|
};
|
|
74
60
|
}
|
package/lib/use/node.d.mts
CHANGED
|
@@ -16,7 +16,7 @@ export type HandlerOptions<Context extends OperationContext = undefined> = HttpH
|
|
|
16
16
|
* ```js
|
|
17
17
|
* import http from 'http';
|
|
18
18
|
* import { createHandler } from 'graphql-http/lib/use/node';
|
|
19
|
-
* import { schema } from './my-graphql-
|
|
19
|
+
* import { schema } from './my-graphql-schema/index.mjs';
|
|
20
20
|
*
|
|
21
21
|
* const server = http.createServer(createHandler({ schema }));
|
|
22
22
|
*
|
package/lib/use/node.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export type HandlerOptions<Context extends OperationContext = undefined> = HttpH
|
|
|
16
16
|
* ```js
|
|
17
17
|
* import http from 'http';
|
|
18
18
|
* import { createHandler } from 'graphql-http/lib/use/node';
|
|
19
|
-
* import { schema } from './my-graphql-
|
|
19
|
+
* import { schema } from './my-graphql-schema';
|
|
20
20
|
*
|
|
21
21
|
* const server = http.createServer(createHandler({ schema }));
|
|
22
22
|
*
|
package/lib/use/node.js
CHANGED
|
@@ -9,7 +9,7 @@ const http_1 = require("./http");
|
|
|
9
9
|
* ```js
|
|
10
10
|
* import http from 'http';
|
|
11
11
|
* import { createHandler } from 'graphql-http/lib/use/node';
|
|
12
|
-
* import { schema } from './my-graphql-
|
|
12
|
+
* import { schema } from './my-graphql-schema';
|
|
13
13
|
*
|
|
14
14
|
* const server = http.createServer(createHandler({ schema }));
|
|
15
15
|
*
|
package/lib/use/node.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { createHandler as httpCreateHandler, } from './http.mjs';
|
|
|
6
6
|
* ```js
|
|
7
7
|
* import http from 'http';
|
|
8
8
|
* import { createHandler } from 'graphql-http/lib/use/node';
|
|
9
|
-
* import { schema } from './my-graphql-
|
|
9
|
+
* import { schema } from './my-graphql-schema/index.mjs';
|
|
10
10
|
*
|
|
11
11
|
* const server = http.createServer(createHandler({ schema }));
|
|
12
12
|
*
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { HttpRequest, HttpResponse } from 'uWebSockets.js';
|
|
2
|
+
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler.mjs';
|
|
3
|
+
/**
|
|
4
|
+
* The context in the request for the handler.
|
|
5
|
+
*
|
|
6
|
+
* @category Server/uWebSockets
|
|
7
|
+
*/
|
|
8
|
+
export interface RequestContext {
|
|
9
|
+
res: HttpResponse;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Handler options when using the http adapter.
|
|
13
|
+
*
|
|
14
|
+
* @category Server/uWebSockets
|
|
15
|
+
*/
|
|
16
|
+
export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<HttpRequest, RequestContext, Context>;
|
|
17
|
+
/**
|
|
18
|
+
* Create a GraphQL over HTTP spec compliant request handler for
|
|
19
|
+
* the Node environment [uWebSockets.js module](https://github.com/uNetworking/uWebSockets.js/).
|
|
20
|
+
*
|
|
21
|
+
* ```js
|
|
22
|
+
* import uWS from 'uWebSockets.js'; // yarn add uWebSockets.js@uNetworking/uWebSockets.js#<version>
|
|
23
|
+
* import { createHandler } from 'graphql-http/lib/use/uWebSockets';
|
|
24
|
+
* import { schema } from './my-graphql-schema/index.mjs';
|
|
25
|
+
*
|
|
26
|
+
* uWS
|
|
27
|
+
* .App()
|
|
28
|
+
* .any('/graphql', createHandler({ schema }))
|
|
29
|
+
* .listen(4000, () => {
|
|
30
|
+
* console.log('Listening to port 4000');
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @category Server/uWebSockets
|
|
35
|
+
*/
|
|
36
|
+
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<Context>): (res: HttpResponse, req: HttpRequest) => Promise<void>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { HttpRequest, HttpResponse } from 'uWebSockets.js';
|
|
2
|
+
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
|
|
3
|
+
/**
|
|
4
|
+
* The context in the request for the handler.
|
|
5
|
+
*
|
|
6
|
+
* @category Server/uWebSockets
|
|
7
|
+
*/
|
|
8
|
+
export interface RequestContext {
|
|
9
|
+
res: HttpResponse;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Handler options when using the http adapter.
|
|
13
|
+
*
|
|
14
|
+
* @category Server/uWebSockets
|
|
15
|
+
*/
|
|
16
|
+
export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<HttpRequest, RequestContext, Context>;
|
|
17
|
+
/**
|
|
18
|
+
* Create a GraphQL over HTTP spec compliant request handler for
|
|
19
|
+
* the Node environment [uWebSockets.js module](https://github.com/uNetworking/uWebSockets.js/).
|
|
20
|
+
*
|
|
21
|
+
* ```js
|
|
22
|
+
* import uWS from 'uWebSockets.js'; // yarn add uWebSockets.js@uNetworking/uWebSockets.js#<version>
|
|
23
|
+
* import { createHandler } from 'graphql-http/lib/use/uWebSockets';
|
|
24
|
+
* import { schema } from './my-graphql-schema';
|
|
25
|
+
*
|
|
26
|
+
* uWS
|
|
27
|
+
* .App()
|
|
28
|
+
* .any('/graphql', createHandler({ schema }))
|
|
29
|
+
* .listen(4000, () => {
|
|
30
|
+
* console.log('Listening to port 4000');
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @category Server/uWebSockets
|
|
35
|
+
*/
|
|
36
|
+
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<Context>): (res: HttpResponse, req: HttpRequest) => Promise<void>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createHandler = void 0;
|
|
4
|
+
const handler_1 = require("../handler");
|
|
5
|
+
/**
|
|
6
|
+
* Create a GraphQL over HTTP spec compliant request handler for
|
|
7
|
+
* the Node environment [uWebSockets.js module](https://github.com/uNetworking/uWebSockets.js/).
|
|
8
|
+
*
|
|
9
|
+
* ```js
|
|
10
|
+
* import uWS from 'uWebSockets.js'; // yarn add uWebSockets.js@uNetworking/uWebSockets.js#<version>
|
|
11
|
+
* import { createHandler } from 'graphql-http/lib/use/uWebSockets';
|
|
12
|
+
* import { schema } from './my-graphql-schema';
|
|
13
|
+
*
|
|
14
|
+
* uWS
|
|
15
|
+
* .App()
|
|
16
|
+
* .any('/graphql', createHandler({ schema }))
|
|
17
|
+
* .listen(4000, () => {
|
|
18
|
+
* console.log('Listening to port 4000');
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @category Server/uWebSockets
|
|
23
|
+
*/
|
|
24
|
+
function createHandler(options) {
|
|
25
|
+
const handle = (0, handler_1.createHandler)(options);
|
|
26
|
+
return async function requestListener(res, req) {
|
|
27
|
+
let aborted = false;
|
|
28
|
+
res.onAborted(() => (aborted = true));
|
|
29
|
+
try {
|
|
30
|
+
let url = req.getUrl();
|
|
31
|
+
const query = req.getQuery();
|
|
32
|
+
if (query) {
|
|
33
|
+
url += '?' + query;
|
|
34
|
+
}
|
|
35
|
+
const [body, init] = await handle({
|
|
36
|
+
url,
|
|
37
|
+
method: req.getMethod().toUpperCase(),
|
|
38
|
+
headers: { get: (key) => req.getHeader(key) },
|
|
39
|
+
body: () => new Promise((resolve) => {
|
|
40
|
+
let body = '';
|
|
41
|
+
if (aborted) {
|
|
42
|
+
resolve(body);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
res.onData((chunk, isLast) => {
|
|
46
|
+
body += Buffer.from(chunk, 0, chunk.byteLength).toString();
|
|
47
|
+
if (isLast) {
|
|
48
|
+
resolve(body);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}),
|
|
53
|
+
raw: req,
|
|
54
|
+
context: { res },
|
|
55
|
+
});
|
|
56
|
+
if (!aborted) {
|
|
57
|
+
res.cork(() => {
|
|
58
|
+
res.writeStatus(`${init.status} ${init.statusText}`);
|
|
59
|
+
for (const [key, val] of Object.entries(init.headers || {})) {
|
|
60
|
+
res.writeHeader(key, val);
|
|
61
|
+
}
|
|
62
|
+
if (body) {
|
|
63
|
+
res.end(body);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
res.endWithoutBody();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
// The handler shouldnt throw errors.
|
|
73
|
+
// If you wish to handle them differently, consider implementing your own request handler.
|
|
74
|
+
console.error('Internal error occurred during request handling. ' +
|
|
75
|
+
'Please check your implementation.', err);
|
|
76
|
+
if (!aborted) {
|
|
77
|
+
res.cork(() => {
|
|
78
|
+
res.writeStatus('500 Internal Server Error').endWithoutBody();
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
exports.createHandler = createHandler;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { createHandler as createRawHandler, } from '../handler.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Create a GraphQL over HTTP spec compliant request handler for
|
|
4
|
+
* the Node environment [uWebSockets.js module](https://github.com/uNetworking/uWebSockets.js/).
|
|
5
|
+
*
|
|
6
|
+
* ```js
|
|
7
|
+
* import uWS from 'uWebSockets.js'; // yarn add uWebSockets.js@uNetworking/uWebSockets.js#<version>
|
|
8
|
+
* import { createHandler } from 'graphql-http/lib/use/uWebSockets';
|
|
9
|
+
* import { schema } from './my-graphql-schema/index.mjs';
|
|
10
|
+
*
|
|
11
|
+
* uWS
|
|
12
|
+
* .App()
|
|
13
|
+
* .any('/graphql', createHandler({ schema }))
|
|
14
|
+
* .listen(4000, () => {
|
|
15
|
+
* console.log('Listening to port 4000');
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @category Server/uWebSockets
|
|
20
|
+
*/
|
|
21
|
+
export function createHandler(options) {
|
|
22
|
+
const handle = createRawHandler(options);
|
|
23
|
+
return async function requestListener(res, req) {
|
|
24
|
+
let aborted = false;
|
|
25
|
+
res.onAborted(() => (aborted = true));
|
|
26
|
+
try {
|
|
27
|
+
let url = req.getUrl();
|
|
28
|
+
const query = req.getQuery();
|
|
29
|
+
if (query) {
|
|
30
|
+
url += '?' + query;
|
|
31
|
+
}
|
|
32
|
+
const [body, init] = await handle({
|
|
33
|
+
url,
|
|
34
|
+
method: req.getMethod().toUpperCase(),
|
|
35
|
+
headers: { get: (key) => req.getHeader(key) },
|
|
36
|
+
body: () => new Promise((resolve) => {
|
|
37
|
+
let body = '';
|
|
38
|
+
if (aborted) {
|
|
39
|
+
resolve(body);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
res.onData((chunk, isLast) => {
|
|
43
|
+
body += Buffer.from(chunk, 0, chunk.byteLength).toString();
|
|
44
|
+
if (isLast) {
|
|
45
|
+
resolve(body);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}),
|
|
50
|
+
raw: req,
|
|
51
|
+
context: { res },
|
|
52
|
+
});
|
|
53
|
+
if (!aborted) {
|
|
54
|
+
res.cork(() => {
|
|
55
|
+
res.writeStatus(`${init.status} ${init.statusText}`);
|
|
56
|
+
for (const [key, val] of Object.entries(init.headers || {})) {
|
|
57
|
+
res.writeHeader(key, val);
|
|
58
|
+
}
|
|
59
|
+
if (body) {
|
|
60
|
+
res.end(body);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
res.endWithoutBody();
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
// The handler shouldnt throw errors.
|
|
70
|
+
// If you wish to handle them differently, consider implementing your own request handler.
|
|
71
|
+
console.error('Internal error occurred during request handling. ' +
|
|
72
|
+
'Please check your implementation.', err);
|
|
73
|
+
if (!aborted) {
|
|
74
|
+
res.cork(() => {
|
|
75
|
+
res.writeStatus('500 Internal Server Error').endWithoutBody();
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
package/lib/utils.js
CHANGED
|
@@ -48,7 +48,9 @@ function isAsyncIterable(val) {
|
|
|
48
48
|
}
|
|
49
49
|
exports.isAsyncIterable = isAsyncIterable;
|
|
50
50
|
/** @private */
|
|
51
|
-
function jsonErrorReplacer(_key,
|
|
51
|
+
function jsonErrorReplacer(_key,
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
|
+
val) {
|
|
52
54
|
if (val instanceof Error &&
|
|
53
55
|
// GraphQL errors implement their own stringer
|
|
54
56
|
!isGraphQLError(val)) {
|
package/lib/utils.mjs
CHANGED
|
@@ -39,7 +39,9 @@ export function isAsyncIterable(val) {
|
|
|
39
39
|
return typeof Object(val)[Symbol.asyncIterator] === 'function';
|
|
40
40
|
}
|
|
41
41
|
/** @private */
|
|
42
|
-
export function jsonErrorReplacer(_key,
|
|
42
|
+
export function jsonErrorReplacer(_key,
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
|
+
val) {
|
|
43
45
|
if (val instanceof Error &&
|
|
44
46
|
// GraphQL errors implement their own stringer
|
|
45
47
|
!isGraphQLError(val)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphql-http",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.20.0",
|
|
4
4
|
"description": "Simple, pluggable, zero-dependency, GraphQL over HTTP spec compliant server, client and audit suite.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphql",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"engines": {
|
|
25
25
|
"node": ">=12"
|
|
26
26
|
},
|
|
27
|
-
"packageManager": "yarn@3.
|
|
27
|
+
"packageManager": "yarn@3.6.1",
|
|
28
28
|
"main": "lib/index.js",
|
|
29
29
|
"module": "lib/index.mjs",
|
|
30
30
|
"browser": "umd/graphql-http.js",
|
|
@@ -70,6 +70,11 @@
|
|
|
70
70
|
"require": "./lib/use/koa.js",
|
|
71
71
|
"import": "./lib/use/koa.mjs"
|
|
72
72
|
},
|
|
73
|
+
"./lib/use/uWebSockets": {
|
|
74
|
+
"types": "./lib/use/uWebSockets.d.ts",
|
|
75
|
+
"require": "./lib/use/uWebSockets.js",
|
|
76
|
+
"import": "./lib/use/uWebSockets.mjs"
|
|
77
|
+
},
|
|
73
78
|
"./package.json": "./package.json"
|
|
74
79
|
},
|
|
75
80
|
"types": "lib/index.d.ts",
|
|
@@ -86,18 +91,18 @@
|
|
|
86
91
|
"access": "public"
|
|
87
92
|
},
|
|
88
93
|
"scripts": {
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"lint
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"type-check": "tsc --noEmit",
|
|
94
|
+
"check:format": "prettier --check .",
|
|
95
|
+
"format": "yarn check:format --write",
|
|
96
|
+
"check:lint": "eslint 'src'",
|
|
97
|
+
"check:spell": "cspell --gitignore **/*.md",
|
|
98
|
+
"check:type": "tsc --noEmit",
|
|
95
99
|
"test": "NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 jest",
|
|
96
|
-
"build:esm": "tsc -b tsconfig.esm.json &&
|
|
100
|
+
"build:esm": "tsc -b tsconfig.esm.json && tsx scripts/esm-post-process.ts",
|
|
97
101
|
"build:cjs": "tsc -b tsconfig.cjs.json",
|
|
98
102
|
"build:umd": "rollup --configPlugin typescript --config rollup.config.ts",
|
|
99
103
|
"build": "yarn build:esm && yarn build:cjs && yarn build:umd",
|
|
100
|
-
"release": "semantic-release"
|
|
104
|
+
"release": "semantic-release",
|
|
105
|
+
"gendocs": "typedoc --options typedoc.js src/"
|
|
101
106
|
},
|
|
102
107
|
"workspaces": [
|
|
103
108
|
"implementations/**/*"
|
|
@@ -106,50 +111,52 @@
|
|
|
106
111
|
"graphql": ">=0.11 <=16"
|
|
107
112
|
},
|
|
108
113
|
"devDependencies": {
|
|
109
|
-
"@babel/core": "^7.
|
|
114
|
+
"@babel/core": "^7.22.8",
|
|
110
115
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
111
116
|
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
|
|
112
117
|
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
|
|
113
118
|
"@babel/plugin-proposal-optional-chaining": "^7.21.0",
|
|
114
|
-
"@babel/preset-env": "^7.
|
|
115
|
-
"@babel/preset-typescript": "^7.
|
|
116
|
-
"@
|
|
117
|
-
"@rollup/plugin-
|
|
119
|
+
"@babel/preset-env": "^7.22.7",
|
|
120
|
+
"@babel/preset-typescript": "^7.22.5",
|
|
121
|
+
"@cspell/cspell-types": "^6.31.1",
|
|
122
|
+
"@rollup/plugin-terser": "^0.4.3",
|
|
123
|
+
"@rollup/plugin-typescript": "^11.1.2",
|
|
118
124
|
"@semantic-release/changelog": "^6.0.3",
|
|
119
125
|
"@semantic-release/git": "^10.0.1",
|
|
120
|
-
"@types/eslint": "^8.
|
|
126
|
+
"@types/eslint": "^8.44.0",
|
|
121
127
|
"@types/express": "^4.17.17",
|
|
122
128
|
"@types/glob": "^8.1.0",
|
|
123
129
|
"@types/html-validator": "^5.0.3",
|
|
124
|
-
"@types/jest": "^29.5.
|
|
130
|
+
"@types/jest": "^29.5.2",
|
|
131
|
+
"@types/k6": "^0.45.0",
|
|
125
132
|
"@types/koa": "^2.13.6",
|
|
126
133
|
"@types/koa-mount": "^4.0.2",
|
|
127
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
128
|
-
"@typescript-eslint/parser": "^5.
|
|
129
|
-
"@whatwg-node/fetch": "^0.
|
|
130
|
-
"babel-jest": "^29.
|
|
131
|
-
"
|
|
134
|
+
"@typescript-eslint/eslint-plugin": "^5.61.0",
|
|
135
|
+
"@typescript-eslint/parser": "^5.61.0",
|
|
136
|
+
"@whatwg-node/fetch": "^0.9.7",
|
|
137
|
+
"babel-jest": "^29.6.1",
|
|
138
|
+
"cspell": "^6.31.1",
|
|
139
|
+
"eslint": "^8.44.0",
|
|
132
140
|
"eslint-config-prettier": "^8.8.0",
|
|
133
141
|
"express": "^4.18.2",
|
|
134
|
-
"fastify": "^4.
|
|
135
|
-
"glob": "^10.
|
|
136
|
-
"graphql": "^16.
|
|
142
|
+
"fastify": "^4.19.2",
|
|
143
|
+
"glob": "^10.3.2",
|
|
144
|
+
"graphql": "^16.7.1",
|
|
137
145
|
"html-validator": "^6.0.1",
|
|
138
|
-
"jest": "^29.
|
|
139
|
-
"jest-jasmine2": "^29.
|
|
146
|
+
"jest": "^29.6.1",
|
|
147
|
+
"jest-jasmine2": "^29.6.1",
|
|
140
148
|
"koa": "^2.14.2",
|
|
141
149
|
"koa-mount": "^4.0.0",
|
|
142
150
|
"node-fetch": "^3.3.1",
|
|
143
|
-
"prettier": "^2.8.
|
|
144
|
-
"rollup": "^3.
|
|
151
|
+
"prettier": "^2.8.8",
|
|
152
|
+
"rollup": "^3.26.2",
|
|
145
153
|
"rollup-plugin-gzip": "^3.1.0",
|
|
146
|
-
"semantic-release": "^21.0.
|
|
147
|
-
"tslib": "^2.
|
|
148
|
-
"
|
|
149
|
-
"typedoc
|
|
150
|
-
"
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
"npm/libnpmversion": "^3.0.6"
|
|
154
|
+
"semantic-release": "^21.0.7",
|
|
155
|
+
"tslib": "^2.6.0",
|
|
156
|
+
"tsx": "^3.12.7",
|
|
157
|
+
"typedoc": "^0.24.8",
|
|
158
|
+
"typedoc-plugin-markdown": "^3.15.3",
|
|
159
|
+
"typescript": "^5.1.6",
|
|
160
|
+
"uWebSockets.js": "uNetworking/uWebSockets.js#v20.30.0"
|
|
154
161
|
}
|
|
155
162
|
}
|