Skip to content

Commit f5b0305

Browse files
committed
feat(use): Deprecate node adapter in favor of http and http2 adapters
1 parent f14a821 commit f5b0305

File tree

10 files changed

+431
-67
lines changed

10 files changed

+431
-67
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const schema = new GraphQLSchema({
5555

5656
```js
5757
import http from 'http';
58-
import { createHandler } from 'graphql-http/lib/use/node';
58+
import { createHandler } from 'graphql-http/lib/use/http';
5959
import { schema } from './previous-step';
6060

6161
// Create the GraphQL over HTTP Node request handler
@@ -86,7 +86,7 @@ $ openssl req -x509 -newkey rsa:2048 -nodes -sha256 -subj '/CN=localhost' \
8686
```js
8787
import fs from 'fs';
8888
import http2 from 'http2';
89-
import { createHandler } from 'graphql-http/lib/use/node';
89+
import { createHandler } from 'graphql-http/lib/use/http2';
9090
import { schema } from './previous-step';
9191

9292
// Create the GraphQL over HTTP Node request handler

docs/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,7 @@ graphql-http
1515
- [use/express](modules/use_express.md)
1616
- [use/fastify](modules/use_fastify.md)
1717
- [use/fetch](modules/use_fetch.md)
18+
- [use/http](modules/use_http.md)
19+
- [use/http2](modules/use_http2.md)
1820
- [use/koa](modules/use_koa.md)
1921
- [use/node](modules/use_node.md)

docs/modules/use_http.md

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
[graphql-http](../README.md) / use/http
2+
3+
# Module: use/http
4+
5+
## Table of contents
6+
7+
### Type Aliases
8+
9+
- [HandlerOptions](use_http.md#handleroptions)
10+
11+
### Functions
12+
13+
- [createHandler](use_http.md#createhandler)
14+
15+
## Server/http
16+
17+
### HandlerOptions
18+
19+
Ƭ **HandlerOptions**<`Context`\>: [`HandlerOptions`](../interfaces/handler.HandlerOptions.md)<`IncomingMessage`, `undefined`, `Context`\>
20+
21+
Handler options when using the http adapter.
22+
23+
#### Type parameters
24+
25+
| Name | Type |
26+
| :------ | :------ |
27+
| `Context` | extends [`OperationContext`](handler.md#operationcontext) = `undefined` |
28+
29+
___
30+
31+
### createHandler
32+
33+
**createHandler**<`Context`\>(`options`): (`req`: `IncomingMessage`, `res`: `ServerResponse`) => `Promise`<`void`\>
34+
35+
Create a GraphQL over HTTP Protocol compliant request handler for
36+
the Node environment http module.
37+
38+
```js
39+
import http from 'http';
40+
import { createHandler } from 'graphql-http/lib/use/http';
41+
import { schema } from './my-graphql-step';
42+
43+
const server = http.createServer(createHandler({ schema }));
44+
45+
server.listen(4000);
46+
console.log('Listening to port 4000');
47+
```
48+
49+
#### Type parameters
50+
51+
| Name | Type |
52+
| :------ | :------ |
53+
| `Context` | extends [`OperationContext`](handler.md#operationcontext) = `undefined` |
54+
55+
#### Parameters
56+
57+
| Name | Type |
58+
| :------ | :------ |
59+
| `options` | [`HandlerOptions`](use_http.md#handleroptions)<`Context`\> |
60+
61+
#### Returns
62+
63+
`fn`
64+
65+
▸ (`req`, `res`): `Promise`<`void`\>
66+
67+
##### Parameters
68+
69+
| Name | Type |
70+
| :------ | :------ |
71+
| `req` | `IncomingMessage` |
72+
| `res` | `ServerResponse` |
73+
74+
##### Returns
75+
76+
`Promise`<`void`\>

docs/modules/use_http2.md

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
[graphql-http](../README.md) / use/http2
2+
3+
# Module: use/http2
4+
5+
## Table of contents
6+
7+
### Type Aliases
8+
9+
- [HandlerOptions](use_http2.md#handleroptions)
10+
11+
### Functions
12+
13+
- [createHandler](use_http2.md#createhandler)
14+
15+
## Server/http2
16+
17+
### HandlerOptions
18+
19+
Ƭ **HandlerOptions**<`Context`\>: [`HandlerOptions`](../interfaces/handler.HandlerOptions.md)<`Http2ServerRequest`, `undefined`, `Context`\>
20+
21+
Handler options when using the http adapter.
22+
23+
#### Type parameters
24+
25+
| Name | Type |
26+
| :------ | :------ |
27+
| `Context` | extends [`OperationContext`](handler.md#operationcontext) = `undefined` |
28+
29+
___
30+
31+
### createHandler
32+
33+
**createHandler**<`Context`\>(`options`): (`req`: `Http2ServerRequest`, `res`: `Http2ServerResponse`) => `Promise`<`void`\>
34+
35+
Create a GraphQL over HTTP Protocol compliant request handler for
36+
the Node environment http2 module.
37+
38+
```shell
39+
$ openssl req -x509 -newkey rsa:2048 -nodes -sha256 -subj '/CN=localhost' \
40+
-keyout localhost-privkey.pem -out localhost-cert.pem
41+
```
42+
43+
```js
44+
import fs from 'fs';
45+
import http2 from 'http2';
46+
import { createHandler } from 'graphql-http/lib/use/http2';
47+
import { schema } from './my-graphql-step';
48+
49+
const server = http2.createSecureServer(
50+
{
51+
key: fs.readFileSync('localhost-privkey.pem'),
52+
cert: fs.readFileSync('localhost-cert.pem'),
53+
},
54+
createHandler({ schema }),
55+
);
56+
57+
server.listen(4000);
58+
console.log('Listening to port 4000');
59+
```
60+
61+
#### Type parameters
62+
63+
| Name | Type |
64+
| :------ | :------ |
65+
| `Context` | extends [`OperationContext`](handler.md#operationcontext) = `undefined` |
66+
67+
#### Parameters
68+
69+
| Name | Type |
70+
| :------ | :------ |
71+
| `options` | [`HandlerOptions`](use_http2.md#handleroptions)<`Context`\> |
72+
73+
#### Returns
74+
75+
`fn`
76+
77+
▸ (`req`, `res`): `Promise`<`void`\>
78+
79+
##### Parameters
80+
81+
| Name | Type |
82+
| :------ | :------ |
83+
| `req` | `Http2ServerRequest` |
84+
| `res` | `Http2ServerResponse` |
85+
86+
##### Returns
87+
88+
`Promise`<`void`\>

docs/modules/use_node.md

+42-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@
1616

1717
### HandlerOptions
1818

19-
Ƭ **HandlerOptions**<`Context`\>: [`HandlerOptions`](../interfaces/handler.HandlerOptions.md)<`IncomingMessage`, `undefined`, `Context`\>
19+
Ƭ **HandlerOptions**<`Context`\>: [`HandlerOptions`](use_http.md#handleroptions)<`Context`\>
2020

2121
Handler options when using the node adapter.
2222

23+
**`Deprecated`**
24+
25+
Please use [http](use_http.md#handleroptions) or [http2](use_http2.md#handleroptions) adapters instead.
26+
2327
#### Type parameters
2428

2529
| Name | Type |
@@ -30,7 +34,7 @@ ___
3034

3135
### createHandler
3236

33-
**createHandler**<`Context`\>(`options`): `RequestListener`
37+
**createHandler**<`Context`\>(`options`): (`req`: `IncomingMessage`, `res`: `ServerResponse`<`IncomingMessage`\>) => `Promise`<`void`\>
3438

3539
Create a GraphQL over HTTP Protocol compliant request handler for
3640
the Node environment.
@@ -46,6 +50,10 @@ server.listen(4000);
4650
console.log('Listening to port 4000');
4751
```
4852

53+
**`Deprecated`**
54+
55+
Please use [http](use_http.md#createhandler) or [http2](use_http2.md#createhandler) adapters instead.
56+
4957
#### Type parameters
5058

5159
| Name | Type |
@@ -60,4 +68,35 @@ console.log('Listening to port 4000');
6068

6169
#### Returns
6270

63-
`RequestListener`
71+
`fn`
72+
73+
▸ (`req`, `res`): `Promise`<`void`\>
74+
75+
Create a GraphQL over HTTP Protocol compliant request handler for
76+
the Node environment http module.
77+
78+
```js
79+
import http from 'http';
80+
import { createHandler } from 'graphql-http/lib/use/http';
81+
import { schema } from './my-graphql-step';
82+
83+
const server = http.createServer(createHandler({ schema }));
84+
85+
server.listen(4000);
86+
console.log('Listening to port 4000');
87+
```
88+
89+
**`Category`**
90+
91+
Server/http
92+
93+
##### Parameters
94+
95+
| Name | Type |
96+
| :------ | :------ |
97+
| `req` | `IncomingMessage` |
98+
| `res` | `ServerResponse`<`IncomingMessage`\> |
99+
100+
##### Returns
101+
102+
`Promise`<`void`\>

package.json

+10
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@
4545
"require": "./lib/use/node.js",
4646
"import": "./lib/use/node.mjs"
4747
},
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+
},
4858
"./lib/use/express": {
4959
"types": "./lib/use/express.d.ts",
5060
"require": "./lib/use/express.js",

src/__tests__/use.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import { startDisposableServer } from './utils/tserver';
99
import { serverAudits } from '../audits';
1010
import { schema } from './fixtures/simple';
1111

12-
import { createHandler as createNodeHandler } from '../use/node';
12+
import { createHandler as createHttpHandler } from '../use/http';
1313
import { createHandler as createExpressHandler } from '../use/express';
1414
import { createHandler as createFastifyHandler } from '../use/fastify';
1515
import { createHandler as createFetchHandler } from '../use/fetch';
1616
import { createHandler as createKoaHandler } from '../use/koa';
1717

18-
describe('node', () => {
18+
describe('http', () => {
1919
const [url, dispose] = startDisposableServer(
20-
http.createServer(createNodeHandler({ schema })),
20+
http.createServer(createHttpHandler({ schema })),
2121
);
2222
afterAll(dispose);
2323

@@ -31,6 +31,10 @@ describe('node', () => {
3131
}
3232
});
3333

34+
describe('http2', () => {
35+
it.todo('should pass all server audits');
36+
});
37+
3438
describe('express', () => {
3539
const app = express();
3640
app.all('/', createExpressHandler({ schema }));

0 commit comments

Comments
 (0)