graphql-http 1.17.0 → 1.18.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 +1 -0
- package/lib/audits/common.d.mts +1 -1
- package/lib/audits/common.d.ts +1 -1
- package/lib/audits/index.d.mts +3 -3
- package/lib/audits/render.d.mts +1 -1
- package/lib/audits/render.js +15 -0
- package/lib/audits/render.mjs +15 -0
- package/lib/audits/server.d.mts +1 -1
- package/lib/audits/server.js +61 -161
- package/lib/audits/server.mjs +61 -161
- package/lib/audits/utils.d.mts +2 -2
- package/lib/audits/utils.js +6 -3
- package/lib/audits/utils.mjs +6 -3
- package/lib/client.d.mts +2 -2
- package/lib/handler.d.mts +22 -5
- package/lib/handler.d.ts +20 -3
- package/lib/handler.js +36 -14
- package/lib/handler.mjs +37 -15
- package/lib/index.d.mts +4 -4
- package/lib/use/express.d.mts +2 -2
- package/lib/use/fastify.d.mts +2 -2
- package/lib/use/fetch.d.mts +2 -2
- package/lib/use/http.d.mts +2 -2
- package/lib/use/http2.d.mts +2 -2
- package/lib/use/koa.d.mts +2 -2
- package/lib/use/node.d.mts +3 -3
- 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 +16 -15
- package/umd/graphql-http-audits.js +82 -164
- package/umd/graphql-http-audits.min.js +1 -1
- package/umd/graphql-http-audits.min.js.gz +0 -0
package/lib/handler.js
CHANGED
|
@@ -76,7 +76,7 @@ exports.isResponse = isResponse;
|
|
|
76
76
|
* @category Server
|
|
77
77
|
*/
|
|
78
78
|
function createHandler(options) {
|
|
79
|
-
const { schema, context, validate = graphql_1.validate, validationRules = [], execute = graphql_1.execute, parse = graphql_1.parse, getOperationAST = graphql_1.getOperationAST, rootValue, onSubscribe, onOperation, } = options;
|
|
79
|
+
const { schema, context, validate = graphql_1.validate, validationRules = [], execute = graphql_1.execute, parse = graphql_1.parse, getOperationAST = graphql_1.getOperationAST, rootValue, onSubscribe, onOperation, formatError = (err) => err, } = options;
|
|
80
80
|
return async function handler(req) {
|
|
81
81
|
var _a, _b;
|
|
82
82
|
const method = req.method;
|
|
@@ -177,6 +177,10 @@ function createHandler(options) {
|
|
|
177
177
|
Array.isArray(partParams.variables))) {
|
|
178
178
|
throw new Error('Invalid variables');
|
|
179
179
|
}
|
|
180
|
+
if (partParams.operationName != null &&
|
|
181
|
+
typeof partParams.operationName !== 'string') {
|
|
182
|
+
throw new Error('Invalid operationName');
|
|
183
|
+
}
|
|
180
184
|
if (partParams.extensions != null &&
|
|
181
185
|
(typeof partParams.extensions !== 'object' ||
|
|
182
186
|
Array.isArray(partParams.extensions))) {
|
|
@@ -186,7 +190,7 @@ function createHandler(options) {
|
|
|
186
190
|
params = partParams;
|
|
187
191
|
}
|
|
188
192
|
catch (err) {
|
|
189
|
-
return makeResponse(
|
|
193
|
+
return makeResponse(err, acceptedMediaType, formatError);
|
|
190
194
|
}
|
|
191
195
|
let args;
|
|
192
196
|
const maybeResErrsOrArgs = await (onSubscribe === null || onSubscribe === void 0 ? void 0 : onSubscribe(req, params));
|
|
@@ -194,7 +198,7 @@ function createHandler(options) {
|
|
|
194
198
|
return maybeResErrsOrArgs;
|
|
195
199
|
else if ((0, utils_1.isExecutionResult)(maybeResErrsOrArgs) ||
|
|
196
200
|
(0, utils_1.areGraphQLErrors)(maybeResErrsOrArgs))
|
|
197
|
-
return makeResponse(maybeResErrsOrArgs, acceptedMediaType);
|
|
201
|
+
return makeResponse(maybeResErrsOrArgs, acceptedMediaType, formatError);
|
|
198
202
|
else if (maybeResErrsOrArgs)
|
|
199
203
|
args = maybeResErrsOrArgs;
|
|
200
204
|
else {
|
|
@@ -206,7 +210,7 @@ function createHandler(options) {
|
|
|
206
210
|
document = parse(query);
|
|
207
211
|
}
|
|
208
212
|
catch (err) {
|
|
209
|
-
return makeResponse(err, acceptedMediaType);
|
|
213
|
+
return makeResponse(err, acceptedMediaType, formatError);
|
|
210
214
|
}
|
|
211
215
|
const resOrContext = typeof context === 'function' ? await context(req, params) : context;
|
|
212
216
|
if (isResponse(resOrContext))
|
|
@@ -235,7 +239,7 @@ function createHandler(options) {
|
|
|
235
239
|
}
|
|
236
240
|
const validationErrs = validate(args.schema, args.document, rules);
|
|
237
241
|
if (validationErrs.length) {
|
|
238
|
-
return makeResponse(validationErrs, acceptedMediaType);
|
|
242
|
+
return makeResponse(validationErrs, acceptedMediaType, formatError);
|
|
239
243
|
}
|
|
240
244
|
}
|
|
241
245
|
let operation;
|
|
@@ -246,10 +250,10 @@ function createHandler(options) {
|
|
|
246
250
|
operation = ast.operation;
|
|
247
251
|
}
|
|
248
252
|
catch (_d) {
|
|
249
|
-
return makeResponse(new graphql_1.GraphQLError('Unable to detect operation AST'), acceptedMediaType);
|
|
253
|
+
return makeResponse(new graphql_1.GraphQLError('Unable to detect operation AST'), acceptedMediaType, formatError);
|
|
250
254
|
}
|
|
251
255
|
if (operation === 'subscription') {
|
|
252
|
-
return makeResponse(new graphql_1.GraphQLError('Subscriptions are not supported'), acceptedMediaType);
|
|
256
|
+
return makeResponse(new graphql_1.GraphQLError('Subscriptions are not supported'), acceptedMediaType, formatError);
|
|
253
257
|
}
|
|
254
258
|
// mutations cannot happen over GETs
|
|
255
259
|
// https://graphql.github.io/graphql-over-http/draft/#sel-CALFJRPAAELBAAxwP
|
|
@@ -283,9 +287,9 @@ function createHandler(options) {
|
|
|
283
287
|
else if (maybeResponseOrResult)
|
|
284
288
|
result = maybeResponseOrResult;
|
|
285
289
|
if ((0, utils_1.isAsyncIterable)(result)) {
|
|
286
|
-
return makeResponse(new graphql_1.GraphQLError('Subscriptions are not supported'), acceptedMediaType);
|
|
290
|
+
return makeResponse(new graphql_1.GraphQLError('Subscriptions are not supported'), acceptedMediaType, formatError);
|
|
287
291
|
}
|
|
288
|
-
return makeResponse(result, acceptedMediaType);
|
|
292
|
+
return makeResponse(result, acceptedMediaType, formatError);
|
|
289
293
|
};
|
|
290
294
|
}
|
|
291
295
|
exports.createHandler = createHandler;
|
|
@@ -327,12 +331,29 @@ exports.getAcceptableMediaType = getAcceptableMediaType;
|
|
|
327
331
|
*
|
|
328
332
|
* If the first argument is an `ExecutionResult`, the operation will be treated as "successful".
|
|
329
333
|
*
|
|
330
|
-
* If the first argument is
|
|
331
|
-
*
|
|
334
|
+
* If the first argument is (an array of) `GraphQLError`, or an `ExecutionResult` without the `data` field, it will be treated
|
|
335
|
+
* the response will be constructed with the help of `acceptedMediaType` complying with the GraphQL over HTTP spec.
|
|
336
|
+
*
|
|
337
|
+
* If the first argument is an `Error`, the operation will be treated as a bad request responding with `400: Bad Request` and the
|
|
338
|
+
* error will be present in the `ExecutionResult` style.
|
|
332
339
|
*
|
|
333
340
|
* @category Server
|
|
334
341
|
*/
|
|
335
|
-
function makeResponse(resultOrErrors, acceptedMediaType) {
|
|
342
|
+
function makeResponse(resultOrErrors, acceptedMediaType, formatError) {
|
|
343
|
+
if (resultOrErrors instanceof Error &&
|
|
344
|
+
// because GraphQLError extends the Error class
|
|
345
|
+
!(0, utils_1.isGraphQLError)(resultOrErrors)) {
|
|
346
|
+
return [
|
|
347
|
+
JSON.stringify({ errors: [formatError(resultOrErrors)] }, utils_1.jsonErrorReplacer),
|
|
348
|
+
{
|
|
349
|
+
status: 400,
|
|
350
|
+
statusText: 'Bad Request',
|
|
351
|
+
headers: {
|
|
352
|
+
'content-type': 'application/json; charset=utf-8',
|
|
353
|
+
},
|
|
354
|
+
},
|
|
355
|
+
];
|
|
356
|
+
}
|
|
336
357
|
const errors = (0, utils_1.isGraphQLError)(resultOrErrors)
|
|
337
358
|
? [resultOrErrors]
|
|
338
359
|
: (0, utils_1.areGraphQLErrors)(resultOrErrors)
|
|
@@ -340,7 +361,7 @@ function makeResponse(resultOrErrors, acceptedMediaType) {
|
|
|
340
361
|
: null;
|
|
341
362
|
if (errors) {
|
|
342
363
|
return [
|
|
343
|
-
JSON.stringify({ errors }),
|
|
364
|
+
JSON.stringify({ errors: errors.map(formatError) }, utils_1.jsonErrorReplacer),
|
|
344
365
|
Object.assign(Object.assign({}, (acceptedMediaType === 'application/json'
|
|
345
366
|
? {
|
|
346
367
|
status: 200,
|
|
@@ -357,7 +378,8 @@ function makeResponse(resultOrErrors, acceptedMediaType) {
|
|
|
357
378
|
];
|
|
358
379
|
}
|
|
359
380
|
return [
|
|
360
|
-
JSON.stringify(resultOrErrors
|
|
381
|
+
JSON.stringify('errors' in resultOrErrors && resultOrErrors.errors
|
|
382
|
+
? Object.assign(Object.assign({}, resultOrErrors), { errors: resultOrErrors.errors.map(formatError) }) : resultOrErrors, utils_1.jsonErrorReplacer),
|
|
361
383
|
{
|
|
362
384
|
status: 200,
|
|
363
385
|
statusText: 'OK',
|
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/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './common';
|
|
2
|
-
export * from './handler';
|
|
3
|
-
export * from './client';
|
|
4
|
-
export * from './audits';
|
|
1
|
+
export * from './common.mjs';
|
|
2
|
+
export * from './handler.mjs';
|
|
3
|
+
export * from './client.mjs';
|
|
4
|
+
export * from './audits/index.mjs';
|
package/lib/use/express.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Request, Response, Handler } from 'express';
|
|
2
|
-
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
|
|
2
|
+
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler.mjs';
|
|
3
3
|
/**
|
|
4
4
|
* The context in the request for the handler.
|
|
5
5
|
*
|
|
@@ -21,7 +21,7 @@ export type HandlerOptions<Context extends OperationContext = undefined> = RawHa
|
|
|
21
21
|
* ```js
|
|
22
22
|
* import express from 'express'; // yarn add express
|
|
23
23
|
* import { createHandler } from 'graphql-http/lib/use/express';
|
|
24
|
-
* import { schema } from './my-graphql-schema';
|
|
24
|
+
* import { schema } from './my-graphql-schema/index.mjs';
|
|
25
25
|
*
|
|
26
26
|
* const app = express();
|
|
27
27
|
* app.all('/graphql', createHandler({ schema }));
|
package/lib/use/fastify.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FastifyRequest, FastifyReply, RouteHandler } from 'fastify';
|
|
2
|
-
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
|
|
2
|
+
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler.mjs';
|
|
3
3
|
/**
|
|
4
4
|
* The context in the request for the handler.
|
|
5
5
|
*
|
|
@@ -21,7 +21,7 @@ export type HandlerOptions<Context extends OperationContext = undefined> = RawHa
|
|
|
21
21
|
* ```js
|
|
22
22
|
* import Fastify from 'fastify'; // yarn add fastify
|
|
23
23
|
* import { createHandler } from 'graphql-http/lib/use/express';
|
|
24
|
-
* import { schema } from './my-graphql-schema';
|
|
24
|
+
* import { schema } from './my-graphql-schema/index.mjs';
|
|
25
25
|
*
|
|
26
26
|
* const fastify = Fastify();
|
|
27
27
|
* fastify.all('/graphql', createHandler({ schema }));
|
package/lib/use/fetch.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
|
|
1
|
+
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler.mjs';
|
|
2
2
|
/**
|
|
3
3
|
* The necessary API from the fetch environment for the handler.
|
|
4
4
|
*
|
|
@@ -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-step';
|
|
29
|
+
* import { schema } from './my-graphql-step/index.mjs';
|
|
30
30
|
*
|
|
31
31
|
* // Use this adapter in _any_ environment.
|
|
32
32
|
* const adapter = createServerAdapter({
|
package/lib/use/http.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { IncomingMessage, ServerResponse } from 'http';
|
|
3
|
-
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
|
|
3
|
+
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler.mjs';
|
|
4
4
|
/**
|
|
5
5
|
* The context in the request for the handler.
|
|
6
6
|
*
|
|
@@ -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-step';
|
|
25
|
+
* import { schema } from './my-graphql-step/index.mjs';
|
|
26
26
|
*
|
|
27
27
|
* const server = http.createServer(createHandler({ schema }));
|
|
28
28
|
*
|
package/lib/use/http2.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { Http2ServerRequest, Http2ServerResponse } from 'http2';
|
|
3
|
-
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
|
|
3
|
+
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler.mjs';
|
|
4
4
|
/**
|
|
5
5
|
* The context in the request for the handler.
|
|
6
6
|
*
|
|
@@ -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-step';
|
|
31
|
+
* import { schema } from './my-graphql-step/index.mjs';
|
|
32
32
|
*
|
|
33
33
|
* const server = http2.createSecureServer(
|
|
34
34
|
* {
|
package/lib/use/koa.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { Middleware, Response } from 'koa';
|
|
3
3
|
import type { IncomingMessage } from 'http';
|
|
4
|
-
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
|
|
4
|
+
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler.mjs';
|
|
5
5
|
/**
|
|
6
6
|
* The context in the request for the handler.
|
|
7
7
|
*
|
|
@@ -24,7 +24,7 @@ export type HandlerOptions<Context extends OperationContext = undefined> = RawHa
|
|
|
24
24
|
* import Koa from 'koa'; // yarn add koa
|
|
25
25
|
* import mount from 'koa-mount'; // yarn add koa-mount
|
|
26
26
|
* import { createHandler } from 'graphql-http/lib/use/koa';
|
|
27
|
-
* import { schema } from './my-graphql-schema';
|
|
27
|
+
* import { schema } from './my-graphql-schema/index.mjs';
|
|
28
28
|
*
|
|
29
29
|
* const app = new Koa();
|
|
30
30
|
* app.use(mount('/', createHandler({ schema })));
|
package/lib/use/node.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { HandlerOptions as HttpHandlerOptions } from './http';
|
|
3
|
-
import { OperationContext } from '../handler';
|
|
2
|
+
import { HandlerOptions as HttpHandlerOptions } from './http.mjs';
|
|
3
|
+
import { OperationContext } from '../handler.mjs';
|
|
4
4
|
/**
|
|
5
5
|
* Handler options when using the node adapter.
|
|
6
6
|
*
|
|
@@ -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-step';
|
|
19
|
+
* import { schema } from './my-graphql-step/index.mjs';
|
|
20
20
|
*
|
|
21
21
|
* const server = http.createServer(createHandler({ schema }));
|
|
22
22
|
*
|
package/lib/utils.d.mts
CHANGED
|
@@ -17,3 +17,5 @@ export declare function isGraphQLError(obj: unknown): obj is GraphQLError;
|
|
|
17
17
|
export declare function isExecutionResult(val: unknown): val is ExecutionResult;
|
|
18
18
|
/** @private */
|
|
19
19
|
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
|
@@ -17,3 +17,5 @@ export declare function isGraphQLError(obj: unknown): obj is GraphQLError;
|
|
|
17
17
|
export declare function isExecutionResult(val: unknown): val is ExecutionResult;
|
|
18
18
|
/** @private */
|
|
19
19
|
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,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.isAsyncIterable = exports.isExecutionResult = exports.isGraphQLError = exports.areGraphQLErrors = exports.isObject = exports.extendedTypeof = void 0;
|
|
8
|
+
exports.jsonErrorReplacer = exports.isAsyncIterable = exports.isExecutionResult = exports.isGraphQLError = exports.areGraphQLErrors = exports.isObject = exports.extendedTypeof = void 0;
|
|
9
9
|
const graphql_1 = require("graphql");
|
|
10
10
|
/** @private */
|
|
11
11
|
function extendedTypeof(val) {
|
|
@@ -47,3 +47,17 @@ function isAsyncIterable(val) {
|
|
|
47
47
|
return typeof Object(val)[Symbol.asyncIterator] === 'function';
|
|
48
48
|
}
|
|
49
49
|
exports.isAsyncIterable = isAsyncIterable;
|
|
50
|
+
/** @private */
|
|
51
|
+
function jsonErrorReplacer(_key, val) {
|
|
52
|
+
if (val instanceof Error &&
|
|
53
|
+
// GraphQL errors implement their own stringer
|
|
54
|
+
!isGraphQLError(val)) {
|
|
55
|
+
return {
|
|
56
|
+
// name: val.name, name is included in message
|
|
57
|
+
message: val.message,
|
|
58
|
+
// stack: val.stack, can leak sensitive details
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return val;
|
|
62
|
+
}
|
|
63
|
+
exports.jsonErrorReplacer = jsonErrorReplacer;
|
package/lib/utils.mjs
CHANGED
|
@@ -38,3 +38,16 @@ export function isExecutionResult(val) {
|
|
|
38
38
|
export function isAsyncIterable(val) {
|
|
39
39
|
return typeof Object(val)[Symbol.asyncIterator] === 'function';
|
|
40
40
|
}
|
|
41
|
+
/** @private */
|
|
42
|
+
export function jsonErrorReplacer(_key, val) {
|
|
43
|
+
if (val instanceof Error &&
|
|
44
|
+
// GraphQL errors implement their own stringer
|
|
45
|
+
!isGraphQLError(val)) {
|
|
46
|
+
return {
|
|
47
|
+
// name: val.name, name is included in message
|
|
48
|
+
message: val.message,
|
|
49
|
+
// stack: val.stack, can leak sensitive details
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return val;
|
|
53
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphql-http",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.18.0",
|
|
4
4
|
"description": "Simple, pluggable, zero-dependency, GraphQL over HTTP spec compliant server, client and audit suite.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphql",
|
|
@@ -106,47 +106,48 @@
|
|
|
106
106
|
"graphql": ">=0.11 <=16"
|
|
107
107
|
},
|
|
108
108
|
"devDependencies": {
|
|
109
|
-
"@babel/core": "^7.21.
|
|
109
|
+
"@babel/core": "^7.21.4",
|
|
110
110
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
111
111
|
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
|
|
112
112
|
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
|
|
113
113
|
"@babel/plugin-proposal-optional-chaining": "^7.21.0",
|
|
114
|
-
"@babel/preset-env": "^7.
|
|
115
|
-
"@babel/preset-typescript": "^7.21.
|
|
116
|
-
"@rollup/plugin-terser": "^0.4.
|
|
117
|
-
"@rollup/plugin-typescript": "^11.
|
|
114
|
+
"@babel/preset-env": "^7.21.4",
|
|
115
|
+
"@babel/preset-typescript": "^7.21.4",
|
|
116
|
+
"@rollup/plugin-terser": "^0.4.1",
|
|
117
|
+
"@rollup/plugin-typescript": "^11.1.0",
|
|
118
118
|
"@semantic-release/changelog": "^6.0.3",
|
|
119
119
|
"@semantic-release/git": "^10.0.1",
|
|
120
|
-
"@types/eslint": "^8.
|
|
120
|
+
"@types/eslint": "^8.37.0",
|
|
121
121
|
"@types/express": "^4.17.17",
|
|
122
122
|
"@types/glob": "^8.1.0",
|
|
123
123
|
"@types/html-validator": "^5.0.3",
|
|
124
124
|
"@types/jest": "^29.5.0",
|
|
125
125
|
"@types/koa": "^2.13.6",
|
|
126
126
|
"@types/koa-mount": "^4.0.2",
|
|
127
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
128
|
-
"@typescript-eslint/parser": "^5.
|
|
127
|
+
"@typescript-eslint/eslint-plugin": "^5.58.0",
|
|
128
|
+
"@typescript-eslint/parser": "^5.58.0",
|
|
129
129
|
"@whatwg-node/fetch": "^0.8.4",
|
|
130
130
|
"babel-jest": "^29.5.0",
|
|
131
|
-
"eslint": "^8.
|
|
131
|
+
"eslint": "^8.38.0",
|
|
132
132
|
"eslint-config-prettier": "^8.8.0",
|
|
133
133
|
"express": "^4.18.2",
|
|
134
134
|
"fastify": "^4.15.0",
|
|
135
|
+
"glob": "^10.0.0",
|
|
135
136
|
"graphql": "^16.6.0",
|
|
136
137
|
"html-validator": "^6.0.1",
|
|
137
138
|
"jest": "^29.5.0",
|
|
138
139
|
"jest-jasmine2": "^29.5.0",
|
|
139
|
-
"koa": "^2.14.
|
|
140
|
+
"koa": "^2.14.2",
|
|
140
141
|
"koa-mount": "^4.0.0",
|
|
141
142
|
"node-fetch": "^3.3.1",
|
|
142
143
|
"prettier": "^2.8.7",
|
|
143
144
|
"rollup": "^3.20.2",
|
|
144
145
|
"rollup-plugin-gzip": "^3.1.0",
|
|
145
|
-
"semantic-release": "^21.0.
|
|
146
|
+
"semantic-release": "^21.0.1",
|
|
146
147
|
"tslib": "^2.5.0",
|
|
147
|
-
"typedoc": "^0.
|
|
148
|
-
"typedoc-plugin-markdown": "^3.
|
|
149
|
-
"typescript": "^5.0.
|
|
148
|
+
"typedoc": "^0.24.1",
|
|
149
|
+
"typedoc-plugin-markdown": "^3.15.1",
|
|
150
|
+
"typescript": "^5.0.4"
|
|
150
151
|
},
|
|
151
152
|
"resolutions": {
|
|
152
153
|
"npm/libnpmversion": "^3.0.6"
|