graphql-http 1.14.0 → 1.16.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.
Files changed (48) hide show
  1. package/README.md +5 -3
  2. package/lib/audits/index.d.mts +1 -0
  3. package/lib/audits/index.d.ts +1 -0
  4. package/lib/audits/index.js +1 -0
  5. package/lib/audits/index.mjs +1 -0
  6. package/lib/audits/render.d.mts +8 -0
  7. package/lib/audits/render.d.ts +8 -0
  8. package/lib/audits/render.js +134 -0
  9. package/lib/audits/render.mjs +130 -0
  10. package/lib/audits/utils.js +6 -3
  11. package/lib/audits/utils.mjs +6 -3
  12. package/lib/handler.d.mts +3 -3
  13. package/lib/handler.d.ts +3 -3
  14. package/lib/handler.js +3 -3
  15. package/lib/handler.mjs +3 -3
  16. package/lib/use/express.d.mts +9 -3
  17. package/lib/use/express.d.ts +9 -3
  18. package/lib/use/express.js +1 -1
  19. package/lib/use/express.mjs +1 -1
  20. package/lib/use/fastify.d.mts +9 -3
  21. package/lib/use/fastify.d.ts +9 -3
  22. package/lib/use/fastify.js +1 -1
  23. package/lib/use/fastify.mjs +1 -1
  24. package/lib/use/fetch.d.mts +10 -4
  25. package/lib/use/fetch.d.ts +10 -4
  26. package/lib/use/fetch.js +6 -6
  27. package/lib/use/fetch.mjs +6 -6
  28. package/lib/use/http.d.mts +27 -0
  29. package/lib/use/http.d.ts +27 -0
  30. package/lib/use/http.js +72 -0
  31. package/lib/use/http.mjs +68 -0
  32. package/lib/use/http2.d.mts +39 -0
  33. package/lib/use/http2.d.ts +39 -0
  34. package/lib/use/http2.js +90 -0
  35. package/lib/use/http2.mjs +86 -0
  36. package/lib/use/koa.d.mts +9 -3
  37. package/lib/use/koa.d.ts +9 -3
  38. package/lib/use/koa.js +1 -1
  39. package/lib/use/koa.mjs +1 -1
  40. package/lib/use/node.d.mts +14 -4
  41. package/lib/use/node.d.ts +14 -4
  42. package/lib/use/node.js +5 -50
  43. package/lib/use/node.mjs +5 -50
  44. package/package.json +22 -9
  45. package/umd/graphql-http-audits.js +1006 -0
  46. package/umd/graphql-http-audits.min.js +1 -0
  47. package/umd/graphql-http-audits.min.js.gz +0 -0
  48. package/umd/graphql-http.min.js.gz +0 -0
@@ -1,8 +1,16 @@
1
1
  /// <reference types="node" />
2
- import type { IncomingMessage, RequestListener } from 'http';
3
- import { HandlerOptions, OperationContext } from '../handler';
2
+ import { HandlerOptions as HttpHandlerOptions } from './http';
3
+ import { OperationContext } from '../handler';
4
4
  /**
5
- * Create a GraphQL over HTTP Protocol compliant request handler for
5
+ * Handler options when using the node adapter.
6
+ *
7
+ * @category Server/node
8
+ *
9
+ * @deprecated Please use {@link use/http.HandlerOptions | http} or {@link use/http2.HandlerOptions | http2} adapters instead.
10
+ */
11
+ export type HandlerOptions<Context extends OperationContext = undefined> = HttpHandlerOptions<Context>;
12
+ /**
13
+ * Create a GraphQL over HTTP spec compliant request handler for
6
14
  * the Node environment.
7
15
  *
8
16
  * ```js
@@ -17,5 +25,7 @@ import { HandlerOptions, OperationContext } from '../handler';
17
25
  * ```
18
26
  *
19
27
  * @category Server/node
28
+ *
29
+ * @deprecated Please use {@link use/http.createHandler | http} or {@link use/http2.createHandler | http2} adapters instead.
20
30
  */
21
- export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<IncomingMessage, undefined, Context>): RequestListener;
31
+ export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<Context>): (req: import("http").IncomingMessage, res: import("http").ServerResponse<import("http").IncomingMessage>) => Promise<void>;
package/lib/use/node.d.ts CHANGED
@@ -1,8 +1,16 @@
1
1
  /// <reference types="node" />
2
- import type { IncomingMessage, RequestListener } from 'http';
3
- import { HandlerOptions, OperationContext } from '../handler';
2
+ import { HandlerOptions as HttpHandlerOptions } from './http';
3
+ import { OperationContext } from '../handler';
4
4
  /**
5
- * Create a GraphQL over HTTP Protocol compliant request handler for
5
+ * Handler options when using the node adapter.
6
+ *
7
+ * @category Server/node
8
+ *
9
+ * @deprecated Please use {@link use/http.HandlerOptions | http} or {@link use/http2.HandlerOptions | http2} adapters instead.
10
+ */
11
+ export type HandlerOptions<Context extends OperationContext = undefined> = HttpHandlerOptions<Context>;
12
+ /**
13
+ * Create a GraphQL over HTTP spec compliant request handler for
6
14
  * the Node environment.
7
15
  *
8
16
  * ```js
@@ -17,5 +25,7 @@ import { HandlerOptions, OperationContext } from '../handler';
17
25
  * ```
18
26
  *
19
27
  * @category Server/node
28
+ *
29
+ * @deprecated Please use {@link use/http.createHandler | http} or {@link use/http2.createHandler | http2} adapters instead.
20
30
  */
21
- export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<IncomingMessage, undefined, Context>): RequestListener;
31
+ export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<Context>): (req: import("http").IncomingMessage, res: import("http").ServerResponse<import("http").IncomingMessage>) => Promise<void>;
package/lib/use/node.js CHANGED
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createHandler = void 0;
4
- const handler_1 = require("../handler");
4
+ const http_1 = require("./http");
5
5
  /**
6
- * Create a GraphQL over HTTP Protocol compliant request handler for
6
+ * Create a GraphQL over HTTP spec compliant request handler for
7
7
  * the Node environment.
8
8
  *
9
9
  * ```js
@@ -18,55 +18,10 @@ const handler_1 = require("../handler");
18
18
  * ```
19
19
  *
20
20
  * @category Server/node
21
+ *
22
+ * @deprecated Please use {@link use/http.createHandler | http} or {@link use/http2.createHandler | http2} adapters instead.
21
23
  */
22
24
  function createHandler(options) {
23
- const isProd = process.env.NODE_ENV === 'production';
24
- const handle = (0, handler_1.createHandler)(options);
25
- return async function requestListener(req, res) {
26
- try {
27
- if (!req.url) {
28
- throw new Error('Missing request URL');
29
- }
30
- if (!req.method) {
31
- throw new Error('Missing request method');
32
- }
33
- const [body, init] = await handle({
34
- url: req.url,
35
- method: req.method,
36
- headers: req.headers,
37
- body: () => new Promise((resolve) => {
38
- let body = '';
39
- req.on('data', (chunk) => (body += chunk));
40
- req.on('end', () => resolve(body));
41
- }),
42
- raw: req,
43
- context: undefined,
44
- });
45
- res.writeHead(init.status, init.statusText, init.headers).end(body);
46
- }
47
- catch (err) {
48
- // The handler shouldnt throw errors.
49
- // If you wish to handle them differently, consider implementing your own request handler.
50
- console.error('Internal error occurred during request handling. ' +
51
- 'Please check your implementation.', err);
52
- if (isProd) {
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
- }
69
- }
70
- };
25
+ return (0, http_1.createHandler)(options);
71
26
  }
72
27
  exports.createHandler = createHandler;
package/lib/use/node.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { createHandler as createRawHandler, } from '../handler.mjs';
1
+ import { createHandler as httpCreateHandler, } from './http.mjs';
2
2
  /**
3
- * Create a GraphQL over HTTP Protocol compliant request handler for
3
+ * Create a GraphQL over HTTP spec compliant request handler for
4
4
  * the Node environment.
5
5
  *
6
6
  * ```js
@@ -15,54 +15,9 @@ import { createHandler as createRawHandler, } from '../handler.mjs';
15
15
  * ```
16
16
  *
17
17
  * @category Server/node
18
+ *
19
+ * @deprecated Please use {@link use/http.createHandler | http} or {@link use/http2.createHandler | http2} adapters instead.
18
20
  */
19
21
  export function createHandler(options) {
20
- const isProd = process.env.NODE_ENV === 'production';
21
- const handle = createRawHandler(options);
22
- return async function requestListener(req, res) {
23
- try {
24
- if (!req.url) {
25
- throw new Error('Missing request URL');
26
- }
27
- if (!req.method) {
28
- throw new Error('Missing request method');
29
- }
30
- const [body, init] = await handle({
31
- url: req.url,
32
- method: req.method,
33
- headers: req.headers,
34
- body: () => new Promise((resolve) => {
35
- let body = '';
36
- req.on('data', (chunk) => (body += chunk));
37
- req.on('end', () => resolve(body));
38
- }),
39
- raw: req,
40
- context: undefined,
41
- });
42
- res.writeHead(init.status, init.statusText, init.headers).end(body);
43
- }
44
- catch (err) {
45
- // The handler shouldnt throw errors.
46
- // If you wish to handle them differently, consider implementing your own request handler.
47
- console.error('Internal error occurred during request handling. ' +
48
- 'Please check your implementation.', err);
49
- if (isProd) {
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
- }
66
- }
67
- };
22
+ return httpCreateHandler(options);
68
23
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "graphql-http",
3
- "version": "1.14.0",
4
- "description": "Simple, pluggable, zero-dependency, GraphQL over HTTP Protocol compliant server and client",
3
+ "version": "1.16.0",
4
+ "description": "Simple, pluggable, zero-dependency, GraphQL over HTTP spec compliant server, client and audit suite.",
5
5
  "keywords": [
6
6
  "graphql",
7
7
  "client",
@@ -45,6 +45,16 @@
45
45
  "require": "./lib/use/node.js",
46
46
  "import": "./lib/use/node.mjs"
47
47
  },
48
+ "./lib/use/http": {
49
+ "types": "./lib/use/http.d.ts",
50
+ "require": "./lib/use/http.js",
51
+ "import": "./lib/use/http.mjs"
52
+ },
53
+ "./lib/use/http2": {
54
+ "types": "./lib/use/http2.d.ts",
55
+ "require": "./lib/use/http2.js",
56
+ "import": "./lib/use/http2.mjs"
57
+ },
48
58
  "./lib/use/express": {
49
59
  "types": "./lib/use/express.d.ts",
50
60
  "require": "./lib/use/express.js",
@@ -81,10 +91,10 @@
81
91
  "lint:prettier": "prettier -c .",
82
92
  "lint": "yarn lint:eslint && yarn lint:prettier",
83
93
  "type-check": "tsc --noEmit",
84
- "test": "NODE_OPTIONS=--experimental-vm-modules jest",
94
+ "test": "NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 jest",
85
95
  "build:esm": "tsc -b tsconfig.esm.json && node scripts/esm-post-process.mjs",
86
96
  "build:cjs": "tsc -b tsconfig.cjs.json",
87
- "build:umd": "rollup --bundleConfigAsCjs --config rollup.config.ts --configPlugin typescript && gzip umd/graphql-http.min.js -c > umd/graphql-http.min.js.gz",
97
+ "build:umd": "rollup --configPlugin typescript --config rollup.config.ts",
88
98
  "build": "yarn build:esm && yarn build:cjs && yarn build:umd",
89
99
  "release": "semantic-release"
90
100
  },
@@ -109,28 +119,31 @@
109
119
  "@types/eslint": "^8.21.0",
110
120
  "@types/express": "^4.17.17",
111
121
  "@types/glob": "^8.0.1",
122
+ "@types/html-validator": "^5.0.3",
112
123
  "@types/jest": "^29.4.0",
113
124
  "@types/koa": "^2.13.5",
114
125
  "@types/koa-mount": "^4.0.2",
115
126
  "@typescript-eslint/eslint-plugin": "^5.51.0",
116
127
  "@typescript-eslint/parser": "^5.51.0",
117
- "@whatwg-node/fetch": "^0.7.0",
128
+ "@whatwg-node/fetch": "^0.8.1",
118
129
  "babel-jest": "^29.4.2",
119
- "eslint": "^8.33.0",
130
+ "eslint": "^8.34.0",
120
131
  "eslint-config-prettier": "^8.6.0",
121
132
  "express": "^4.18.2",
122
- "fastify": "^4.12.0",
133
+ "fastify": "^4.13.0",
123
134
  "graphql": "^16.6.0",
135
+ "html-validator": "^6.0.1",
124
136
  "jest": "^29.4.2",
125
137
  "jest-jasmine2": "^29.4.2",
126
138
  "koa": "^2.14.1",
127
139
  "koa-mount": "^4.0.0",
128
140
  "node-fetch": "^3.3.0",
129
141
  "prettier": "^2.8.4",
130
- "rollup": "^3.14.0",
142
+ "rollup": "^3.15.0",
143
+ "rollup-plugin-gzip": "^3.1.0",
131
144
  "semantic-release": "^20.1.0",
132
145
  "tslib": "^2.5.0",
133
- "typedoc": "^0.23.24",
146
+ "typedoc": "^0.23.25",
134
147
  "typedoc-plugin-markdown": "^3.14.0",
135
148
  "typescript": "^4.9.5"
136
149
  },