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.
- package/README.md +5 -3
- 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/audits/utils.js +6 -3
- package/lib/audits/utils.mjs +6 -3
- package/lib/handler.d.mts +3 -3
- package/lib/handler.d.ts +3 -3
- package/lib/handler.js +3 -3
- package/lib/handler.mjs +3 -3
- package/lib/use/express.d.mts +9 -3
- package/lib/use/express.d.ts +9 -3
- package/lib/use/express.js +1 -1
- package/lib/use/express.mjs +1 -1
- package/lib/use/fastify.d.mts +9 -3
- package/lib/use/fastify.d.ts +9 -3
- package/lib/use/fastify.js +1 -1
- package/lib/use/fastify.mjs +1 -1
- package/lib/use/fetch.d.mts +10 -4
- package/lib/use/fetch.d.ts +10 -4
- package/lib/use/fetch.js +6 -6
- package/lib/use/fetch.mjs +6 -6
- package/lib/use/http.d.mts +27 -0
- package/lib/use/http.d.ts +27 -0
- package/lib/use/http.js +72 -0
- package/lib/use/http.mjs +68 -0
- package/lib/use/http2.d.mts +39 -0
- package/lib/use/http2.d.ts +39 -0
- package/lib/use/http2.js +90 -0
- package/lib/use/http2.mjs +86 -0
- package/lib/use/koa.d.mts +9 -3
- package/lib/use/koa.d.ts +9 -3
- package/lib/use/koa.js +1 -1
- package/lib/use/koa.mjs +1 -1
- package/lib/use/node.d.mts +14 -4
- package/lib/use/node.d.ts +14 -4
- package/lib/use/node.js +5 -50
- package/lib/use/node.mjs +5 -50
- package/package.json +22 -9
- package/umd/graphql-http-audits.js +1006 -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>
|
|
@@ -53,7 +55,7 @@ const schema = new GraphQLSchema({
|
|
|
53
55
|
|
|
54
56
|
```js
|
|
55
57
|
import http from 'http';
|
|
56
|
-
import { createHandler } from 'graphql-http/lib/use/
|
|
58
|
+
import { createHandler } from 'graphql-http/lib/use/http';
|
|
57
59
|
import { schema } from './previous-step';
|
|
58
60
|
|
|
59
61
|
// Create the GraphQL over HTTP Node request handler
|
|
@@ -84,7 +86,7 @@ $ openssl req -x509 -newkey rsa:2048 -nodes -sha256 -subj '/CN=localhost' \
|
|
|
84
86
|
```js
|
|
85
87
|
import fs from 'fs';
|
|
86
88
|
import http2 from 'http2';
|
|
87
|
-
import { createHandler } from 'graphql-http/lib/use/
|
|
89
|
+
import { createHandler } from 'graphql-http/lib/use/http2';
|
|
88
90
|
import { schema } from './previous-step';
|
|
89
91
|
|
|
90
92
|
// Create the GraphQL over HTTP Node request handler
|
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/audits/utils.js
CHANGED
|
@@ -114,22 +114,25 @@ function ressert(res) {
|
|
|
114
114
|
bodyAsExecutionResult: {
|
|
115
115
|
data: {
|
|
116
116
|
async toBe(val) {
|
|
117
|
+
const clonedRes = res.clone(); // allow the body to be re-read
|
|
117
118
|
const body = await assertBodyAsExecutionResult(res);
|
|
118
119
|
if (body.data !== val) {
|
|
119
|
-
throw new AuditError(
|
|
120
|
+
throw new AuditError(clonedRes, `Response body execution result data is not "${val}"`);
|
|
120
121
|
}
|
|
121
122
|
},
|
|
122
123
|
},
|
|
123
124
|
async toHaveProperty(key) {
|
|
125
|
+
const clonedRes = res.clone(); // allow the body to be re-read
|
|
124
126
|
const body = await assertBodyAsExecutionResult(res);
|
|
125
127
|
if (!(key in body)) {
|
|
126
|
-
throw new AuditError(
|
|
128
|
+
throw new AuditError(clonedRes, `Response body execution result does not have a property "${key}"`);
|
|
127
129
|
}
|
|
128
130
|
},
|
|
129
131
|
async notToHaveProperty(key) {
|
|
132
|
+
const clonedRes = res.clone(); // allow the body to be re-read
|
|
130
133
|
const body = await assertBodyAsExecutionResult(res);
|
|
131
134
|
if (key in body) {
|
|
132
|
-
throw new AuditError(
|
|
135
|
+
throw new AuditError(clonedRes, `Response body execution result has a property "${key}"`);
|
|
133
136
|
}
|
|
134
137
|
},
|
|
135
138
|
},
|
package/lib/audits/utils.mjs
CHANGED
|
@@ -95,22 +95,25 @@ export function ressert(res) {
|
|
|
95
95
|
bodyAsExecutionResult: {
|
|
96
96
|
data: {
|
|
97
97
|
async toBe(val) {
|
|
98
|
+
const clonedRes = res.clone(); // allow the body to be re-read
|
|
98
99
|
const body = await assertBodyAsExecutionResult(res);
|
|
99
100
|
if (body.data !== val) {
|
|
100
|
-
throw new AuditError(
|
|
101
|
+
throw new AuditError(clonedRes, `Response body execution result data is not "${val}"`);
|
|
101
102
|
}
|
|
102
103
|
},
|
|
103
104
|
},
|
|
104
105
|
async toHaveProperty(key) {
|
|
106
|
+
const clonedRes = res.clone(); // allow the body to be re-read
|
|
105
107
|
const body = await assertBodyAsExecutionResult(res);
|
|
106
108
|
if (!(key in body)) {
|
|
107
|
-
throw new AuditError(
|
|
109
|
+
throw new AuditError(clonedRes, `Response body execution result does not have a property "${key}"`);
|
|
108
110
|
}
|
|
109
111
|
},
|
|
110
112
|
async notToHaveProperty(key) {
|
|
113
|
+
const clonedRes = res.clone(); // allow the body to be re-read
|
|
111
114
|
const body = await assertBodyAsExecutionResult(res);
|
|
112
115
|
if (key in body) {
|
|
113
|
-
throw new AuditError(
|
|
116
|
+
throw new AuditError(clonedRes, `Response body execution result has a property "${key}"`);
|
|
114
117
|
}
|
|
115
118
|
},
|
|
116
119
|
},
|
package/lib/handler.d.mts
CHANGED
|
@@ -228,7 +228,7 @@ export interface HandlerOptions<RequestRaw = unknown, RequestContext = unknown,
|
|
|
228
228
|
*/
|
|
229
229
|
export type Handler<RequestRaw = unknown, RequestContext = unknown> = (req: Request<RequestRaw, RequestContext>) => Promise<Response>;
|
|
230
230
|
/**
|
|
231
|
-
* Makes a GraphQL over HTTP
|
|
231
|
+
* Makes a GraphQL over HTTP spec compliant server handler. The handler can
|
|
232
232
|
* be used with your favourite server library.
|
|
233
233
|
*
|
|
234
234
|
* Beware that the handler resolves only after the whole operation completes.
|
|
@@ -291,7 +291,7 @@ export declare function createHandler<RequestRaw = unknown, RequestContext = unk
|
|
|
291
291
|
export type AcceptableMediaType = 'application/graphql-response+json' | 'application/json';
|
|
292
292
|
/**
|
|
293
293
|
* Inspects the request and detects the appropriate/acceptable Media-Type
|
|
294
|
-
* looking at the `Accept` header while complying with the GraphQL over HTTP
|
|
294
|
+
* looking at the `Accept` header while complying with the GraphQL over HTTP spec.
|
|
295
295
|
*
|
|
296
296
|
* @category Server
|
|
297
297
|
*/
|
|
@@ -302,7 +302,7 @@ export declare function getAcceptableMediaType(acceptHeader: string | null | und
|
|
|
302
302
|
* If the first argument is an `ExecutionResult`, the operation will be treated as "successful".
|
|
303
303
|
*
|
|
304
304
|
* If the first argument is _any_ object without the `data` field, it will be treated as an error (as per the spec)
|
|
305
|
-
* and the response will be constructed with the help of `acceptedMediaType` complying with the GraphQL over HTTP
|
|
305
|
+
* and the response will be constructed with the help of `acceptedMediaType` complying with the GraphQL over HTTP spec.
|
|
306
306
|
*
|
|
307
307
|
* @category Server
|
|
308
308
|
*/
|
package/lib/handler.d.ts
CHANGED
|
@@ -228,7 +228,7 @@ export interface HandlerOptions<RequestRaw = unknown, RequestContext = unknown,
|
|
|
228
228
|
*/
|
|
229
229
|
export type Handler<RequestRaw = unknown, RequestContext = unknown> = (req: Request<RequestRaw, RequestContext>) => Promise<Response>;
|
|
230
230
|
/**
|
|
231
|
-
* Makes a GraphQL over HTTP
|
|
231
|
+
* Makes a GraphQL over HTTP spec compliant server handler. The handler can
|
|
232
232
|
* be used with your favourite server library.
|
|
233
233
|
*
|
|
234
234
|
* Beware that the handler resolves only after the whole operation completes.
|
|
@@ -291,7 +291,7 @@ export declare function createHandler<RequestRaw = unknown, RequestContext = unk
|
|
|
291
291
|
export type AcceptableMediaType = 'application/graphql-response+json' | 'application/json';
|
|
292
292
|
/**
|
|
293
293
|
* Inspects the request and detects the appropriate/acceptable Media-Type
|
|
294
|
-
* looking at the `Accept` header while complying with the GraphQL over HTTP
|
|
294
|
+
* looking at the `Accept` header while complying with the GraphQL over HTTP spec.
|
|
295
295
|
*
|
|
296
296
|
* @category Server
|
|
297
297
|
*/
|
|
@@ -302,7 +302,7 @@ export declare function getAcceptableMediaType(acceptHeader: string | null | und
|
|
|
302
302
|
* If the first argument is an `ExecutionResult`, the operation will be treated as "successful".
|
|
303
303
|
*
|
|
304
304
|
* If the first argument is _any_ object without the `data` field, it will be treated as an error (as per the spec)
|
|
305
|
-
* and the response will be constructed with the help of `acceptedMediaType` complying with the GraphQL over HTTP
|
|
305
|
+
* and the response will be constructed with the help of `acceptedMediaType` complying with the GraphQL over HTTP spec.
|
|
306
306
|
*
|
|
307
307
|
* @category Server
|
|
308
308
|
*/
|
package/lib/handler.js
CHANGED
|
@@ -21,7 +21,7 @@ function isResponse(val) {
|
|
|
21
21
|
}
|
|
22
22
|
exports.isResponse = isResponse;
|
|
23
23
|
/**
|
|
24
|
-
* Makes a GraphQL over HTTP
|
|
24
|
+
* Makes a GraphQL over HTTP spec compliant server handler. The handler can
|
|
25
25
|
* be used with your favourite server library.
|
|
26
26
|
*
|
|
27
27
|
* Beware that the handler resolves only after the whole operation completes.
|
|
@@ -291,7 +291,7 @@ function createHandler(options) {
|
|
|
291
291
|
exports.createHandler = createHandler;
|
|
292
292
|
/**
|
|
293
293
|
* Inspects the request and detects the appropriate/acceptable Media-Type
|
|
294
|
-
* looking at the `Accept` header while complying with the GraphQL over HTTP
|
|
294
|
+
* looking at the `Accept` header while complying with the GraphQL over HTTP spec.
|
|
295
295
|
*
|
|
296
296
|
* @category Server
|
|
297
297
|
*/
|
|
@@ -328,7 +328,7 @@ exports.getAcceptableMediaType = getAcceptableMediaType;
|
|
|
328
328
|
* If the first argument is an `ExecutionResult`, the operation will be treated as "successful".
|
|
329
329
|
*
|
|
330
330
|
* If the first argument is _any_ object without the `data` field, it will be treated as an error (as per the spec)
|
|
331
|
-
* and the response will be constructed with the help of `acceptedMediaType` complying with the GraphQL over HTTP
|
|
331
|
+
* and the response will be constructed with the help of `acceptedMediaType` complying with the GraphQL over HTTP spec.
|
|
332
332
|
*
|
|
333
333
|
* @category Server
|
|
334
334
|
*/
|
package/lib/handler.mjs
CHANGED
|
@@ -17,7 +17,7 @@ export function isResponse(val) {
|
|
|
17
17
|
isObject(val[1]));
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
* Makes a GraphQL over HTTP
|
|
20
|
+
* Makes a GraphQL over HTTP spec compliant server handler. The handler can
|
|
21
21
|
* be used with your favourite server library.
|
|
22
22
|
*
|
|
23
23
|
* Beware that the handler resolves only after the whole operation completes.
|
|
@@ -286,7 +286,7 @@ export function createHandler(options) {
|
|
|
286
286
|
}
|
|
287
287
|
/**
|
|
288
288
|
* Inspects the request and detects the appropriate/acceptable Media-Type
|
|
289
|
-
* looking at the `Accept` header while complying with the GraphQL over HTTP
|
|
289
|
+
* looking at the `Accept` header while complying with the GraphQL over HTTP spec.
|
|
290
290
|
*
|
|
291
291
|
* @category Server
|
|
292
292
|
*/
|
|
@@ -322,7 +322,7 @@ export function getAcceptableMediaType(acceptHeader) {
|
|
|
322
322
|
* If the first argument is an `ExecutionResult`, the operation will be treated as "successful".
|
|
323
323
|
*
|
|
324
324
|
* If the first argument is _any_ object without the `data` field, it will be treated as an error (as per the spec)
|
|
325
|
-
* and the response will be constructed with the help of `acceptedMediaType` complying with the GraphQL over HTTP
|
|
325
|
+
* and the response will be constructed with the help of `acceptedMediaType` complying with the GraphQL over HTTP spec.
|
|
326
326
|
*
|
|
327
327
|
* @category Server
|
|
328
328
|
*/
|
package/lib/use/express.d.mts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import type { Request, Handler } from 'express';
|
|
2
|
-
import { HandlerOptions, OperationContext } from '../handler';
|
|
2
|
+
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Handler options when using the express adapter.
|
|
5
|
+
*
|
|
6
|
+
* @category Server/express
|
|
7
|
+
*/
|
|
8
|
+
export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<Request, undefined, Context>;
|
|
9
|
+
/**
|
|
10
|
+
* Create a GraphQL over HTTP spec compliant request handler for
|
|
5
11
|
* the express framework.
|
|
6
12
|
*
|
|
7
13
|
* ```js
|
|
@@ -18,4 +24,4 @@ import { HandlerOptions, OperationContext } from '../handler';
|
|
|
18
24
|
*
|
|
19
25
|
* @category Server/express
|
|
20
26
|
*/
|
|
21
|
-
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<
|
|
27
|
+
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<Context>): Handler;
|
package/lib/use/express.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import type { Request, Handler } from 'express';
|
|
2
|
-
import { HandlerOptions, OperationContext } from '../handler';
|
|
2
|
+
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Handler options when using the express adapter.
|
|
5
|
+
*
|
|
6
|
+
* @category Server/express
|
|
7
|
+
*/
|
|
8
|
+
export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<Request, undefined, Context>;
|
|
9
|
+
/**
|
|
10
|
+
* Create a GraphQL over HTTP spec compliant request handler for
|
|
5
11
|
* the express framework.
|
|
6
12
|
*
|
|
7
13
|
* ```js
|
|
@@ -18,4 +24,4 @@ import { HandlerOptions, OperationContext } from '../handler';
|
|
|
18
24
|
*
|
|
19
25
|
* @category Server/express
|
|
20
26
|
*/
|
|
21
|
-
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<
|
|
27
|
+
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<Context>): Handler;
|
package/lib/use/express.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createHandler = void 0;
|
|
4
4
|
const handler_1 = require("../handler");
|
|
5
5
|
/**
|
|
6
|
-
* Create a GraphQL over HTTP
|
|
6
|
+
* Create a GraphQL over HTTP spec compliant request handler for
|
|
7
7
|
* the express framework.
|
|
8
8
|
*
|
|
9
9
|
* ```js
|
package/lib/use/express.mjs
CHANGED
package/lib/use/fastify.d.mts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import type { FastifyRequest, RouteHandler } from 'fastify';
|
|
2
|
-
import { HandlerOptions, OperationContext } from '../handler';
|
|
2
|
+
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Handler options when using the fastify adapter.
|
|
5
|
+
*
|
|
6
|
+
* @category Server/fastify
|
|
7
|
+
*/
|
|
8
|
+
export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<FastifyRequest, undefined, Context>;
|
|
9
|
+
/**
|
|
10
|
+
* Create a GraphQL over HTTP spec compliant request handler for
|
|
5
11
|
* the fastify framework.
|
|
6
12
|
*
|
|
7
13
|
* ```js
|
|
@@ -18,4 +24,4 @@ import { HandlerOptions, OperationContext } from '../handler';
|
|
|
18
24
|
*
|
|
19
25
|
* @category Server/fastify
|
|
20
26
|
*/
|
|
21
|
-
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<
|
|
27
|
+
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<Context>): RouteHandler;
|
package/lib/use/fastify.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import type { FastifyRequest, RouteHandler } from 'fastify';
|
|
2
|
-
import { HandlerOptions, OperationContext } from '../handler';
|
|
2
|
+
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Handler options when using the fastify adapter.
|
|
5
|
+
*
|
|
6
|
+
* @category Server/fastify
|
|
7
|
+
*/
|
|
8
|
+
export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<FastifyRequest, undefined, Context>;
|
|
9
|
+
/**
|
|
10
|
+
* Create a GraphQL over HTTP spec compliant request handler for
|
|
5
11
|
* the fastify framework.
|
|
6
12
|
*
|
|
7
13
|
* ```js
|
|
@@ -18,4 +24,4 @@ import { HandlerOptions, OperationContext } from '../handler';
|
|
|
18
24
|
*
|
|
19
25
|
* @category Server/fastify
|
|
20
26
|
*/
|
|
21
|
-
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<
|
|
27
|
+
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<Context>): RouteHandler;
|
package/lib/use/fastify.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createHandler = void 0;
|
|
4
4
|
const handler_1 = require("../handler");
|
|
5
5
|
/**
|
|
6
|
-
* Create a GraphQL over HTTP
|
|
6
|
+
* Create a GraphQL over HTTP spec compliant request handler for
|
|
7
7
|
* the fastify framework.
|
|
8
8
|
*
|
|
9
9
|
* ```js
|
package/lib/use/fastify.mjs
CHANGED