graphql-http 1.17.1 → 1.19.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 +17 -1
- package/lib/audits/common.d.mts +1 -1
- package/lib/audits/common.d.ts +1 -1
- package/lib/audits/render.js +15 -0
- package/lib/audits/render.mjs +15 -0
- package/lib/audits/server.js +42 -172
- package/lib/audits/server.mjs +42 -172
- package/lib/audits/utils.js +6 -3
- package/lib/audits/utils.mjs +6 -3
- package/lib/handler.d.mts +20 -3
- package/lib/handler.d.ts +20 -3
- package/lib/handler.js +36 -14
- package/lib/handler.mjs +37 -15
- 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.d.mts +2 -0
- package/lib/utils.d.ts +2 -0
- package/lib/utils.js +15 -1
- package/lib/utils.mjs +13 -0
- package/package.json +30 -25
- package/umd/graphql-http-audits.js +63 -175
- package/umd/graphql-http-audits.min.js +1 -1
- package/umd/graphql-http-audits.min.js.gz +0 -0
package/lib/handler.mjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
*/
|
|
6
6
|
import { validate as graphqlValidate, specifiedRules, execute as graphqlExecute, parse as graphqlParse, getOperationAST as graphqlGetOperationAST, GraphQLError, } from 'graphql';
|
|
7
|
-
import { areGraphQLErrors, isAsyncIterable, isExecutionResult, isGraphQLError, isObject, } from './utils.mjs';
|
|
7
|
+
import { areGraphQLErrors, isAsyncIterable, isExecutionResult, isGraphQLError, isObject, jsonErrorReplacer, } from './utils.mjs';
|
|
8
8
|
/**
|
|
9
9
|
* Checks whether the passed value is the `graphql-http` server agnostic response.
|
|
10
10
|
*
|
|
@@ -72,7 +72,7 @@ export function isResponse(val) {
|
|
|
72
72
|
* @category Server
|
|
73
73
|
*/
|
|
74
74
|
export function createHandler(options) {
|
|
75
|
-
const { schema, context, validate = graphqlValidate, validationRules = [], execute = graphqlExecute, parse = graphqlParse, getOperationAST = graphqlGetOperationAST, rootValue, onSubscribe, onOperation, } = options;
|
|
75
|
+
const { schema, context, validate = graphqlValidate, validationRules = [], execute = graphqlExecute, parse = graphqlParse, getOperationAST = graphqlGetOperationAST, rootValue, onSubscribe, onOperation, formatError = (err) => err, } = options;
|
|
76
76
|
return async function handler(req) {
|
|
77
77
|
var _a, _b;
|
|
78
78
|
const method = req.method;
|
|
@@ -173,6 +173,10 @@ export function createHandler(options) {
|
|
|
173
173
|
Array.isArray(partParams.variables))) {
|
|
174
174
|
throw new Error('Invalid variables');
|
|
175
175
|
}
|
|
176
|
+
if (partParams.operationName != null &&
|
|
177
|
+
typeof partParams.operationName !== 'string') {
|
|
178
|
+
throw new Error('Invalid operationName');
|
|
179
|
+
}
|
|
176
180
|
if (partParams.extensions != null &&
|
|
177
181
|
(typeof partParams.extensions !== 'object' ||
|
|
178
182
|
Array.isArray(partParams.extensions))) {
|
|
@@ -182,7 +186,7 @@ export function createHandler(options) {
|
|
|
182
186
|
params = partParams;
|
|
183
187
|
}
|
|
184
188
|
catch (err) {
|
|
185
|
-
return makeResponse(
|
|
189
|
+
return makeResponse(err, acceptedMediaType, formatError);
|
|
186
190
|
}
|
|
187
191
|
let args;
|
|
188
192
|
const maybeResErrsOrArgs = await (onSubscribe === null || onSubscribe === void 0 ? void 0 : onSubscribe(req, params));
|
|
@@ -190,7 +194,7 @@ export function createHandler(options) {
|
|
|
190
194
|
return maybeResErrsOrArgs;
|
|
191
195
|
else if (isExecutionResult(maybeResErrsOrArgs) ||
|
|
192
196
|
areGraphQLErrors(maybeResErrsOrArgs))
|
|
193
|
-
return makeResponse(maybeResErrsOrArgs, acceptedMediaType);
|
|
197
|
+
return makeResponse(maybeResErrsOrArgs, acceptedMediaType, formatError);
|
|
194
198
|
else if (maybeResErrsOrArgs)
|
|
195
199
|
args = maybeResErrsOrArgs;
|
|
196
200
|
else {
|
|
@@ -202,7 +206,7 @@ export function createHandler(options) {
|
|
|
202
206
|
document = parse(query);
|
|
203
207
|
}
|
|
204
208
|
catch (err) {
|
|
205
|
-
return makeResponse(err, acceptedMediaType);
|
|
209
|
+
return makeResponse(err, acceptedMediaType, formatError);
|
|
206
210
|
}
|
|
207
211
|
const resOrContext = typeof context === 'function' ? await context(req, params) : context;
|
|
208
212
|
if (isResponse(resOrContext))
|
|
@@ -231,7 +235,7 @@ export function createHandler(options) {
|
|
|
231
235
|
}
|
|
232
236
|
const validationErrs = validate(args.schema, args.document, rules);
|
|
233
237
|
if (validationErrs.length) {
|
|
234
|
-
return makeResponse(validationErrs, acceptedMediaType);
|
|
238
|
+
return makeResponse(validationErrs, acceptedMediaType, formatError);
|
|
235
239
|
}
|
|
236
240
|
}
|
|
237
241
|
let operation;
|
|
@@ -242,10 +246,10 @@ export function createHandler(options) {
|
|
|
242
246
|
operation = ast.operation;
|
|
243
247
|
}
|
|
244
248
|
catch (_d) {
|
|
245
|
-
return makeResponse(new GraphQLError('Unable to detect operation AST'), acceptedMediaType);
|
|
249
|
+
return makeResponse(new GraphQLError('Unable to detect operation AST'), acceptedMediaType, formatError);
|
|
246
250
|
}
|
|
247
251
|
if (operation === 'subscription') {
|
|
248
|
-
return makeResponse(new GraphQLError('Subscriptions are not supported'), acceptedMediaType);
|
|
252
|
+
return makeResponse(new GraphQLError('Subscriptions are not supported'), acceptedMediaType, formatError);
|
|
249
253
|
}
|
|
250
254
|
// mutations cannot happen over GETs
|
|
251
255
|
// https://graphql.github.io/graphql-over-http/draft/#sel-CALFJRPAAELBAAxwP
|
|
@@ -279,9 +283,9 @@ export function createHandler(options) {
|
|
|
279
283
|
else if (maybeResponseOrResult)
|
|
280
284
|
result = maybeResponseOrResult;
|
|
281
285
|
if (isAsyncIterable(result)) {
|
|
282
|
-
return makeResponse(new GraphQLError('Subscriptions are not supported'), acceptedMediaType);
|
|
286
|
+
return makeResponse(new GraphQLError('Subscriptions are not supported'), acceptedMediaType, formatError);
|
|
283
287
|
}
|
|
284
|
-
return makeResponse(result, acceptedMediaType);
|
|
288
|
+
return makeResponse(result, acceptedMediaType, formatError);
|
|
285
289
|
};
|
|
286
290
|
}
|
|
287
291
|
/**
|
|
@@ -321,12 +325,29 @@ export function getAcceptableMediaType(acceptHeader) {
|
|
|
321
325
|
*
|
|
322
326
|
* If the first argument is an `ExecutionResult`, the operation will be treated as "successful".
|
|
323
327
|
*
|
|
324
|
-
* If the first argument is
|
|
325
|
-
*
|
|
328
|
+
* If the first argument is (an array of) `GraphQLError`, or an `ExecutionResult` without the `data` field, it will be treated
|
|
329
|
+
* the response will be constructed with the help of `acceptedMediaType` complying with the GraphQL over HTTP spec.
|
|
330
|
+
*
|
|
331
|
+
* If the first argument is an `Error`, the operation will be treated as a bad request responding with `400: Bad Request` and the
|
|
332
|
+
* error will be present in the `ExecutionResult` style.
|
|
326
333
|
*
|
|
327
334
|
* @category Server
|
|
328
335
|
*/
|
|
329
|
-
export function makeResponse(resultOrErrors, acceptedMediaType) {
|
|
336
|
+
export function makeResponse(resultOrErrors, acceptedMediaType, formatError) {
|
|
337
|
+
if (resultOrErrors instanceof Error &&
|
|
338
|
+
// because GraphQLError extends the Error class
|
|
339
|
+
!isGraphQLError(resultOrErrors)) {
|
|
340
|
+
return [
|
|
341
|
+
JSON.stringify({ errors: [formatError(resultOrErrors)] }, jsonErrorReplacer),
|
|
342
|
+
{
|
|
343
|
+
status: 400,
|
|
344
|
+
statusText: 'Bad Request',
|
|
345
|
+
headers: {
|
|
346
|
+
'content-type': 'application/json; charset=utf-8',
|
|
347
|
+
},
|
|
348
|
+
},
|
|
349
|
+
];
|
|
350
|
+
}
|
|
330
351
|
const errors = isGraphQLError(resultOrErrors)
|
|
331
352
|
? [resultOrErrors]
|
|
332
353
|
: areGraphQLErrors(resultOrErrors)
|
|
@@ -334,7 +355,7 @@ export function makeResponse(resultOrErrors, acceptedMediaType) {
|
|
|
334
355
|
: null;
|
|
335
356
|
if (errors) {
|
|
336
357
|
return [
|
|
337
|
-
JSON.stringify({ errors }),
|
|
358
|
+
JSON.stringify({ errors: errors.map(formatError) }, jsonErrorReplacer),
|
|
338
359
|
Object.assign(Object.assign({}, (acceptedMediaType === 'application/json'
|
|
339
360
|
? {
|
|
340
361
|
status: 200,
|
|
@@ -351,7 +372,8 @@ export function makeResponse(resultOrErrors, acceptedMediaType) {
|
|
|
351
372
|
];
|
|
352
373
|
}
|
|
353
374
|
return [
|
|
354
|
-
JSON.stringify(resultOrErrors
|
|
375
|
+
JSON.stringify('errors' in resultOrErrors && resultOrErrors.errors
|
|
376
|
+
? Object.assign(Object.assign({}, resultOrErrors), { errors: resultOrErrors.errors.map(formatError) }) : resultOrErrors, jsonErrorReplacer),
|
|
355
377
|
{
|
|
356
378
|
status: 200,
|
|
357
379
|
statusText: 'OK',
|
package/lib/use/express.js
CHANGED
|
@@ -21,7 +21,6 @@ const handler_1 = require("../handler");
|
|
|
21
21
|
* @category Server/express
|
|
22
22
|
*/
|
|
23
23
|
function createHandler(options) {
|
|
24
|
-
const isProd = process.env.NODE_ENV === 'production';
|
|
25
24
|
const handle = (0, handler_1.createHandler)(options);
|
|
26
25
|
return async function requestListener(req, res) {
|
|
27
26
|
try {
|
|
@@ -50,23 +49,7 @@ function createHandler(options) {
|
|
|
50
49
|
// If you wish to handle them differently, consider implementing your own request handler.
|
|
51
50
|
console.error('Internal error occurred during request handling. ' +
|
|
52
51
|
'Please check your implementation.', err);
|
|
53
|
-
|
|
54
|
-
res.writeHead(500).end();
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
res
|
|
58
|
-
.writeHead(500, { 'content-type': 'application/json; charset=utf-8' })
|
|
59
|
-
.end(JSON.stringify({
|
|
60
|
-
errors: [
|
|
61
|
-
err instanceof Error
|
|
62
|
-
? {
|
|
63
|
-
message: err.message,
|
|
64
|
-
stack: err.stack,
|
|
65
|
-
}
|
|
66
|
-
: err,
|
|
67
|
-
],
|
|
68
|
-
}));
|
|
69
|
-
}
|
|
52
|
+
res.writeHead(500).end();
|
|
70
53
|
}
|
|
71
54
|
};
|
|
72
55
|
}
|
package/lib/use/express.mjs
CHANGED
|
@@ -18,7 +18,6 @@ import { createHandler as createRawHandler, } from '../handler.mjs';
|
|
|
18
18
|
* @category Server/express
|
|
19
19
|
*/
|
|
20
20
|
export function createHandler(options) {
|
|
21
|
-
const isProd = process.env.NODE_ENV === 'production';
|
|
22
21
|
const handle = createRawHandler(options);
|
|
23
22
|
return async function requestListener(req, res) {
|
|
24
23
|
try {
|
|
@@ -47,23 +46,7 @@ export function createHandler(options) {
|
|
|
47
46
|
// If you wish to handle them differently, consider implementing your own request handler.
|
|
48
47
|
console.error('Internal error occurred during request handling. ' +
|
|
49
48
|
'Please check your implementation.', err);
|
|
50
|
-
|
|
51
|
-
res.writeHead(500).end();
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
res
|
|
55
|
-
.writeHead(500, { 'content-type': 'application/json; charset=utf-8' })
|
|
56
|
-
.end(JSON.stringify({
|
|
57
|
-
errors: [
|
|
58
|
-
err instanceof Error
|
|
59
|
-
? {
|
|
60
|
-
message: err.message,
|
|
61
|
-
stack: err.stack,
|
|
62
|
-
}
|
|
63
|
-
: err,
|
|
64
|
-
],
|
|
65
|
-
}));
|
|
66
|
-
}
|
|
49
|
+
res.writeHead(500).end();
|
|
67
50
|
}
|
|
68
51
|
};
|
|
69
52
|
}
|
package/lib/use/fastify.js
CHANGED
|
@@ -21,7 +21,6 @@ const handler_1 = require("../handler");
|
|
|
21
21
|
* @category Server/fastify
|
|
22
22
|
*/
|
|
23
23
|
function createHandler(options) {
|
|
24
|
-
const isProd = process.env.NODE_ENV === 'production';
|
|
25
24
|
const handle = (0, handler_1.createHandler)(options);
|
|
26
25
|
return async function requestListener(req, reply) {
|
|
27
26
|
try {
|
|
@@ -45,24 +44,7 @@ function createHandler(options) {
|
|
|
45
44
|
// If you wish to handle them differently, consider implementing your own request handler.
|
|
46
45
|
console.error('Internal error occurred during request handling. ' +
|
|
47
46
|
'Please check your implementation.', err);
|
|
48
|
-
|
|
49
|
-
reply.status(500).send();
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
reply
|
|
53
|
-
.status(500)
|
|
54
|
-
.header('content-type', 'application/json; charset=utf-8')
|
|
55
|
-
.send({
|
|
56
|
-
errors: [
|
|
57
|
-
err instanceof Error
|
|
58
|
-
? {
|
|
59
|
-
message: err.message,
|
|
60
|
-
stack: err.stack,
|
|
61
|
-
}
|
|
62
|
-
: err,
|
|
63
|
-
],
|
|
64
|
-
});
|
|
65
|
-
}
|
|
47
|
+
reply.status(500).send();
|
|
66
48
|
}
|
|
67
49
|
};
|
|
68
50
|
}
|
package/lib/use/fastify.mjs
CHANGED
|
@@ -18,7 +18,6 @@ import { createHandler as createRawHandler, } from '../handler.mjs';
|
|
|
18
18
|
* @category Server/fastify
|
|
19
19
|
*/
|
|
20
20
|
export function createHandler(options) {
|
|
21
|
-
const isProd = process.env.NODE_ENV === 'production';
|
|
22
21
|
const handle = createRawHandler(options);
|
|
23
22
|
return async function requestListener(req, reply) {
|
|
24
23
|
try {
|
|
@@ -42,24 +41,7 @@ export function createHandler(options) {
|
|
|
42
41
|
// If you wish to handle them differently, consider implementing your own request handler.
|
|
43
42
|
console.error('Internal error occurred during request handling. ' +
|
|
44
43
|
'Please check your implementation.', err);
|
|
45
|
-
|
|
46
|
-
reply.status(500).send();
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
reply
|
|
50
|
-
.status(500)
|
|
51
|
-
.header('content-type', 'application/json; charset=utf-8')
|
|
52
|
-
.send({
|
|
53
|
-
errors: [
|
|
54
|
-
err instanceof Error
|
|
55
|
-
? {
|
|
56
|
-
message: err.message,
|
|
57
|
-
stack: err.stack,
|
|
58
|
-
}
|
|
59
|
-
: err,
|
|
60
|
-
],
|
|
61
|
-
});
|
|
62
|
-
}
|
|
44
|
+
reply.status(500).send();
|
|
63
45
|
}
|
|
64
46
|
};
|
|
65
47
|
}
|
package/lib/use/fetch.d.mts
CHANGED
|
@@ -26,7 +26,7 @@ export type HandlerOptions<Context extends OperationContext = undefined> = RawHa
|
|
|
26
26
|
* import http from 'http';
|
|
27
27
|
* import { createServerAdapter } from '@whatwg-node/server'; // yarn add @whatwg-node/server
|
|
28
28
|
* import { createHandler } from 'graphql-http/lib/use/fetch';
|
|
29
|
-
* import { schema } from './my-graphql-
|
|
29
|
+
* import { schema } from './my-graphql-schema/index.mjs';
|
|
30
30
|
*
|
|
31
31
|
* // Use this adapter in _any_ environment.
|
|
32
32
|
* const adapter = createServerAdapter({
|
package/lib/use/fetch.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export type HandlerOptions<Context extends OperationContext = undefined> = RawHa
|
|
|
26
26
|
* import http from 'http';
|
|
27
27
|
* import { createServerAdapter } from '@whatwg-node/server'; // yarn add @whatwg-node/server
|
|
28
28
|
* import { createHandler } from 'graphql-http/lib/use/fetch';
|
|
29
|
-
* import { schema } from './my-graphql-
|
|
29
|
+
* import { schema } from './my-graphql-schema';
|
|
30
30
|
*
|
|
31
31
|
* // Use this adapter in _any_ environment.
|
|
32
32
|
* const adapter = createServerAdapter({
|
package/lib/use/fetch.js
CHANGED
|
@@ -13,7 +13,7 @@ const handler_1 = require("../handler");
|
|
|
13
13
|
* import http from 'http';
|
|
14
14
|
* import { createServerAdapter } from '@whatwg-node/server'; // yarn add @whatwg-node/server
|
|
15
15
|
* import { createHandler } from 'graphql-http/lib/use/fetch';
|
|
16
|
-
* import { schema } from './my-graphql-
|
|
16
|
+
* import { schema } from './my-graphql-schema';
|
|
17
17
|
*
|
|
18
18
|
* // Use this adapter in _any_ environment.
|
|
19
19
|
* const adapter = createServerAdapter({
|
|
@@ -31,7 +31,6 @@ const handler_1 = require("../handler");
|
|
|
31
31
|
* @category Server/fetch
|
|
32
32
|
*/
|
|
33
33
|
function createHandler(options, reqCtx = {}) {
|
|
34
|
-
const isProd = process.env.NODE_ENV === 'production';
|
|
35
34
|
const api = {
|
|
36
35
|
Response: reqCtx.Response || Response,
|
|
37
36
|
TextEncoder: reqCtx.TextEncoder || TextEncoder,
|
|
@@ -55,26 +54,7 @@ function createHandler(options, reqCtx = {}) {
|
|
|
55
54
|
// If you wish to handle them differently, consider implementing your own request handler.
|
|
56
55
|
console.error('Internal error occurred during request handling. ' +
|
|
57
56
|
'Please check your implementation.', err);
|
|
58
|
-
|
|
59
|
-
return new api.Response(null, { status: 500 });
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
return new api.Response(JSON.stringify({
|
|
63
|
-
errors: [
|
|
64
|
-
err instanceof Error
|
|
65
|
-
? {
|
|
66
|
-
message: err.message,
|
|
67
|
-
stack: err.stack,
|
|
68
|
-
}
|
|
69
|
-
: err,
|
|
70
|
-
],
|
|
71
|
-
}), {
|
|
72
|
-
status: 500,
|
|
73
|
-
headers: {
|
|
74
|
-
'content-type': 'application/json; charset=utf-8',
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
}
|
|
57
|
+
return new api.Response(null, { status: 500 });
|
|
78
58
|
}
|
|
79
59
|
};
|
|
80
60
|
}
|
package/lib/use/fetch.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import { createHandler as createRawHandler, } from '../handler.mjs';
|
|
|
10
10
|
* import http from 'http';
|
|
11
11
|
* import { createServerAdapter } from '@whatwg-node/server'; // yarn add @whatwg-node/server
|
|
12
12
|
* import { createHandler } from 'graphql-http/lib/use/fetch';
|
|
13
|
-
* import { schema } from './my-graphql-
|
|
13
|
+
* import { schema } from './my-graphql-schema/index.mjs';
|
|
14
14
|
*
|
|
15
15
|
* // Use this adapter in _any_ environment.
|
|
16
16
|
* const adapter = createServerAdapter({
|
|
@@ -28,7 +28,6 @@ import { createHandler as createRawHandler, } from '../handler.mjs';
|
|
|
28
28
|
* @category Server/fetch
|
|
29
29
|
*/
|
|
30
30
|
export function createHandler(options, reqCtx = {}) {
|
|
31
|
-
const isProd = process.env.NODE_ENV === 'production';
|
|
32
31
|
const api = {
|
|
33
32
|
Response: reqCtx.Response || Response,
|
|
34
33
|
TextEncoder: reqCtx.TextEncoder || TextEncoder,
|
|
@@ -52,26 +51,7 @@ export function createHandler(options, reqCtx = {}) {
|
|
|
52
51
|
// If you wish to handle them differently, consider implementing your own request handler.
|
|
53
52
|
console.error('Internal error occurred during request handling. ' +
|
|
54
53
|
'Please check your implementation.', err);
|
|
55
|
-
|
|
56
|
-
return new api.Response(null, { status: 500 });
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
return new api.Response(JSON.stringify({
|
|
60
|
-
errors: [
|
|
61
|
-
err instanceof Error
|
|
62
|
-
? {
|
|
63
|
-
message: err.message,
|
|
64
|
-
stack: err.stack,
|
|
65
|
-
}
|
|
66
|
-
: err,
|
|
67
|
-
],
|
|
68
|
-
}), {
|
|
69
|
-
status: 500,
|
|
70
|
-
headers: {
|
|
71
|
-
'content-type': 'application/json; charset=utf-8',
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
}
|
|
54
|
+
return new api.Response(null, { status: 500 });
|
|
75
55
|
}
|
|
76
56
|
};
|
|
77
57
|
}
|
package/lib/use/http.d.mts
CHANGED
|
@@ -22,7 +22,7 @@ export type HandlerOptions<Context extends OperationContext = undefined> = RawHa
|
|
|
22
22
|
* ```js
|
|
23
23
|
* import http from 'http';
|
|
24
24
|
* import { createHandler } from 'graphql-http/lib/use/http';
|
|
25
|
-
* import { schema } from './my-graphql-
|
|
25
|
+
* import { schema } from './my-graphql-schema/index.mjs';
|
|
26
26
|
*
|
|
27
27
|
* const server = http.createServer(createHandler({ schema }));
|
|
28
28
|
*
|
package/lib/use/http.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export type HandlerOptions<Context extends OperationContext = undefined> = RawHa
|
|
|
22
22
|
* ```js
|
|
23
23
|
* import http from 'http';
|
|
24
24
|
* import { createHandler } from 'graphql-http/lib/use/http';
|
|
25
|
-
* import { schema } from './my-graphql-
|
|
25
|
+
* import { schema } from './my-graphql-schema';
|
|
26
26
|
*
|
|
27
27
|
* const server = http.createServer(createHandler({ schema }));
|
|
28
28
|
*
|
package/lib/use/http.js
CHANGED
|
@@ -9,7 +9,7 @@ const handler_1 = require("../handler");
|
|
|
9
9
|
* ```js
|
|
10
10
|
* import http from 'http';
|
|
11
11
|
* import { createHandler } from 'graphql-http/lib/use/http';
|
|
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
|
*
|
|
@@ -20,7 +20,6 @@ const handler_1 = require("../handler");
|
|
|
20
20
|
* @category Server/http
|
|
21
21
|
*/
|
|
22
22
|
function createHandler(options) {
|
|
23
|
-
const isProd = process.env.NODE_ENV === 'production';
|
|
24
23
|
const handle = (0, handler_1.createHandler)(options);
|
|
25
24
|
return async function requestListener(req, res) {
|
|
26
25
|
try {
|
|
@@ -49,23 +48,7 @@ function createHandler(options) {
|
|
|
49
48
|
// If you wish to handle them differently, consider implementing your own request handler.
|
|
50
49
|
console.error('Internal error occurred during request handling. ' +
|
|
51
50
|
'Please check your implementation.', err);
|
|
52
|
-
|
|
53
|
-
res.writeHead(500).end();
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
res
|
|
57
|
-
.writeHead(500, { 'content-type': 'application/json; charset=utf-8' })
|
|
58
|
-
.end(JSON.stringify({
|
|
59
|
-
errors: [
|
|
60
|
-
err instanceof Error
|
|
61
|
-
? {
|
|
62
|
-
message: err.message,
|
|
63
|
-
stack: err.stack,
|
|
64
|
-
}
|
|
65
|
-
: err,
|
|
66
|
-
],
|
|
67
|
-
}));
|
|
68
|
-
}
|
|
51
|
+
res.writeHead(500).end();
|
|
69
52
|
}
|
|
70
53
|
};
|
|
71
54
|
}
|
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
|
*
|