graphql-http 1.20.0 → 1.22.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 +13 -1
- package/lib/handler.d.mts +19 -2
- package/lib/handler.d.ts +19 -2
- package/lib/handler.js +145 -115
- package/lib/handler.mjs +137 -108
- package/lib/use/@netlify/functions.d.mts +14 -0
- package/lib/use/@netlify/functions.d.ts +14 -0
- package/lib/use/@netlify/functions.js +37 -0
- package/lib/use/@netlify/functions.mjs +33 -0
- package/lib/use/express.d.mts +41 -0
- package/lib/use/express.d.ts +41 -0
- package/lib/use/express.js +72 -19
- package/lib/use/express.mjs +71 -19
- package/lib/use/fastify.d.mts +42 -1
- package/lib/use/fastify.d.ts +42 -1
- package/lib/use/fastify.js +68 -11
- package/lib/use/fastify.mjs +67 -11
- package/lib/use/fetch.d.mts +50 -0
- package/lib/use/fetch.d.ts +50 -0
- package/lib/use/fetch.js +74 -9
- package/lib/use/fetch.mjs +73 -9
- package/lib/use/http.d.mts +44 -0
- package/lib/use/http.d.ts +44 -0
- package/lib/use/http.js +75 -13
- package/lib/use/http.mjs +74 -13
- package/lib/use/http2.d.mts +56 -0
- package/lib/use/http2.d.ts +56 -0
- package/lib/use/http2.js +93 -13
- package/lib/use/http2.mjs +92 -13
- package/lib/use/koa.d.mts +47 -1
- package/lib/use/koa.d.ts +47 -1
- package/lib/use/koa.js +84 -1
- package/lib/use/koa.mjs +83 -1
- package/lib/use/uWebSockets.d.mts +55 -0
- package/lib/use/uWebSockets.d.ts +55 -0
- package/lib/use/uWebSockets.js +109 -31
- package/lib/use/uWebSockets.mjs +108 -31
- package/lib/utils.d.mts +0 -7
- package/lib/utils.d.ts +0 -7
- package/lib/utils.js +1 -31
- package/lib/utils.mjs +0 -27
- package/package.json +28 -32
- package/umd/graphql-http-audits.js +2 -2
- package/umd/graphql-http-audits.min.js +1 -1
- package/umd/graphql-http-audits.min.js.gz +0 -0
- package/umd/graphql-http.js +3 -2
- package/umd/graphql-http.min.js +1 -1
- package/umd/graphql-http.min.js.gz +0 -0
package/lib/use/uWebSockets.js
CHANGED
|
@@ -1,7 +1,82 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createHandler = void 0;
|
|
3
|
+
exports.createHandler = exports.parseRequestParams = void 0;
|
|
4
4
|
const handler_1 = require("../handler");
|
|
5
|
+
/**
|
|
6
|
+
* The GraphQL over HTTP spec compliant request parser for an incoming GraphQL request.
|
|
7
|
+
*
|
|
8
|
+
* It is important to pass in the `abortedRef` so that the parser does not perform any
|
|
9
|
+
* operations on a disposed request (see example).
|
|
10
|
+
*
|
|
11
|
+
* If the HTTP request _is not_ a [well-formatted GraphQL over HTTP request](https://graphql.github.io/graphql-over-http/draft/#sec-Request), the function will respond
|
|
12
|
+
* on the `HttpResponse` argument and return `null`.
|
|
13
|
+
*
|
|
14
|
+
* If the HTTP request _is_ a [well-formatted GraphQL over HTTP request](https://graphql.github.io/graphql-over-http/draft/#sec-Request), but is invalid or malformed,
|
|
15
|
+
* the function will throw an error and it is up to the user to handle and respond as they see fit.
|
|
16
|
+
*
|
|
17
|
+
* ```js
|
|
18
|
+
* import uWS from 'uWebSockets.js'; // yarn add uWebSockets.js@uNetworking/uWebSockets.js#<version>
|
|
19
|
+
* import { parseRequestParams } from 'graphql-http/lib/use/uWebSockets';
|
|
20
|
+
*
|
|
21
|
+
* uWS
|
|
22
|
+
* .App()
|
|
23
|
+
* .any('/graphql', async (res, req) => {
|
|
24
|
+
* const abortedRef = { current: false };
|
|
25
|
+
* res.onAborted(() => (abortedRef.current = true));
|
|
26
|
+
* try {
|
|
27
|
+
* const maybeParams = await parseRequestParams(req, res, abortedRef);
|
|
28
|
+
* if (!maybeParams) {
|
|
29
|
+
* // not a well-formatted GraphQL over HTTP request,
|
|
30
|
+
* // parser responded and there's nothing else to do
|
|
31
|
+
* return;
|
|
32
|
+
* }
|
|
33
|
+
*
|
|
34
|
+
* // well-formatted GraphQL over HTTP request,
|
|
35
|
+
* // with valid parameters
|
|
36
|
+
* if (!abortedRef.current) {
|
|
37
|
+
* res.writeStatus('200 OK');
|
|
38
|
+
* res.end(JSON.stringify(maybeParams, null, ' '));
|
|
39
|
+
* }
|
|
40
|
+
* } catch (err) {
|
|
41
|
+
* // well-formatted GraphQL over HTTP request,
|
|
42
|
+
* // but with invalid parameters
|
|
43
|
+
* if (!abortedRef.current) {
|
|
44
|
+
* res.writeStatus('400 Bad Request');
|
|
45
|
+
* res.end(err.message);
|
|
46
|
+
* }
|
|
47
|
+
* }
|
|
48
|
+
* })
|
|
49
|
+
* .listen(4000, () => {
|
|
50
|
+
* console.log('Listening to port 4000');
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @category Server/uWebSockets
|
|
55
|
+
*/
|
|
56
|
+
async function parseRequestParams(req, res, abortedRef) {
|
|
57
|
+
const rawReq = toRequest(req, res, abortedRef);
|
|
58
|
+
const paramsOrRes = await (0, handler_1.parseRequestParams)(rawReq);
|
|
59
|
+
if (!('query' in paramsOrRes)) {
|
|
60
|
+
if (!abortedRef.current) {
|
|
61
|
+
const [body, init] = paramsOrRes;
|
|
62
|
+
res.cork(() => {
|
|
63
|
+
res.writeStatus(`${init.status} ${init.statusText}`);
|
|
64
|
+
for (const [key, val] of Object.entries(init.headers || {})) {
|
|
65
|
+
res.writeHeader(key, val);
|
|
66
|
+
}
|
|
67
|
+
if (body) {
|
|
68
|
+
res.end(body);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
res.endWithoutBody();
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
return paramsOrRes;
|
|
78
|
+
}
|
|
79
|
+
exports.parseRequestParams = parseRequestParams;
|
|
5
80
|
/**
|
|
6
81
|
* Create a GraphQL over HTTP spec compliant request handler for
|
|
7
82
|
* the Node environment [uWebSockets.js module](https://github.com/uNetworking/uWebSockets.js/).
|
|
@@ -24,36 +99,11 @@ const handler_1 = require("../handler");
|
|
|
24
99
|
function createHandler(options) {
|
|
25
100
|
const handle = (0, handler_1.createHandler)(options);
|
|
26
101
|
return async function requestListener(res, req) {
|
|
27
|
-
|
|
28
|
-
res.onAborted(() => (
|
|
102
|
+
const abortedRef = { current: false };
|
|
103
|
+
res.onAborted(() => (abortedRef.current = true));
|
|
29
104
|
try {
|
|
30
|
-
|
|
31
|
-
|
|
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) {
|
|
105
|
+
const [body, init] = await handle(toRequest(req, res, abortedRef));
|
|
106
|
+
if (!abortedRef.current) {
|
|
57
107
|
res.cork(() => {
|
|
58
108
|
res.writeStatus(`${init.status} ${init.statusText}`);
|
|
59
109
|
for (const [key, val] of Object.entries(init.headers || {})) {
|
|
@@ -73,7 +123,7 @@ function createHandler(options) {
|
|
|
73
123
|
// If you wish to handle them differently, consider implementing your own request handler.
|
|
74
124
|
console.error('Internal error occurred during request handling. ' +
|
|
75
125
|
'Please check your implementation.', err);
|
|
76
|
-
if (!
|
|
126
|
+
if (!abortedRef.current) {
|
|
77
127
|
res.cork(() => {
|
|
78
128
|
res.writeStatus('500 Internal Server Error').endWithoutBody();
|
|
79
129
|
});
|
|
@@ -82,3 +132,31 @@ function createHandler(options) {
|
|
|
82
132
|
};
|
|
83
133
|
}
|
|
84
134
|
exports.createHandler = createHandler;
|
|
135
|
+
function toRequest(req, res, abortedRef) {
|
|
136
|
+
let url = req.getUrl();
|
|
137
|
+
const query = req.getQuery();
|
|
138
|
+
if (query) {
|
|
139
|
+
url += '?' + query;
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
url,
|
|
143
|
+
method: req.getMethod().toUpperCase(),
|
|
144
|
+
headers: { get: (key) => req.getHeader(key) },
|
|
145
|
+
body: () => new Promise((resolve) => {
|
|
146
|
+
let body = '';
|
|
147
|
+
if (abortedRef.current) {
|
|
148
|
+
resolve(body);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
res.onData((chunk, isLast) => {
|
|
152
|
+
body += Buffer.from(chunk, 0, chunk.byteLength).toString();
|
|
153
|
+
if (isLast) {
|
|
154
|
+
resolve(body);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}),
|
|
159
|
+
raw: req,
|
|
160
|
+
context: { res },
|
|
161
|
+
};
|
|
162
|
+
}
|
package/lib/use/uWebSockets.mjs
CHANGED
|
@@ -1,4 +1,78 @@
|
|
|
1
|
-
import { createHandler as createRawHandler, } from '../handler.mjs';
|
|
1
|
+
import { createHandler as createRawHandler, parseRequestParams as rawParseRequestParams, } from '../handler.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* The GraphQL over HTTP spec compliant request parser for an incoming GraphQL request.
|
|
4
|
+
*
|
|
5
|
+
* It is important to pass in the `abortedRef` so that the parser does not perform any
|
|
6
|
+
* operations on a disposed request (see example).
|
|
7
|
+
*
|
|
8
|
+
* If the HTTP request _is not_ a [well-formatted GraphQL over HTTP request](https://graphql.github.io/graphql-over-http/draft/#sec-Request), the function will respond
|
|
9
|
+
* on the `HttpResponse` argument and return `null`.
|
|
10
|
+
*
|
|
11
|
+
* If the HTTP request _is_ a [well-formatted GraphQL over HTTP request](https://graphql.github.io/graphql-over-http/draft/#sec-Request), but is invalid or malformed,
|
|
12
|
+
* the function will throw an error and it is up to the user to handle and respond as they see fit.
|
|
13
|
+
*
|
|
14
|
+
* ```js
|
|
15
|
+
* import uWS from 'uWebSockets.js'; // yarn add uWebSockets.js@uNetworking/uWebSockets.js#<version>
|
|
16
|
+
* import { parseRequestParams } from 'graphql-http/lib/use/uWebSockets';
|
|
17
|
+
*
|
|
18
|
+
* uWS
|
|
19
|
+
* .App()
|
|
20
|
+
* .any('/graphql', async (res, req) => {
|
|
21
|
+
* const abortedRef = { current: false };
|
|
22
|
+
* res.onAborted(() => (abortedRef.current = true));
|
|
23
|
+
* try {
|
|
24
|
+
* const maybeParams = await parseRequestParams(req, res, abortedRef);
|
|
25
|
+
* if (!maybeParams) {
|
|
26
|
+
* // not a well-formatted GraphQL over HTTP request,
|
|
27
|
+
* // parser responded and there's nothing else to do
|
|
28
|
+
* return;
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* // well-formatted GraphQL over HTTP request,
|
|
32
|
+
* // with valid parameters
|
|
33
|
+
* if (!abortedRef.current) {
|
|
34
|
+
* res.writeStatus('200 OK');
|
|
35
|
+
* res.end(JSON.stringify(maybeParams, null, ' '));
|
|
36
|
+
* }
|
|
37
|
+
* } catch (err) {
|
|
38
|
+
* // well-formatted GraphQL over HTTP request,
|
|
39
|
+
* // but with invalid parameters
|
|
40
|
+
* if (!abortedRef.current) {
|
|
41
|
+
* res.writeStatus('400 Bad Request');
|
|
42
|
+
* res.end(err.message);
|
|
43
|
+
* }
|
|
44
|
+
* }
|
|
45
|
+
* })
|
|
46
|
+
* .listen(4000, () => {
|
|
47
|
+
* console.log('Listening to port 4000');
|
|
48
|
+
* });
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @category Server/uWebSockets
|
|
52
|
+
*/
|
|
53
|
+
export async function parseRequestParams(req, res, abortedRef) {
|
|
54
|
+
const rawReq = toRequest(req, res, abortedRef);
|
|
55
|
+
const paramsOrRes = await rawParseRequestParams(rawReq);
|
|
56
|
+
if (!('query' in paramsOrRes)) {
|
|
57
|
+
if (!abortedRef.current) {
|
|
58
|
+
const [body, init] = paramsOrRes;
|
|
59
|
+
res.cork(() => {
|
|
60
|
+
res.writeStatus(`${init.status} ${init.statusText}`);
|
|
61
|
+
for (const [key, val] of Object.entries(init.headers || {})) {
|
|
62
|
+
res.writeHeader(key, val);
|
|
63
|
+
}
|
|
64
|
+
if (body) {
|
|
65
|
+
res.end(body);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
res.endWithoutBody();
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
return paramsOrRes;
|
|
75
|
+
}
|
|
2
76
|
/**
|
|
3
77
|
* Create a GraphQL over HTTP spec compliant request handler for
|
|
4
78
|
* the Node environment [uWebSockets.js module](https://github.com/uNetworking/uWebSockets.js/).
|
|
@@ -21,36 +95,11 @@ import { createHandler as createRawHandler, } from '../handler.mjs';
|
|
|
21
95
|
export function createHandler(options) {
|
|
22
96
|
const handle = createRawHandler(options);
|
|
23
97
|
return async function requestListener(res, req) {
|
|
24
|
-
|
|
25
|
-
res.onAborted(() => (
|
|
98
|
+
const abortedRef = { current: false };
|
|
99
|
+
res.onAborted(() => (abortedRef.current = true));
|
|
26
100
|
try {
|
|
27
|
-
|
|
28
|
-
|
|
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) {
|
|
101
|
+
const [body, init] = await handle(toRequest(req, res, abortedRef));
|
|
102
|
+
if (!abortedRef.current) {
|
|
54
103
|
res.cork(() => {
|
|
55
104
|
res.writeStatus(`${init.status} ${init.statusText}`);
|
|
56
105
|
for (const [key, val] of Object.entries(init.headers || {})) {
|
|
@@ -70,7 +119,7 @@ export function createHandler(options) {
|
|
|
70
119
|
// If you wish to handle them differently, consider implementing your own request handler.
|
|
71
120
|
console.error('Internal error occurred during request handling. ' +
|
|
72
121
|
'Please check your implementation.', err);
|
|
73
|
-
if (!
|
|
122
|
+
if (!abortedRef.current) {
|
|
74
123
|
res.cork(() => {
|
|
75
124
|
res.writeStatus('500 Internal Server Error').endWithoutBody();
|
|
76
125
|
});
|
|
@@ -78,3 +127,31 @@ export function createHandler(options) {
|
|
|
78
127
|
}
|
|
79
128
|
};
|
|
80
129
|
}
|
|
130
|
+
function toRequest(req, res, abortedRef) {
|
|
131
|
+
let url = req.getUrl();
|
|
132
|
+
const query = req.getQuery();
|
|
133
|
+
if (query) {
|
|
134
|
+
url += '?' + query;
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
url,
|
|
138
|
+
method: req.getMethod().toUpperCase(),
|
|
139
|
+
headers: { get: (key) => req.getHeader(key) },
|
|
140
|
+
body: () => new Promise((resolve) => {
|
|
141
|
+
let body = '';
|
|
142
|
+
if (abortedRef.current) {
|
|
143
|
+
resolve(body);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
res.onData((chunk, isLast) => {
|
|
147
|
+
body += Buffer.from(chunk, 0, chunk.byteLength).toString();
|
|
148
|
+
if (isLast) {
|
|
149
|
+
resolve(body);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}),
|
|
154
|
+
raw: req,
|
|
155
|
+
context: { res },
|
|
156
|
+
};
|
|
157
|
+
}
|
package/lib/utils.d.mts
CHANGED
|
@@ -4,18 +4,11 @@
|
|
|
4
4
|
*
|
|
5
5
|
*/
|
|
6
6
|
import type { ExecutionResult } from 'graphql';
|
|
7
|
-
import { GraphQLError } from 'graphql';
|
|
8
7
|
/** @private */
|
|
9
8
|
export declare function extendedTypeof(val: unknown): 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function' | 'array' | 'null';
|
|
10
9
|
/** @private */
|
|
11
10
|
export declare function isObject(val: unknown): val is Record<PropertyKey, any>;
|
|
12
11
|
/** @private */
|
|
13
|
-
export declare function areGraphQLErrors(obj: unknown): obj is readonly GraphQLError[];
|
|
14
|
-
/** @private */
|
|
15
|
-
export declare function isGraphQLError(obj: unknown): obj is GraphQLError;
|
|
16
|
-
/** @private */
|
|
17
12
|
export declare function isExecutionResult(val: unknown): val is ExecutionResult;
|
|
18
13
|
/** @private */
|
|
19
14
|
export declare function isAsyncIterable<T = unknown>(val: unknown): val is AsyncIterable<T>;
|
|
20
|
-
/** @private */
|
|
21
|
-
export declare function jsonErrorReplacer(_key: string, val: any): any;
|
package/lib/utils.d.ts
CHANGED
|
@@ -4,18 +4,11 @@
|
|
|
4
4
|
*
|
|
5
5
|
*/
|
|
6
6
|
import type { ExecutionResult } from 'graphql';
|
|
7
|
-
import { GraphQLError } from 'graphql';
|
|
8
7
|
/** @private */
|
|
9
8
|
export declare function extendedTypeof(val: unknown): 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function' | 'array' | 'null';
|
|
10
9
|
/** @private */
|
|
11
10
|
export declare function isObject(val: unknown): val is Record<PropertyKey, any>;
|
|
12
11
|
/** @private */
|
|
13
|
-
export declare function areGraphQLErrors(obj: unknown): obj is readonly GraphQLError[];
|
|
14
|
-
/** @private */
|
|
15
|
-
export declare function isGraphQLError(obj: unknown): obj is GraphQLError;
|
|
16
|
-
/** @private */
|
|
17
12
|
export declare function isExecutionResult(val: unknown): val is ExecutionResult;
|
|
18
13
|
/** @private */
|
|
19
14
|
export declare function isAsyncIterable<T = unknown>(val: unknown): val is AsyncIterable<T>;
|
|
20
|
-
/** @private */
|
|
21
|
-
export declare function jsonErrorReplacer(_key: string, val: any): any;
|
package/lib/utils.js
CHANGED
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.
|
|
9
|
-
const graphql_1 = require("graphql");
|
|
8
|
+
exports.isAsyncIterable = exports.isExecutionResult = exports.isObject = exports.extendedTypeof = void 0;
|
|
10
9
|
/** @private */
|
|
11
10
|
function extendedTypeof(val) {
|
|
12
11
|
if (val === null) {
|
|
@@ -24,19 +23,6 @@ function isObject(val) {
|
|
|
24
23
|
}
|
|
25
24
|
exports.isObject = isObject;
|
|
26
25
|
/** @private */
|
|
27
|
-
function areGraphQLErrors(obj) {
|
|
28
|
-
return (Array.isArray(obj) &&
|
|
29
|
-
obj.length > 0 &&
|
|
30
|
-
// if one item in the array is a GraphQLError, we're good
|
|
31
|
-
obj.some(isGraphQLError));
|
|
32
|
-
}
|
|
33
|
-
exports.areGraphQLErrors = areGraphQLErrors;
|
|
34
|
-
/** @private */
|
|
35
|
-
function isGraphQLError(obj) {
|
|
36
|
-
return obj instanceof graphql_1.GraphQLError;
|
|
37
|
-
}
|
|
38
|
-
exports.isGraphQLError = isGraphQLError;
|
|
39
|
-
/** @private */
|
|
40
26
|
function isExecutionResult(val) {
|
|
41
27
|
return (isObject(val) &&
|
|
42
28
|
('data' in val || ('data' in val && val.data == null && 'errors' in val)));
|
|
@@ -47,19 +33,3 @@ function isAsyncIterable(val) {
|
|
|
47
33
|
return typeof Object(val)[Symbol.asyncIterator] === 'function';
|
|
48
34
|
}
|
|
49
35
|
exports.isAsyncIterable = isAsyncIterable;
|
|
50
|
-
/** @private */
|
|
51
|
-
function jsonErrorReplacer(_key,
|
|
52
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
|
-
val) {
|
|
54
|
-
if (val instanceof Error &&
|
|
55
|
-
// GraphQL errors implement their own stringer
|
|
56
|
-
!isGraphQLError(val)) {
|
|
57
|
-
return {
|
|
58
|
-
// name: val.name, name is included in message
|
|
59
|
-
message: val.message,
|
|
60
|
-
// stack: val.stack, can leak sensitive details
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
return val;
|
|
64
|
-
}
|
|
65
|
-
exports.jsonErrorReplacer = jsonErrorReplacer;
|
package/lib/utils.mjs
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* utils
|
|
4
4
|
*
|
|
5
5
|
*/
|
|
6
|
-
import { GraphQLError } from 'graphql';
|
|
7
6
|
/** @private */
|
|
8
7
|
export function extendedTypeof(val) {
|
|
9
8
|
if (val === null) {
|
|
@@ -19,17 +18,6 @@ export function isObject(val) {
|
|
|
19
18
|
return typeof val === 'object' && val !== null;
|
|
20
19
|
}
|
|
21
20
|
/** @private */
|
|
22
|
-
export function areGraphQLErrors(obj) {
|
|
23
|
-
return (Array.isArray(obj) &&
|
|
24
|
-
obj.length > 0 &&
|
|
25
|
-
// if one item in the array is a GraphQLError, we're good
|
|
26
|
-
obj.some(isGraphQLError));
|
|
27
|
-
}
|
|
28
|
-
/** @private */
|
|
29
|
-
export function isGraphQLError(obj) {
|
|
30
|
-
return obj instanceof GraphQLError;
|
|
31
|
-
}
|
|
32
|
-
/** @private */
|
|
33
21
|
export function isExecutionResult(val) {
|
|
34
22
|
return (isObject(val) &&
|
|
35
23
|
('data' in val || ('data' in val && val.data == null && 'errors' in val)));
|
|
@@ -38,18 +26,3 @@ export function isExecutionResult(val) {
|
|
|
38
26
|
export function isAsyncIterable(val) {
|
|
39
27
|
return typeof Object(val)[Symbol.asyncIterator] === 'function';
|
|
40
28
|
}
|
|
41
|
-
/** @private */
|
|
42
|
-
export function jsonErrorReplacer(_key,
|
|
43
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
|
-
val) {
|
|
45
|
-
if (val instanceof Error &&
|
|
46
|
-
// GraphQL errors implement their own stringer
|
|
47
|
-
!isGraphQLError(val)) {
|
|
48
|
-
return {
|
|
49
|
-
// name: val.name, name is included in message
|
|
50
|
-
message: val.message,
|
|
51
|
-
// stack: val.stack, can leak sensitive details
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
return val;
|
|
55
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphql-http",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.22.0",
|
|
4
4
|
"description": "Simple, pluggable, zero-dependency, GraphQL over HTTP spec compliant server, client and audit suite.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphql",
|
|
@@ -65,6 +65,11 @@
|
|
|
65
65
|
"require": "./lib/use/fastify.js",
|
|
66
66
|
"import": "./lib/use/fastify.mjs"
|
|
67
67
|
},
|
|
68
|
+
"./lib/use/@netlify/functions": {
|
|
69
|
+
"types": "./lib/use/@netlify/functions.d.ts",
|
|
70
|
+
"require": "./lib/use/@netlify/functions.js",
|
|
71
|
+
"import": "./lib/use/@netlify/functions.mjs"
|
|
72
|
+
},
|
|
68
73
|
"./lib/use/koa": {
|
|
69
74
|
"types": "./lib/use/koa.d.ts",
|
|
70
75
|
"require": "./lib/use/koa.js",
|
|
@@ -96,7 +101,7 @@
|
|
|
96
101
|
"check:lint": "eslint 'src'",
|
|
97
102
|
"check:spell": "cspell --gitignore **/*.md",
|
|
98
103
|
"check:type": "tsc --noEmit",
|
|
99
|
-
"test": "
|
|
104
|
+
"test": "vitest",
|
|
100
105
|
"build:esm": "tsc -b tsconfig.esm.json && tsx scripts/esm-post-process.ts",
|
|
101
106
|
"build:cjs": "tsc -b tsconfig.cjs.json",
|
|
102
107
|
"build:umd": "rollup --configPlugin typescript --config rollup.config.ts",
|
|
@@ -111,52 +116,43 @@
|
|
|
111
116
|
"graphql": ">=0.11 <=16"
|
|
112
117
|
},
|
|
113
118
|
"devDependencies": {
|
|
114
|
-
"@
|
|
115
|
-
"@
|
|
116
|
-
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
|
|
117
|
-
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
|
|
118
|
-
"@babel/plugin-proposal-optional-chaining": "^7.21.0",
|
|
119
|
-
"@babel/preset-env": "^7.22.7",
|
|
120
|
-
"@babel/preset-typescript": "^7.22.5",
|
|
121
|
-
"@cspell/cspell-types": "^6.31.1",
|
|
119
|
+
"@cspell/cspell-types": "^7.0.0",
|
|
120
|
+
"@netlify/functions": "^1.6.0",
|
|
122
121
|
"@rollup/plugin-terser": "^0.4.3",
|
|
123
122
|
"@rollup/plugin-typescript": "^11.1.2",
|
|
124
123
|
"@semantic-release/changelog": "^6.0.3",
|
|
125
124
|
"@semantic-release/git": "^10.0.1",
|
|
126
|
-
"@types/eslint": "^8.44.
|
|
125
|
+
"@types/eslint": "^8.44.2",
|
|
127
126
|
"@types/express": "^4.17.17",
|
|
128
127
|
"@types/glob": "^8.1.0",
|
|
129
128
|
"@types/html-validator": "^5.0.3",
|
|
130
|
-
"@types/
|
|
131
|
-
"@types/
|
|
132
|
-
"@types/koa": "^2.13.6",
|
|
129
|
+
"@types/k6": "^0.46.0",
|
|
130
|
+
"@types/koa": "^2.13.8",
|
|
133
131
|
"@types/koa-mount": "^4.0.2",
|
|
134
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
135
|
-
"@typescript-eslint/parser": "^
|
|
136
|
-
"@whatwg-node/fetch": "^0.9.
|
|
137
|
-
"
|
|
138
|
-
"
|
|
139
|
-
"eslint": "^
|
|
140
|
-
"eslint-config-prettier": "^8.8.0",
|
|
132
|
+
"@typescript-eslint/eslint-plugin": "^6.4.0",
|
|
133
|
+
"@typescript-eslint/parser": "^6.4.0",
|
|
134
|
+
"@whatwg-node/fetch": "^0.9.9",
|
|
135
|
+
"cspell": "^7.0.0",
|
|
136
|
+
"eslint": "^8.47.0",
|
|
137
|
+
"eslint-config-prettier": "^9.0.0",
|
|
141
138
|
"express": "^4.18.2",
|
|
142
|
-
"fastify": "^4.
|
|
143
|
-
"glob": "^10.3.
|
|
144
|
-
"graphql": "^16.
|
|
139
|
+
"fastify": "^4.21.0",
|
|
140
|
+
"glob": "^10.3.3",
|
|
141
|
+
"graphql": "^16.8.0",
|
|
145
142
|
"html-validator": "^6.0.1",
|
|
146
|
-
"jest": "^29.6.1",
|
|
147
|
-
"jest-jasmine2": "^29.6.1",
|
|
148
143
|
"koa": "^2.14.2",
|
|
149
144
|
"koa-mount": "^4.0.0",
|
|
150
|
-
"node-fetch": "^3.3.
|
|
151
|
-
"prettier": "^
|
|
152
|
-
"rollup": "^3.
|
|
145
|
+
"node-fetch": "^3.3.2",
|
|
146
|
+
"prettier": "^3.0.1",
|
|
147
|
+
"rollup": "^3.28.0",
|
|
153
148
|
"rollup-plugin-gzip": "^3.1.0",
|
|
154
149
|
"semantic-release": "^21.0.7",
|
|
155
|
-
"tslib": "^2.6.
|
|
150
|
+
"tslib": "^2.6.1",
|
|
156
151
|
"tsx": "^3.12.7",
|
|
157
152
|
"typedoc": "^0.24.8",
|
|
158
|
-
"typedoc-plugin-markdown": "^3.15.
|
|
153
|
+
"typedoc-plugin-markdown": "^3.15.4",
|
|
159
154
|
"typescript": "^5.1.6",
|
|
160
|
-
"uWebSockets.js": "uNetworking/uWebSockets.js#v20.
|
|
155
|
+
"uWebSockets.js": "uNetworking/uWebSockets.js#v20.31.0",
|
|
156
|
+
"vitest": "^0.34.1"
|
|
161
157
|
}
|
|
162
158
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports'
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.graphqlHttpAudits = {}));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|