graphql-http 1.15.0 → 1.17.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 +38 -11
- 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 +18 -4
- package/lib/use/express.d.ts +18 -4
- package/lib/use/express.js +2 -2
- package/lib/use/express.mjs +2 -2
- package/lib/use/fastify.d.mts +18 -4
- package/lib/use/fastify.d.ts +18 -4
- package/lib/use/fastify.js +2 -2
- package/lib/use/fastify.mjs +2 -2
- 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 +35 -0
- package/lib/use/http.d.ts +35 -0
- package/lib/use/http.js +72 -0
- package/lib/use/http.mjs +68 -0
- package/lib/use/http2.d.mts +47 -0
- package/lib/use/http2.d.ts +47 -0
- package/lib/use/http2.js +90 -0
- package/lib/use/http2.mjs +86 -0
- package/lib/use/koa.d.mts +18 -4
- package/lib/use/koa.d.ts +18 -4
- package/lib/use/koa.js +2 -2
- package/lib/use/koa.mjs +2 -2
- 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 +38 -27
- package/umd/graphql-http-audits.js +6 -3
- package/umd/graphql-http-audits.min.js +1 -1
- package/umd/graphql-http-audits.min.js.gz +0 -0
package/README.md
CHANGED
|
@@ -55,7 +55,7 @@ const schema = new GraphQLSchema({
|
|
|
55
55
|
|
|
56
56
|
```js
|
|
57
57
|
import http from 'http';
|
|
58
|
-
import { createHandler } from 'graphql-http/lib/use/
|
|
58
|
+
import { createHandler } from 'graphql-http/lib/use/http';
|
|
59
59
|
import { schema } from './previous-step';
|
|
60
60
|
|
|
61
61
|
// Create the GraphQL over HTTP Node request handler
|
|
@@ -86,7 +86,7 @@ $ openssl req -x509 -newkey rsa:2048 -nodes -sha256 -subj '/CN=localhost' \
|
|
|
86
86
|
```js
|
|
87
87
|
import fs from 'fs';
|
|
88
88
|
import http2 from 'http2';
|
|
89
|
-
import { createHandler } from 'graphql-http/lib/use/
|
|
89
|
+
import { createHandler } from 'graphql-http/lib/use/http2';
|
|
90
90
|
import { schema } from './previous-step';
|
|
91
91
|
|
|
92
92
|
// Create the GraphQL over HTTP Node request handler
|
|
@@ -736,6 +736,36 @@ for (const audit of serverAudits({
|
|
|
736
736
|
|
|
737
737
|
</details>
|
|
738
738
|
|
|
739
|
+
<details id="audit-deno">
|
|
740
|
+
<summary><a href="#audit-deno">🔗</a> Audit for servers usage in <a href="https://deno.land">Deno</a> environment</summary>
|
|
741
|
+
|
|
742
|
+
```ts
|
|
743
|
+
import { serverAudits } from 'npm:graphql-http';
|
|
744
|
+
|
|
745
|
+
for (const audit of serverAudits({
|
|
746
|
+
url: 'http://localhost:4000/graphql',
|
|
747
|
+
fetchFn: fetch,
|
|
748
|
+
})) {
|
|
749
|
+
Deno.test(audit.name, async () => {
|
|
750
|
+
const result = await audit.fn();
|
|
751
|
+
if (result.status === 'error') {
|
|
752
|
+
throw result.reason;
|
|
753
|
+
}
|
|
754
|
+
if (result.status === 'warn') {
|
|
755
|
+
console.warn(result.reason); // or throw if you want full compliance (warnings are not requirements)
|
|
756
|
+
}
|
|
757
|
+
// Avoid leaking resources
|
|
758
|
+
if ('body' in result && result.body instanceof ReadableStream) {
|
|
759
|
+
await result.body.cancel();
|
|
760
|
+
}
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
```
|
|
764
|
+
|
|
765
|
+
Put the above contents in a file and run it with `deno test --allow-net`.
|
|
766
|
+
|
|
767
|
+
</details>
|
|
768
|
+
|
|
739
769
|
## Only [GraphQL over HTTP](https://graphql.github.io/graphql-over-http/)
|
|
740
770
|
|
|
741
771
|
This is the official [GraphQL over HTTP spec](https://graphql.github.io/graphql-over-http/) reference implementation and as such follows the specification strictly without any additional features (like file uploads, @stream/@defer directives and subscriptions).
|
|
@@ -744,7 +774,9 @@ Having said this, graphql-http is mostly aimed for library authors and simple se
|
|
|
744
774
|
|
|
745
775
|
## [Servers](/implementations)
|
|
746
776
|
|
|
747
|
-
If you want a feature-full server with bleeding edge technologies, you're recommended to use one of the following.
|
|
777
|
+
If you want a feature-full server with bleeding edge technologies, you're recommended to use one of the following servers.
|
|
778
|
+
|
|
779
|
+
Their compliance with the [GraphQL over HTTP spec](https://graphql.github.io/graphql-over-http) is checked automatically and updated regularly.
|
|
748
780
|
|
|
749
781
|
<!-- <ServersTable> -->
|
|
750
782
|
<!-- prettier-ignore-start -->
|
|
@@ -768,16 +800,11 @@ Check the [docs folder](docs/) out for [TypeDoc](https://typedoc.org) generated
|
|
|
768
800
|
|
|
769
801
|
## [Audits](implementations/)
|
|
770
802
|
|
|
771
|
-
Inspect audits of other implementations in the [implementations folder](implementations
|
|
803
|
+
Inspect audits of other implementations in the [implementations folder](implementations).
|
|
804
|
+
Adding your implementation is very welcome, [see how](CONTRIBUTING.md#adding-implementations)!
|
|
772
805
|
|
|
773
806
|
## Want to help?
|
|
774
807
|
|
|
775
|
-
File a bug, contribute with code, or improve documentation? Read
|
|
776
|
-
|
|
777
|
-
This repository is managed by EasyCLA. Project participants must sign the free [GraphQL Specification Membership agreement](https://preview-spec-membership.graphql.org) before making a contribution. You only need to do this one time, and it can be signed by [individual contributors](http://individual-spec-membership.graphql.org/) or their [employers](http://corporate-spec-membership.graphql.org/).
|
|
778
|
-
|
|
779
|
-
To initiate the signature process please open a PR against this repo. The EasyCLA bot will block the merge if we still need a membership agreement from you.
|
|
780
|
-
|
|
781
|
-
You can find [detailed information here](https://github.com/graphql/graphql-wg/tree/main/membership). If you have issues, please email [operations@graphql.org](mailto:operations@graphql.org).
|
|
808
|
+
File a bug, contribute with code, or improve documentation? [Read more in CONTRIBUTING.md](CONTRIBUTING.md).
|
|
782
809
|
|
|
783
810
|
If your company benefits from GraphQL and you would like to provide essential financial support for the systems and people that power our community, please also consider membership in the [GraphQL Foundation](https://foundation.graphql.org/join).
|
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,21 @@
|
|
|
1
|
-
import type { Request, Handler } from 'express';
|
|
2
|
-
import { HandlerOptions, OperationContext } from '../handler';
|
|
1
|
+
import type { Request, Response, Handler } from 'express';
|
|
2
|
+
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* The context in the request for the handler.
|
|
5
|
+
*
|
|
6
|
+
* @category Server/express
|
|
7
|
+
*/
|
|
8
|
+
export interface RequestContext {
|
|
9
|
+
res: Response;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Handler options when using the express adapter.
|
|
13
|
+
*
|
|
14
|
+
* @category Server/express
|
|
15
|
+
*/
|
|
16
|
+
export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<Request, RequestContext, Context>;
|
|
17
|
+
/**
|
|
18
|
+
* Create a GraphQL over HTTP spec compliant request handler for
|
|
5
19
|
* the express framework.
|
|
6
20
|
*
|
|
7
21
|
* ```js
|
|
@@ -18,4 +32,4 @@ import { HandlerOptions, OperationContext } from '../handler';
|
|
|
18
32
|
*
|
|
19
33
|
* @category Server/express
|
|
20
34
|
*/
|
|
21
|
-
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<
|
|
35
|
+
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<Context>): Handler;
|
package/lib/use/express.d.ts
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
|
-
import type { Request, Handler } from 'express';
|
|
2
|
-
import { HandlerOptions, OperationContext } from '../handler';
|
|
1
|
+
import type { Request, Response, Handler } from 'express';
|
|
2
|
+
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* The context in the request for the handler.
|
|
5
|
+
*
|
|
6
|
+
* @category Server/express
|
|
7
|
+
*/
|
|
8
|
+
export interface RequestContext {
|
|
9
|
+
res: Response;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Handler options when using the express adapter.
|
|
13
|
+
*
|
|
14
|
+
* @category Server/express
|
|
15
|
+
*/
|
|
16
|
+
export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<Request, RequestContext, Context>;
|
|
17
|
+
/**
|
|
18
|
+
* Create a GraphQL over HTTP spec compliant request handler for
|
|
5
19
|
* the express framework.
|
|
6
20
|
*
|
|
7
21
|
* ```js
|
|
@@ -18,4 +32,4 @@ import { HandlerOptions, OperationContext } from '../handler';
|
|
|
18
32
|
*
|
|
19
33
|
* @category Server/express
|
|
20
34
|
*/
|
|
21
|
-
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<
|
|
35
|
+
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
|
|
@@ -41,7 +41,7 @@ function createHandler(options) {
|
|
|
41
41
|
});
|
|
42
42
|
},
|
|
43
43
|
raw: req,
|
|
44
|
-
context:
|
|
44
|
+
context: { res },
|
|
45
45
|
});
|
|
46
46
|
res.writeHead(init.status, init.statusText, init.headers).end(body);
|
|
47
47
|
}
|
package/lib/use/express.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHandler as createRawHandler, } from '../handler.mjs';
|
|
2
2
|
/**
|
|
3
|
-
* Create a GraphQL over HTTP
|
|
3
|
+
* Create a GraphQL over HTTP spec compliant request handler for
|
|
4
4
|
* the express framework.
|
|
5
5
|
*
|
|
6
6
|
* ```js
|
|
@@ -38,7 +38,7 @@ export function createHandler(options) {
|
|
|
38
38
|
});
|
|
39
39
|
},
|
|
40
40
|
raw: req,
|
|
41
|
-
context:
|
|
41
|
+
context: { res },
|
|
42
42
|
});
|
|
43
43
|
res.writeHead(init.status, init.statusText, init.headers).end(body);
|
|
44
44
|
}
|
package/lib/use/fastify.d.mts
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
|
-
import type { FastifyRequest, RouteHandler } from 'fastify';
|
|
2
|
-
import { HandlerOptions, OperationContext } from '../handler';
|
|
1
|
+
import type { FastifyRequest, FastifyReply, RouteHandler } from 'fastify';
|
|
2
|
+
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* The context in the request for the handler.
|
|
5
|
+
*
|
|
6
|
+
* @category Server/fastify
|
|
7
|
+
*/
|
|
8
|
+
export interface RequestContext {
|
|
9
|
+
reply: FastifyReply;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Handler options when using the fastify adapter.
|
|
13
|
+
*
|
|
14
|
+
* @category Server/fastify
|
|
15
|
+
*/
|
|
16
|
+
export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<FastifyRequest, RequestContext, Context>;
|
|
17
|
+
/**
|
|
18
|
+
* Create a GraphQL over HTTP spec compliant request handler for
|
|
5
19
|
* the fastify framework.
|
|
6
20
|
*
|
|
7
21
|
* ```js
|
|
@@ -18,4 +32,4 @@ import { HandlerOptions, OperationContext } from '../handler';
|
|
|
18
32
|
*
|
|
19
33
|
* @category Server/fastify
|
|
20
34
|
*/
|
|
21
|
-
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<
|
|
35
|
+
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<Context>): RouteHandler;
|
package/lib/use/fastify.d.ts
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
|
-
import type { FastifyRequest, RouteHandler } from 'fastify';
|
|
2
|
-
import { HandlerOptions, OperationContext } from '../handler';
|
|
1
|
+
import type { FastifyRequest, FastifyReply, RouteHandler } from 'fastify';
|
|
2
|
+
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* The context in the request for the handler.
|
|
5
|
+
*
|
|
6
|
+
* @category Server/fastify
|
|
7
|
+
*/
|
|
8
|
+
export interface RequestContext {
|
|
9
|
+
reply: FastifyReply;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Handler options when using the fastify adapter.
|
|
13
|
+
*
|
|
14
|
+
* @category Server/fastify
|
|
15
|
+
*/
|
|
16
|
+
export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<FastifyRequest, RequestContext, Context>;
|
|
17
|
+
/**
|
|
18
|
+
* Create a GraphQL over HTTP spec compliant request handler for
|
|
5
19
|
* the fastify framework.
|
|
6
20
|
*
|
|
7
21
|
* ```js
|
|
@@ -18,4 +32,4 @@ import { HandlerOptions, OperationContext } from '../handler';
|
|
|
18
32
|
*
|
|
19
33
|
* @category Server/fastify
|
|
20
34
|
*/
|
|
21
|
-
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<
|
|
35
|
+
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
|
|
@@ -32,7 +32,7 @@ function createHandler(options) {
|
|
|
32
32
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
33
|
body: req.body,
|
|
34
34
|
raw: req,
|
|
35
|
-
context:
|
|
35
|
+
context: { reply },
|
|
36
36
|
});
|
|
37
37
|
reply
|
|
38
38
|
.status(init.status)
|
package/lib/use/fastify.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHandler as createRawHandler, } from '../handler.mjs';
|
|
2
2
|
/**
|
|
3
|
-
* Create a GraphQL over HTTP
|
|
3
|
+
* Create a GraphQL over HTTP spec compliant request handler for
|
|
4
4
|
* the fastify framework.
|
|
5
5
|
*
|
|
6
6
|
* ```js
|
|
@@ -29,7 +29,7 @@ export function createHandler(options) {
|
|
|
29
29
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
30
|
body: req.body,
|
|
31
31
|
raw: req,
|
|
32
|
-
context:
|
|
32
|
+
context: { reply },
|
|
33
33
|
});
|
|
34
34
|
reply
|
|
35
35
|
.status(init.status)
|
package/lib/use/fetch.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HandlerOptions, OperationContext } from '../handler';
|
|
1
|
+
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
|
|
2
2
|
/**
|
|
3
3
|
* The necessary API from the fetch environment for the handler.
|
|
4
4
|
*
|
|
@@ -10,7 +10,13 @@ export interface FetchAPI {
|
|
|
10
10
|
TextEncoder: typeof TextEncoder;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Handler options when using the fetch adapter.
|
|
14
|
+
*
|
|
15
|
+
* @category Server/fetch
|
|
16
|
+
*/
|
|
17
|
+
export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<Request, FetchAPI, Context>;
|
|
18
|
+
/**
|
|
19
|
+
* Create a GraphQL over HTTP spec compliant request handler for
|
|
14
20
|
* a fetch environment like Deno, Bun, CloudFlare Workers, Lambdas, etc.
|
|
15
21
|
*
|
|
16
22
|
* You can use [@whatwg-node/server](https://github.com/ardatan/whatwg-node/tree/master/packages/server) to create a server adapter and
|
|
@@ -33,8 +39,8 @@ export interface FetchAPI {
|
|
|
33
39
|
* console.log('Listening to port 4000');
|
|
34
40
|
* ```
|
|
35
41
|
*
|
|
36
|
-
* @param
|
|
42
|
+
* @param reqCtx - Custom fetch API engine, will use from global scope if left undefined.
|
|
37
43
|
*
|
|
38
44
|
* @category Server/fetch
|
|
39
45
|
*/
|
|
40
|
-
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<
|
|
46
|
+
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<Context>, reqCtx?: Partial<FetchAPI>): (req: Request) => Promise<Response>;
|
package/lib/use/fetch.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HandlerOptions, OperationContext } from '../handler';
|
|
1
|
+
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
|
|
2
2
|
/**
|
|
3
3
|
* The necessary API from the fetch environment for the handler.
|
|
4
4
|
*
|
|
@@ -10,7 +10,13 @@ export interface FetchAPI {
|
|
|
10
10
|
TextEncoder: typeof TextEncoder;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Handler options when using the fetch adapter.
|
|
14
|
+
*
|
|
15
|
+
* @category Server/fetch
|
|
16
|
+
*/
|
|
17
|
+
export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<Request, FetchAPI, Context>;
|
|
18
|
+
/**
|
|
19
|
+
* Create a GraphQL over HTTP spec compliant request handler for
|
|
14
20
|
* a fetch environment like Deno, Bun, CloudFlare Workers, Lambdas, etc.
|
|
15
21
|
*
|
|
16
22
|
* You can use [@whatwg-node/server](https://github.com/ardatan/whatwg-node/tree/master/packages/server) to create a server adapter and
|
|
@@ -33,8 +39,8 @@ export interface FetchAPI {
|
|
|
33
39
|
* console.log('Listening to port 4000');
|
|
34
40
|
* ```
|
|
35
41
|
*
|
|
36
|
-
* @param
|
|
42
|
+
* @param reqCtx - Custom fetch API engine, will use from global scope if left undefined.
|
|
37
43
|
*
|
|
38
44
|
* @category Server/fetch
|
|
39
45
|
*/
|
|
40
|
-
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<
|
|
46
|
+
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<Context>, reqCtx?: Partial<FetchAPI>): (req: Request) => Promise<Response>;
|
package/lib/use/fetch.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
|
* a fetch environment like Deno, Bun, CloudFlare Workers, Lambdas, etc.
|
|
8
8
|
*
|
|
9
9
|
* You can use [@whatwg-node/server](https://github.com/ardatan/whatwg-node/tree/master/packages/server) to create a server adapter and
|
|
@@ -26,16 +26,16 @@ const handler_1 = require("../handler");
|
|
|
26
26
|
* console.log('Listening to port 4000');
|
|
27
27
|
* ```
|
|
28
28
|
*
|
|
29
|
-
* @param
|
|
29
|
+
* @param reqCtx - Custom fetch API engine, will use from global scope if left undefined.
|
|
30
30
|
*
|
|
31
31
|
* @category Server/fetch
|
|
32
32
|
*/
|
|
33
|
-
function createHandler(options,
|
|
33
|
+
function createHandler(options, reqCtx = {}) {
|
|
34
34
|
const isProd = process.env.NODE_ENV === 'production';
|
|
35
35
|
const api = {
|
|
36
|
-
Response:
|
|
37
|
-
TextEncoder:
|
|
38
|
-
ReadableStream:
|
|
36
|
+
Response: reqCtx.Response || Response,
|
|
37
|
+
TextEncoder: reqCtx.TextEncoder || TextEncoder,
|
|
38
|
+
ReadableStream: reqCtx.ReadableStream || ReadableStream,
|
|
39
39
|
};
|
|
40
40
|
const handler = (0, handler_1.createHandler)(options);
|
|
41
41
|
return async function handleRequest(req) {
|
package/lib/use/fetch.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHandler as createRawHandler, } from '../handler.mjs';
|
|
2
2
|
/**
|
|
3
|
-
* Create a GraphQL over HTTP
|
|
3
|
+
* Create a GraphQL over HTTP spec compliant request handler for
|
|
4
4
|
* a fetch environment like Deno, Bun, CloudFlare Workers, Lambdas, etc.
|
|
5
5
|
*
|
|
6
6
|
* You can use [@whatwg-node/server](https://github.com/ardatan/whatwg-node/tree/master/packages/server) to create a server adapter and
|
|
@@ -23,16 +23,16 @@ import { createHandler as createRawHandler, } from '../handler.mjs';
|
|
|
23
23
|
* console.log('Listening to port 4000');
|
|
24
24
|
* ```
|
|
25
25
|
*
|
|
26
|
-
* @param
|
|
26
|
+
* @param reqCtx - Custom fetch API engine, will use from global scope if left undefined.
|
|
27
27
|
*
|
|
28
28
|
* @category Server/fetch
|
|
29
29
|
*/
|
|
30
|
-
export function createHandler(options,
|
|
30
|
+
export function createHandler(options, reqCtx = {}) {
|
|
31
31
|
const isProd = process.env.NODE_ENV === 'production';
|
|
32
32
|
const api = {
|
|
33
|
-
Response:
|
|
34
|
-
TextEncoder:
|
|
35
|
-
ReadableStream:
|
|
33
|
+
Response: reqCtx.Response || Response,
|
|
34
|
+
TextEncoder: reqCtx.TextEncoder || TextEncoder,
|
|
35
|
+
ReadableStream: reqCtx.ReadableStream || ReadableStream,
|
|
36
36
|
};
|
|
37
37
|
const handler = createRawHandler(options);
|
|
38
38
|
return async function handleRequest(req) {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { IncomingMessage, ServerResponse } from 'http';
|
|
3
|
+
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
|
|
4
|
+
/**
|
|
5
|
+
* The context in the request for the handler.
|
|
6
|
+
*
|
|
7
|
+
* @category Server/http
|
|
8
|
+
*/
|
|
9
|
+
export interface RequestContext {
|
|
10
|
+
res: ServerResponse;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Handler options when using the http adapter.
|
|
14
|
+
*
|
|
15
|
+
* @category Server/http
|
|
16
|
+
*/
|
|
17
|
+
export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<IncomingMessage, RequestContext, Context>;
|
|
18
|
+
/**
|
|
19
|
+
* Create a GraphQL over HTTP spec compliant request handler for
|
|
20
|
+
* the Node environment http module.
|
|
21
|
+
*
|
|
22
|
+
* ```js
|
|
23
|
+
* import http from 'http';
|
|
24
|
+
* import { createHandler } from 'graphql-http/lib/use/http';
|
|
25
|
+
* import { schema } from './my-graphql-step';
|
|
26
|
+
*
|
|
27
|
+
* const server = http.createServer(createHandler({ schema }));
|
|
28
|
+
*
|
|
29
|
+
* server.listen(4000);
|
|
30
|
+
* console.log('Listening to port 4000');
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @category Server/http
|
|
34
|
+
*/
|
|
35
|
+
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<Context>): (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { IncomingMessage, ServerResponse } from 'http';
|
|
3
|
+
import { HandlerOptions as RawHandlerOptions, OperationContext } from '../handler';
|
|
4
|
+
/**
|
|
5
|
+
* The context in the request for the handler.
|
|
6
|
+
*
|
|
7
|
+
* @category Server/http
|
|
8
|
+
*/
|
|
9
|
+
export interface RequestContext {
|
|
10
|
+
res: ServerResponse;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Handler options when using the http adapter.
|
|
14
|
+
*
|
|
15
|
+
* @category Server/http
|
|
16
|
+
*/
|
|
17
|
+
export type HandlerOptions<Context extends OperationContext = undefined> = RawHandlerOptions<IncomingMessage, RequestContext, Context>;
|
|
18
|
+
/**
|
|
19
|
+
* Create a GraphQL over HTTP spec compliant request handler for
|
|
20
|
+
* the Node environment http module.
|
|
21
|
+
*
|
|
22
|
+
* ```js
|
|
23
|
+
* import http from 'http';
|
|
24
|
+
* import { createHandler } from 'graphql-http/lib/use/http';
|
|
25
|
+
* import { schema } from './my-graphql-step';
|
|
26
|
+
*
|
|
27
|
+
* const server = http.createServer(createHandler({ schema }));
|
|
28
|
+
*
|
|
29
|
+
* server.listen(4000);
|
|
30
|
+
* console.log('Listening to port 4000');
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @category Server/http
|
|
34
|
+
*/
|
|
35
|
+
export declare function createHandler<Context extends OperationContext = undefined>(options: HandlerOptions<Context>): (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|