graphql-http 1.13.0 → 1.15.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 +3 -1
- package/lib/audits/index.d.mts +1 -0
- package/lib/audits/index.d.ts +1 -0
- package/lib/audits/index.js +1 -0
- package/lib/audits/index.mjs +1 -0
- package/lib/audits/render.d.mts +8 -0
- package/lib/audits/render.d.ts +8 -0
- package/lib/audits/render.js +134 -0
- package/lib/audits/render.mjs +130 -0
- package/lib/handler.d.mts +14 -1
- package/lib/handler.d.ts +14 -1
- package/lib/handler.js +9 -2
- package/lib/handler.mjs +10 -3
- package/package.json +22 -19
- package/umd/graphql-http-audits.js +1003 -0
- package/umd/graphql-http-audits.min.js +1 -0
- package/umd/graphql-http-audits.min.js.gz +0 -0
- package/umd/graphql-http.min.js.gz +0 -0
package/README.md
CHANGED
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
<h3>graphql-http</h3>
|
|
5
5
|
|
|
6
|
-
<h6>Simple, pluggable, zero-dependency, <a href="https://graphql.github.io/graphql-over-http">GraphQL over HTTP
|
|
6
|
+
<h6>Simple, pluggable, zero-dependency, <a href="https://graphql.github.io/graphql-over-http">GraphQL over HTTP spec</a> compliant server, client and audit suite.</h6>
|
|
7
7
|
|
|
8
8
|
[](https://github.com/graphql/graphql-http/actions?query=workflow%3A%22Continuous+integration%22) [](https://www.npmjs.com/package/graphql-http)
|
|
9
9
|
|
|
10
|
+
<i>Quickly check for compliance? Visit <b>[graphql-http.com](https://graphql-http.com)</b>!</i>
|
|
11
|
+
|
|
10
12
|
<i>Want a full-featured server? See the <b>[servers section](#servers)</b>!</i>
|
|
11
13
|
|
|
12
14
|
<i>Need subscriptions? Try <b>[graphql-ws](https://github.com/enisdenjo/graphql-ws)</b> or <b>[graphql-sse](https://github.com/enisdenjo/graphql-sse)</b> instead!</i>
|
package/lib/audits/index.d.mts
CHANGED
package/lib/audits/index.d.ts
CHANGED
package/lib/audits/index.js
CHANGED
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./common"), exports);
|
|
18
18
|
__exportStar(require("./server"), exports);
|
|
19
|
+
__exportStar(require("./render"), exports);
|
package/lib/audits/index.mjs
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AuditResult } from './common';
|
|
2
|
+
/**
|
|
3
|
+
* Renders the provided audit results to well-formatted and valid HTML.
|
|
4
|
+
*
|
|
5
|
+
* Do note that the rendered result is not an HTML document, it's rather
|
|
6
|
+
* just a component with results.
|
|
7
|
+
*/
|
|
8
|
+
export declare function renderAuditResultsToHTML(results: AuditResult[]): Promise<string>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AuditResult } from './common';
|
|
2
|
+
/**
|
|
3
|
+
* Renders the provided audit results to well-formatted and valid HTML.
|
|
4
|
+
*
|
|
5
|
+
* Do note that the rendered result is not an HTML document, it's rather
|
|
6
|
+
* just a component with results.
|
|
7
|
+
*/
|
|
8
|
+
export declare function renderAuditResultsToHTML(results: AuditResult[]): Promise<string>;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renderAuditResultsToHTML = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Renders the provided audit results to well-formatted and valid HTML.
|
|
6
|
+
*
|
|
7
|
+
* Do note that the rendered result is not an HTML document, it's rather
|
|
8
|
+
* just a component with results.
|
|
9
|
+
*/
|
|
10
|
+
async function renderAuditResultsToHTML(results) {
|
|
11
|
+
const grouped = {
|
|
12
|
+
total: 0,
|
|
13
|
+
ok: [],
|
|
14
|
+
warn: [],
|
|
15
|
+
error: [],
|
|
16
|
+
};
|
|
17
|
+
for (const result of results) {
|
|
18
|
+
grouped.total++;
|
|
19
|
+
if (result.status === 'ok') {
|
|
20
|
+
grouped[result.status].push(result);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
grouped[result.status].push(result);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
let report = '<i>* This report was auto-generated by graphql-http</i>\n';
|
|
27
|
+
report += '\n';
|
|
28
|
+
report += '<h1>GraphQL over HTTP audit report</h1>\n';
|
|
29
|
+
report += '\n';
|
|
30
|
+
report += '<ul>\n';
|
|
31
|
+
report += `<li><b>${grouped.total}</b> audits in total</li>\n`;
|
|
32
|
+
// font-family: monospace helps render native emojis in HTML
|
|
33
|
+
if (grouped.ok.length) {
|
|
34
|
+
report += `<li><span style="font-family: monospace">✅</span> <b>${grouped.ok.length}</b> pass</li>\n`;
|
|
35
|
+
}
|
|
36
|
+
if (grouped.warn.length) {
|
|
37
|
+
// TODO: warning sign is rendered as "⚠️" in markdown instead of the emoji
|
|
38
|
+
report += `<li><span style="font-family: monospace">⚠️</span> <b>${grouped.warn.length}</b> warnings (optional)</li>\n`;
|
|
39
|
+
}
|
|
40
|
+
if (grouped.error.length) {
|
|
41
|
+
report += `<li><span style="font-family: monospace">❌</span> <b>${grouped.error.length}</b> errors (required)</li>\n`;
|
|
42
|
+
}
|
|
43
|
+
report += '</ul>\n';
|
|
44
|
+
report += '\n';
|
|
45
|
+
if (grouped.ok.length) {
|
|
46
|
+
report += '<h2>Passing</h2>\n';
|
|
47
|
+
report += '<ol>\n';
|
|
48
|
+
for (const [, result] of grouped.ok.entries()) {
|
|
49
|
+
report += `<li><code>${result.id}</code> ${result.name}</li>\n`;
|
|
50
|
+
}
|
|
51
|
+
report += '</ol>\n';
|
|
52
|
+
report += '\n';
|
|
53
|
+
}
|
|
54
|
+
if (grouped.warn.length) {
|
|
55
|
+
report += `<h2>Warnings</h2>\n`;
|
|
56
|
+
report += 'The server <i>SHOULD</i> support these, but is not required.\n';
|
|
57
|
+
report += '<ol>\n';
|
|
58
|
+
for (const [, result] of grouped.warn.entries()) {
|
|
59
|
+
report += await printAuditFail(result);
|
|
60
|
+
}
|
|
61
|
+
report += '</ol>\n';
|
|
62
|
+
report += '\n';
|
|
63
|
+
}
|
|
64
|
+
if (grouped.error.length) {
|
|
65
|
+
report += `<h2>Errors</h2>\n`;
|
|
66
|
+
report += 'The server <b>MUST</b> support these.\n';
|
|
67
|
+
report += '<ol>\n';
|
|
68
|
+
for (const [, result] of grouped.error.entries()) {
|
|
69
|
+
report += await printAuditFail(result);
|
|
70
|
+
}
|
|
71
|
+
report += '</ol>\n';
|
|
72
|
+
}
|
|
73
|
+
return report;
|
|
74
|
+
}
|
|
75
|
+
exports.renderAuditResultsToHTML = renderAuditResultsToHTML;
|
|
76
|
+
async function printAuditFail(result) {
|
|
77
|
+
let report = '';
|
|
78
|
+
report += `<li><code>${result.id}</code> ${result.name}\n`;
|
|
79
|
+
report += '<details>\n';
|
|
80
|
+
report += `<summary>${truncate(result.reason)}</summary>\n`;
|
|
81
|
+
report += '<pre><code class="lang-json">'; // no "\n" because they count in HTML pre tags
|
|
82
|
+
const res = result.response;
|
|
83
|
+
const headers = {};
|
|
84
|
+
for (const [key, val] of res.headers.entries()) {
|
|
85
|
+
// some headers change on each run, dont report it
|
|
86
|
+
if (key === 'date') {
|
|
87
|
+
headers[key] = '<timestamp>';
|
|
88
|
+
}
|
|
89
|
+
else if (['cf-ray', 'server-timing'].includes(key)) {
|
|
90
|
+
headers[key] = '<omitted>';
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
headers[key] = val;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
let text = '', json;
|
|
97
|
+
try {
|
|
98
|
+
text = await res.text();
|
|
99
|
+
json = JSON.parse(text);
|
|
100
|
+
}
|
|
101
|
+
catch (_a) {
|
|
102
|
+
// noop
|
|
103
|
+
}
|
|
104
|
+
const stringified = JSON.stringify({
|
|
105
|
+
status: res.status,
|
|
106
|
+
statusText: res.statusText,
|
|
107
|
+
headers,
|
|
108
|
+
body: json || ((text === null || text === void 0 ? void 0 : text.length) > 5120 ? '<body is too long>' : text) || null,
|
|
109
|
+
}, (_k, v) => {
|
|
110
|
+
if (v != null && typeof v === 'object' && !Array.isArray(v)) {
|
|
111
|
+
// sort object fields for stable stringify
|
|
112
|
+
const acc = {};
|
|
113
|
+
return Object.keys(v)
|
|
114
|
+
.sort()
|
|
115
|
+
.reverse() // body on bottom
|
|
116
|
+
.reduce((acc, k) => {
|
|
117
|
+
acc[k] = v[k];
|
|
118
|
+
return acc;
|
|
119
|
+
}, acc);
|
|
120
|
+
}
|
|
121
|
+
return v;
|
|
122
|
+
}, 2);
|
|
123
|
+
report += stringified + '\n';
|
|
124
|
+
report += '</code></pre>\n';
|
|
125
|
+
report += '</details>\n';
|
|
126
|
+
report += '</li>\n';
|
|
127
|
+
return report;
|
|
128
|
+
}
|
|
129
|
+
function truncate(str, len = 1024) {
|
|
130
|
+
if (str.length > len) {
|
|
131
|
+
return str.substring(0, len) + '...';
|
|
132
|
+
}
|
|
133
|
+
return str;
|
|
134
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Renders the provided audit results to well-formatted and valid HTML.
|
|
3
|
+
*
|
|
4
|
+
* Do note that the rendered result is not an HTML document, it's rather
|
|
5
|
+
* just a component with results.
|
|
6
|
+
*/
|
|
7
|
+
export async function renderAuditResultsToHTML(results) {
|
|
8
|
+
const grouped = {
|
|
9
|
+
total: 0,
|
|
10
|
+
ok: [],
|
|
11
|
+
warn: [],
|
|
12
|
+
error: [],
|
|
13
|
+
};
|
|
14
|
+
for (const result of results) {
|
|
15
|
+
grouped.total++;
|
|
16
|
+
if (result.status === 'ok') {
|
|
17
|
+
grouped[result.status].push(result);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
grouped[result.status].push(result);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
let report = '<i>* This report was auto-generated by graphql-http</i>\n';
|
|
24
|
+
report += '\n';
|
|
25
|
+
report += '<h1>GraphQL over HTTP audit report</h1>\n';
|
|
26
|
+
report += '\n';
|
|
27
|
+
report += '<ul>\n';
|
|
28
|
+
report += `<li><b>${grouped.total}</b> audits in total</li>\n`;
|
|
29
|
+
// font-family: monospace helps render native emojis in HTML
|
|
30
|
+
if (grouped.ok.length) {
|
|
31
|
+
report += `<li><span style="font-family: monospace">✅</span> <b>${grouped.ok.length}</b> pass</li>\n`;
|
|
32
|
+
}
|
|
33
|
+
if (grouped.warn.length) {
|
|
34
|
+
// TODO: warning sign is rendered as "⚠️" in markdown instead of the emoji
|
|
35
|
+
report += `<li><span style="font-family: monospace">⚠️</span> <b>${grouped.warn.length}</b> warnings (optional)</li>\n`;
|
|
36
|
+
}
|
|
37
|
+
if (grouped.error.length) {
|
|
38
|
+
report += `<li><span style="font-family: monospace">❌</span> <b>${grouped.error.length}</b> errors (required)</li>\n`;
|
|
39
|
+
}
|
|
40
|
+
report += '</ul>\n';
|
|
41
|
+
report += '\n';
|
|
42
|
+
if (grouped.ok.length) {
|
|
43
|
+
report += '<h2>Passing</h2>\n';
|
|
44
|
+
report += '<ol>\n';
|
|
45
|
+
for (const [, result] of grouped.ok.entries()) {
|
|
46
|
+
report += `<li><code>${result.id}</code> ${result.name}</li>\n`;
|
|
47
|
+
}
|
|
48
|
+
report += '</ol>\n';
|
|
49
|
+
report += '\n';
|
|
50
|
+
}
|
|
51
|
+
if (grouped.warn.length) {
|
|
52
|
+
report += `<h2>Warnings</h2>\n`;
|
|
53
|
+
report += 'The server <i>SHOULD</i> support these, but is not required.\n';
|
|
54
|
+
report += '<ol>\n';
|
|
55
|
+
for (const [, result] of grouped.warn.entries()) {
|
|
56
|
+
report += await printAuditFail(result);
|
|
57
|
+
}
|
|
58
|
+
report += '</ol>\n';
|
|
59
|
+
report += '\n';
|
|
60
|
+
}
|
|
61
|
+
if (grouped.error.length) {
|
|
62
|
+
report += `<h2>Errors</h2>\n`;
|
|
63
|
+
report += 'The server <b>MUST</b> support these.\n';
|
|
64
|
+
report += '<ol>\n';
|
|
65
|
+
for (const [, result] of grouped.error.entries()) {
|
|
66
|
+
report += await printAuditFail(result);
|
|
67
|
+
}
|
|
68
|
+
report += '</ol>\n';
|
|
69
|
+
}
|
|
70
|
+
return report;
|
|
71
|
+
}
|
|
72
|
+
async function printAuditFail(result) {
|
|
73
|
+
let report = '';
|
|
74
|
+
report += `<li><code>${result.id}</code> ${result.name}\n`;
|
|
75
|
+
report += '<details>\n';
|
|
76
|
+
report += `<summary>${truncate(result.reason)}</summary>\n`;
|
|
77
|
+
report += '<pre><code class="lang-json">'; // no "\n" because they count in HTML pre tags
|
|
78
|
+
const res = result.response;
|
|
79
|
+
const headers = {};
|
|
80
|
+
for (const [key, val] of res.headers.entries()) {
|
|
81
|
+
// some headers change on each run, dont report it
|
|
82
|
+
if (key === 'date') {
|
|
83
|
+
headers[key] = '<timestamp>';
|
|
84
|
+
}
|
|
85
|
+
else if (['cf-ray', 'server-timing'].includes(key)) {
|
|
86
|
+
headers[key] = '<omitted>';
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
headers[key] = val;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
let text = '', json;
|
|
93
|
+
try {
|
|
94
|
+
text = await res.text();
|
|
95
|
+
json = JSON.parse(text);
|
|
96
|
+
}
|
|
97
|
+
catch (_a) {
|
|
98
|
+
// noop
|
|
99
|
+
}
|
|
100
|
+
const stringified = JSON.stringify({
|
|
101
|
+
status: res.status,
|
|
102
|
+
statusText: res.statusText,
|
|
103
|
+
headers,
|
|
104
|
+
body: json || ((text === null || text === void 0 ? void 0 : text.length) > 5120 ? '<body is too long>' : text) || null,
|
|
105
|
+
}, (_k, v) => {
|
|
106
|
+
if (v != null && typeof v === 'object' && !Array.isArray(v)) {
|
|
107
|
+
// sort object fields for stable stringify
|
|
108
|
+
const acc = {};
|
|
109
|
+
return Object.keys(v)
|
|
110
|
+
.sort()
|
|
111
|
+
.reverse() // body on bottom
|
|
112
|
+
.reduce((acc, k) => {
|
|
113
|
+
acc[k] = v[k];
|
|
114
|
+
return acc;
|
|
115
|
+
}, acc);
|
|
116
|
+
}
|
|
117
|
+
return v;
|
|
118
|
+
}, 2);
|
|
119
|
+
report += stringified + '\n';
|
|
120
|
+
report += '</code></pre>\n';
|
|
121
|
+
report += '</details>\n';
|
|
122
|
+
report += '</li>\n';
|
|
123
|
+
return report;
|
|
124
|
+
}
|
|
125
|
+
function truncate(str, len = 1024) {
|
|
126
|
+
if (str.length > len) {
|
|
127
|
+
return str.substring(0, len) + '...';
|
|
128
|
+
}
|
|
129
|
+
return str;
|
|
130
|
+
}
|
package/lib/handler.d.mts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* handler
|
|
4
4
|
*
|
|
5
5
|
*/
|
|
6
|
-
import { ExecutionArgs, ExecutionResult, GraphQLSchema, validate as graphqlValidate, execute as graphqlExecute, parse as graphqlParse, getOperationAST as graphqlGetOperationAST, GraphQLError } from 'graphql';
|
|
6
|
+
import { ExecutionArgs, ExecutionResult, GraphQLSchema, validate as graphqlValidate, ValidationRule, execute as graphqlExecute, parse as graphqlParse, getOperationAST as graphqlGetOperationAST, GraphQLError } from 'graphql';
|
|
7
7
|
import { RequestParams } from './common';
|
|
8
8
|
/**
|
|
9
9
|
* The incoming request headers the implementing server should provide.
|
|
@@ -137,6 +137,19 @@ export interface HandlerOptions<RequestRaw = unknown, RequestContext = unknown,
|
|
|
137
137
|
* Will not be used when implementing a custom `onSubscribe`.
|
|
138
138
|
*/
|
|
139
139
|
validate?: typeof graphqlValidate;
|
|
140
|
+
/**
|
|
141
|
+
* The validation rules for running GraphQL validate.
|
|
142
|
+
*
|
|
143
|
+
* When providing an array, the rules will be APPENDED to the default
|
|
144
|
+
* `specifiedRules` array provided by the graphql-js module.
|
|
145
|
+
*
|
|
146
|
+
* Alternatively, providing a function instead will OVERWRITE the defaults
|
|
147
|
+
* and use exclusively the rules returned by the function. The third (last)
|
|
148
|
+
* argument of the function are the default `specifiedRules` array provided
|
|
149
|
+
* by the graphql-js module, you're free to prepend/append the defaults to
|
|
150
|
+
* your rule set, or omit them altogether.
|
|
151
|
+
*/
|
|
152
|
+
validationRules?: readonly ValidationRule[] | ((req: Request<RequestRaw, RequestContext>, args: OperationArgs<Context>, specifiedRules: readonly ValidationRule[]) => Promise<readonly ValidationRule[]> | readonly ValidationRule[]);
|
|
140
153
|
/**
|
|
141
154
|
* Is the `execute` function from GraphQL which is
|
|
142
155
|
* used to execute the query and mutation operations.
|
package/lib/handler.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* handler
|
|
4
4
|
*
|
|
5
5
|
*/
|
|
6
|
-
import { ExecutionArgs, ExecutionResult, GraphQLSchema, validate as graphqlValidate, execute as graphqlExecute, parse as graphqlParse, getOperationAST as graphqlGetOperationAST, GraphQLError } from 'graphql';
|
|
6
|
+
import { ExecutionArgs, ExecutionResult, GraphQLSchema, validate as graphqlValidate, ValidationRule, execute as graphqlExecute, parse as graphqlParse, getOperationAST as graphqlGetOperationAST, GraphQLError } from 'graphql';
|
|
7
7
|
import { RequestParams } from './common';
|
|
8
8
|
/**
|
|
9
9
|
* The incoming request headers the implementing server should provide.
|
|
@@ -137,6 +137,19 @@ export interface HandlerOptions<RequestRaw = unknown, RequestContext = unknown,
|
|
|
137
137
|
* Will not be used when implementing a custom `onSubscribe`.
|
|
138
138
|
*/
|
|
139
139
|
validate?: typeof graphqlValidate;
|
|
140
|
+
/**
|
|
141
|
+
* The validation rules for running GraphQL validate.
|
|
142
|
+
*
|
|
143
|
+
* When providing an array, the rules will be APPENDED to the default
|
|
144
|
+
* `specifiedRules` array provided by the graphql-js module.
|
|
145
|
+
*
|
|
146
|
+
* Alternatively, providing a function instead will OVERWRITE the defaults
|
|
147
|
+
* and use exclusively the rules returned by the function. The third (last)
|
|
148
|
+
* argument of the function are the default `specifiedRules` array provided
|
|
149
|
+
* by the graphql-js module, you're free to prepend/append the defaults to
|
|
150
|
+
* your rule set, or omit them altogether.
|
|
151
|
+
*/
|
|
152
|
+
validationRules?: readonly ValidationRule[] | ((req: Request<RequestRaw, RequestContext>, args: OperationArgs<Context>, specifiedRules: readonly ValidationRule[]) => Promise<readonly ValidationRule[]> | readonly ValidationRule[]);
|
|
140
153
|
/**
|
|
141
154
|
* Is the `execute` function from GraphQL which is
|
|
142
155
|
* used to execute the query and mutation operations.
|
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, 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, } = options;
|
|
80
80
|
return async function handler(req) {
|
|
81
81
|
var _a, _b;
|
|
82
82
|
const method = req.method;
|
|
@@ -226,7 +226,14 @@ function createHandler(options) {
|
|
|
226
226
|
else {
|
|
227
227
|
args = Object.assign(Object.assign({}, argsWithoutSchema), { schema });
|
|
228
228
|
}
|
|
229
|
-
|
|
229
|
+
let rules = graphql_1.specifiedRules;
|
|
230
|
+
if (typeof validationRules === 'function') {
|
|
231
|
+
rules = await validationRules(req, args, graphql_1.specifiedRules);
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
rules = [...rules, ...validationRules];
|
|
235
|
+
}
|
|
236
|
+
const validationErrs = validate(args.schema, args.document, rules);
|
|
230
237
|
if (validationErrs.length) {
|
|
231
238
|
return makeResponse(validationErrs, acceptedMediaType);
|
|
232
239
|
}
|
package/lib/handler.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* handler
|
|
4
4
|
*
|
|
5
5
|
*/
|
|
6
|
-
import { validate as graphqlValidate, execute as graphqlExecute, parse as graphqlParse, getOperationAST as graphqlGetOperationAST, GraphQLError, } from 'graphql';
|
|
6
|
+
import { validate as graphqlValidate, specifiedRules, execute as graphqlExecute, parse as graphqlParse, getOperationAST as graphqlGetOperationAST, GraphQLError, } from 'graphql';
|
|
7
7
|
import { areGraphQLErrors, isAsyncIterable, isExecutionResult, isGraphQLError, isObject, } from './utils.mjs';
|
|
8
8
|
/**
|
|
9
9
|
* Checks whether the passed value is the `graphql-http` server agnostic response.
|
|
@@ -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, 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, } = options;
|
|
76
76
|
return async function handler(req) {
|
|
77
77
|
var _a, _b;
|
|
78
78
|
const method = req.method;
|
|
@@ -222,7 +222,14 @@ export function createHandler(options) {
|
|
|
222
222
|
else {
|
|
223
223
|
args = Object.assign(Object.assign({}, argsWithoutSchema), { schema });
|
|
224
224
|
}
|
|
225
|
-
|
|
225
|
+
let rules = specifiedRules;
|
|
226
|
+
if (typeof validationRules === 'function') {
|
|
227
|
+
rules = await validationRules(req, args, specifiedRules);
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
rules = [...rules, ...validationRules];
|
|
231
|
+
}
|
|
232
|
+
const validationErrs = validate(args.schema, args.document, rules);
|
|
226
233
|
if (validationErrs.length) {
|
|
227
234
|
return makeResponse(validationErrs, acceptedMediaType);
|
|
228
235
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphql-http",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Simple, pluggable, zero-dependency, GraphQL over HTTP
|
|
3
|
+
"version": "1.15.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",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"engines": {
|
|
25
25
|
"node": ">=12"
|
|
26
26
|
},
|
|
27
|
-
"packageManager": "yarn@3.
|
|
27
|
+
"packageManager": "yarn@3.4.1",
|
|
28
28
|
"main": "lib/index.js",
|
|
29
29
|
"module": "lib/index.mjs",
|
|
30
30
|
"browser": "umd/graphql-http.js",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
|
|
85
85
|
"build:esm": "tsc -b tsconfig.esm.json && node scripts/esm-post-process.mjs",
|
|
86
86
|
"build:cjs": "tsc -b tsconfig.cjs.json",
|
|
87
|
-
"build:umd": "rollup --
|
|
87
|
+
"build:umd": "rollup --configPlugin typescript --config rollup.config.ts",
|
|
88
88
|
"build": "yarn build:esm && yarn build:cjs && yarn build:umd",
|
|
89
89
|
"release": "semantic-release"
|
|
90
90
|
},
|
|
@@ -106,33 +106,36 @@
|
|
|
106
106
|
"@rollup/plugin-typescript": "^11.0.0",
|
|
107
107
|
"@semantic-release/changelog": "^6.0.2",
|
|
108
108
|
"@semantic-release/git": "^10.0.1",
|
|
109
|
-
"@types/eslint": "^8.
|
|
110
|
-
"@types/express": "^4.17.
|
|
109
|
+
"@types/eslint": "^8.21.0",
|
|
110
|
+
"@types/express": "^4.17.17",
|
|
111
111
|
"@types/glob": "^8.0.1",
|
|
112
|
+
"@types/html-validator": "^5.0.3",
|
|
112
113
|
"@types/jest": "^29.4.0",
|
|
113
114
|
"@types/koa": "^2.13.5",
|
|
114
115
|
"@types/koa-mount": "^4.0.2",
|
|
115
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
116
|
-
"@typescript-eslint/parser": "^5.
|
|
117
|
-
"@whatwg-node/fetch": "^0.
|
|
118
|
-
"babel-jest": "^29.4.
|
|
119
|
-
"eslint": "^8.
|
|
116
|
+
"@typescript-eslint/eslint-plugin": "^5.51.0",
|
|
117
|
+
"@typescript-eslint/parser": "^5.51.0",
|
|
118
|
+
"@whatwg-node/fetch": "^0.8.1",
|
|
119
|
+
"babel-jest": "^29.4.2",
|
|
120
|
+
"eslint": "^8.34.0",
|
|
120
121
|
"eslint-config-prettier": "^8.6.0",
|
|
121
122
|
"express": "^4.18.2",
|
|
122
|
-
"fastify": "^4.
|
|
123
|
+
"fastify": "^4.13.0",
|
|
123
124
|
"graphql": "^16.6.0",
|
|
124
|
-
"
|
|
125
|
-
"jest
|
|
125
|
+
"html-validator": "^6.0.1",
|
|
126
|
+
"jest": "^29.4.2",
|
|
127
|
+
"jest-jasmine2": "^29.4.2",
|
|
126
128
|
"koa": "^2.14.1",
|
|
127
129
|
"koa-mount": "^4.0.0",
|
|
128
130
|
"node-fetch": "^3.3.0",
|
|
129
|
-
"prettier": "^2.8.
|
|
130
|
-
"rollup": "^3.
|
|
131
|
+
"prettier": "^2.8.4",
|
|
132
|
+
"rollup": "^3.15.0",
|
|
133
|
+
"rollup-plugin-gzip": "^3.1.0",
|
|
131
134
|
"semantic-release": "^20.1.0",
|
|
132
|
-
"tslib": "^2.
|
|
133
|
-
"typedoc": "^0.23.
|
|
135
|
+
"tslib": "^2.5.0",
|
|
136
|
+
"typedoc": "^0.23.25",
|
|
134
137
|
"typedoc-plugin-markdown": "^3.14.0",
|
|
135
|
-
"typescript": "^4.9.
|
|
138
|
+
"typescript": "^4.9.5"
|
|
136
139
|
},
|
|
137
140
|
"resolutions": {
|
|
138
141
|
"npm/libnpmversion": "^3.0.6"
|