Skip to content

Commit f14a821

Browse files
committed
feat(use): Each adapter has an adapted HandlerOptions interface
1 parent 01f278c commit f14a821

File tree

10 files changed

+152
-22
lines changed

10 files changed

+152
-22
lines changed

docs/modules/use_express.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,30 @@
44

55
## Table of contents
66

7+
### Type Aliases
8+
9+
- [HandlerOptions](use_express.md#handleroptions)
10+
711
### Functions
812

913
- [createHandler](use_express.md#createhandler)
1014

1115
## Server/express
1216

17+
### HandlerOptions
18+
19+
Ƭ **HandlerOptions**<`Context`\>: [`HandlerOptions`](../interfaces/handler.HandlerOptions.md)<`Request`, `undefined`, `Context`\>
20+
21+
Handler options when using the express adapter.
22+
23+
#### Type parameters
24+
25+
| Name | Type |
26+
| :------ | :------ |
27+
| `Context` | extends [`OperationContext`](handler.md#operationcontext) = `undefined` |
28+
29+
___
30+
1331
### createHandler
1432

1533
**createHandler**<`Context`\>(`options`): `Handler`
@@ -39,7 +57,7 @@ console.log('Listening to port 4000');
3957

4058
| Name | Type |
4159
| :------ | :------ |
42-
| `options` | [`HandlerOptions`](../interfaces/handler.HandlerOptions.md)<`Request`<`ParamsDictionary`, `any`, `any`, `ParsedQs`, `Record`<`string`, `any`\>\>, `undefined`, `Context`\> |
60+
| `options` | [`HandlerOptions`](use_express.md#handleroptions)<`Context`\> |
4361

4462
#### Returns
4563

docs/modules/use_fastify.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,30 @@
44

55
## Table of contents
66

7+
### Type Aliases
8+
9+
- [HandlerOptions](use_fastify.md#handleroptions)
10+
711
### Functions
812

913
- [createHandler](use_fastify.md#createhandler)
1014

1115
## Server/fastify
1216

17+
### HandlerOptions
18+
19+
Ƭ **HandlerOptions**<`Context`\>: [`HandlerOptions`](../interfaces/handler.HandlerOptions.md)<`FastifyRequest`, `undefined`, `Context`\>
20+
21+
Handler options when using the fastify adapter.
22+
23+
#### Type parameters
24+
25+
| Name | Type |
26+
| :------ | :------ |
27+
| `Context` | extends [`OperationContext`](handler.md#operationcontext) = `undefined` |
28+
29+
___
30+
1331
### createHandler
1432

1533
**createHandler**<`Context`\>(`options`): `RouteHandler`
@@ -39,7 +57,7 @@ console.log('Listening to port 4000');
3957

4058
| Name | Type |
4159
| :------ | :------ |
42-
| `options` | [`HandlerOptions`](../interfaces/handler.HandlerOptions.md)<`FastifyRequest`<`RouteGenericInterface`, `RawServerDefault`, `IncomingMessage`, `FastifySchema`, `FastifyTypeProviderDefault`, `unknown`, `FastifyBaseLogger`, `ResolveFastifyRequestType`<`FastifyTypeProviderDefault`, `FastifySchema`, `RouteGenericInterface`\>\>, `undefined`, `Context`\> |
60+
| `options` | [`HandlerOptions`](use_fastify.md#handleroptions)<`Context`\> |
4361

4462
#### Returns
4563

docs/modules/use_fetch.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,33 @@
88

99
- [FetchAPI](../interfaces/use_fetch.FetchAPI.md)
1010

11+
### Type Aliases
12+
13+
- [HandlerOptions](use_fetch.md#handleroptions)
14+
1115
### Functions
1216

1317
- [createHandler](use_fetch.md#createhandler)
1418

1519
## Server/fetch
1620

21+
### HandlerOptions
22+
23+
Ƭ **HandlerOptions**<`Context`\>: [`HandlerOptions`](../interfaces/handler.HandlerOptions.md)<`Request`, [`FetchAPI`](../interfaces/use_fetch.FetchAPI.md), `Context`\>
24+
25+
Handler options when using the fetch adapter.
26+
27+
#### Type parameters
28+
29+
| Name | Type |
30+
| :------ | :------ |
31+
| `Context` | extends [`OperationContext`](handler.md#operationcontext) = `undefined` |
32+
33+
___
34+
1735
### createHandler
1836

19-
**createHandler**<`Context`\>(`options`, `fetchApi?`): (`req`: `Request`) => `Promise`<`Response`\>
37+
**createHandler**<`Context`\>(`options`, `reqCtx?`): (`req`: `Request`) => `Promise`<`Response`\>
2038

2139
Create a GraphQL over HTTP Protocol compliant request handler for
2240
a fetch environment like Deno, Bun, CloudFlare Workers, Lambdas, etc.
@@ -51,8 +69,8 @@ console.log('Listening to port 4000');
5169

5270
| Name | Type | Description |
5371
| :------ | :------ | :------ |
54-
| `options` | [`HandlerOptions`](../interfaces/handler.HandlerOptions.md)<`Request`, [`FetchAPI`](../interfaces/use_fetch.FetchAPI.md), `Context`\> | - |
55-
| `fetchApi` | `Partial`<[`FetchAPI`](../interfaces/use_fetch.FetchAPI.md)\> | Custom fetch API engine, will use from global scope if left undefined. |
72+
| `options` | [`HandlerOptions`](use_fetch.md#handleroptions)<`Context`\> | - |
73+
| `reqCtx` | `Partial`<[`FetchAPI`](../interfaces/use_fetch.FetchAPI.md)\> | Custom fetch API engine, will use from global scope if left undefined. |
5674

5775
#### Returns
5876

docs/modules/use_koa.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,30 @@
44

55
## Table of contents
66

7+
### Type Aliases
8+
9+
- [HandlerOptions](use_koa.md#handleroptions)
10+
711
### Functions
812

913
- [createHandler](use_koa.md#createhandler)
1014

1115
## Server/koa
1216

17+
### HandlerOptions
18+
19+
Ƭ **HandlerOptions**<`Context`\>: [`HandlerOptions`](../interfaces/handler.HandlerOptions.md)<`IncomingMessage`, `undefined`, `Context`\>
20+
21+
Handler options when using the koa adapter.
22+
23+
#### Type parameters
24+
25+
| Name | Type |
26+
| :------ | :------ |
27+
| `Context` | extends [`OperationContext`](handler.md#operationcontext) = `undefined` |
28+
29+
___
30+
1331
### createHandler
1432

1533
**createHandler**<`Context`\>(`options`): `Middleware`
@@ -40,7 +58,7 @@ console.log('Listening to port 4000');
4058

4159
| Name | Type |
4260
| :------ | :------ |
43-
| `options` | [`HandlerOptions`](../interfaces/handler.HandlerOptions.md)<`IncomingMessage`, `undefined`, `Context`\> |
61+
| `options` | [`HandlerOptions`](use_koa.md#handleroptions)<`Context`\> |
4462

4563
#### Returns
4664

docs/modules/use_node.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,30 @@
44

55
## Table of contents
66

7+
### Type Aliases
8+
9+
- [HandlerOptions](use_node.md#handleroptions)
10+
711
### Functions
812

913
- [createHandler](use_node.md#createhandler)
1014

1115
## Server/node
1216

17+
### HandlerOptions
18+
19+
Ƭ **HandlerOptions**<`Context`\>: [`HandlerOptions`](../interfaces/handler.HandlerOptions.md)<`IncomingMessage`, `undefined`, `Context`\>
20+
21+
Handler options when using the node adapter.
22+
23+
#### Type parameters
24+
25+
| Name | Type |
26+
| :------ | :------ |
27+
| `Context` | extends [`OperationContext`](handler.md#operationcontext) = `undefined` |
28+
29+
___
30+
1331
### createHandler
1432

1533
**createHandler**<`Context`\>(`options`): `RequestListener`
@@ -38,7 +56,7 @@ console.log('Listening to port 4000');
3856

3957
| Name | Type |
4058
| :------ | :------ |
41-
| `options` | [`HandlerOptions`](../interfaces/handler.HandlerOptions.md)<`IncomingMessage`, `undefined`, `Context`\> |
59+
| `options` | [`HandlerOptions`](use_node.md#handleroptions)<`Context`\> |
4260

4361
#### Returns
4462

src/use/express.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import type { Request, Handler } from 'express';
22
import {
33
createHandler as createRawHandler,
4-
HandlerOptions,
4+
HandlerOptions as RawHandlerOptions,
55
OperationContext,
66
} from '../handler';
77

8+
/**
9+
* Handler options when using the express adapter.
10+
*
11+
* @category Server/express
12+
*/
13+
export type HandlerOptions<Context extends OperationContext = undefined> =
14+
RawHandlerOptions<Request, undefined, Context>;
15+
816
/**
917
* Create a GraphQL over HTTP Protocol compliant request handler for
1018
* the express framework.
@@ -24,7 +32,7 @@ import {
2432
* @category Server/express
2533
*/
2634
export function createHandler<Context extends OperationContext = undefined>(
27-
options: HandlerOptions<Request, undefined, Context>,
35+
options: HandlerOptions<Context>,
2836
): Handler {
2937
const isProd = process.env.NODE_ENV === 'production';
3038
const handle = createRawHandler(options);

src/use/fastify.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import type { FastifyRequest, RouteHandler } from 'fastify';
22
import {
33
createHandler as createRawHandler,
4-
HandlerOptions,
4+
HandlerOptions as RawHandlerOptions,
55
OperationContext,
66
} from '../handler';
77

8+
/**
9+
* Handler options when using the fastify adapter.
10+
*
11+
* @category Server/fastify
12+
*/
13+
export type HandlerOptions<Context extends OperationContext = undefined> =
14+
RawHandlerOptions<FastifyRequest, undefined, Context>;
15+
816
/**
917
* Create a GraphQL over HTTP Protocol compliant request handler for
1018
* the fastify framework.
@@ -24,7 +32,7 @@ import {
2432
* @category Server/fastify
2533
*/
2634
export function createHandler<Context extends OperationContext = undefined>(
27-
options: HandlerOptions<FastifyRequest, undefined, Context>,
35+
options: HandlerOptions<Context>,
2836
): RouteHandler {
2937
const isProd = process.env.NODE_ENV === 'production';
3038
const handle = createRawHandler(options);

src/use/fetch.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
22
createHandler as createRawHandler,
3-
HandlerOptions,
3+
HandlerOptions as RawHandlerOptions,
44
OperationContext,
55
} from '../handler';
66

@@ -15,6 +15,14 @@ export interface FetchAPI {
1515
TextEncoder: typeof TextEncoder;
1616
}
1717

18+
/**
19+
* Handler options when using the fetch adapter.
20+
*
21+
* @category Server/fetch
22+
*/
23+
export type HandlerOptions<Context extends OperationContext = undefined> =
24+
RawHandlerOptions<Request, FetchAPI, Context>;
25+
1826
/**
1927
* Create a GraphQL over HTTP Protocol compliant request handler for
2028
* a fetch environment like Deno, Bun, CloudFlare Workers, Lambdas, etc.
@@ -39,19 +47,19 @@ export interface FetchAPI {
3947
* console.log('Listening to port 4000');
4048
* ```
4149
*
42-
* @param fetchApi - Custom fetch API engine, will use from global scope if left undefined.
50+
* @param reqCtx - Custom fetch API engine, will use from global scope if left undefined.
4351
*
4452
* @category Server/fetch
4553
*/
4654
export function createHandler<Context extends OperationContext = undefined>(
47-
options: HandlerOptions<Request, FetchAPI, Context>,
48-
fetchApi: Partial<FetchAPI> = {},
55+
options: HandlerOptions<Context>,
56+
reqCtx: Partial<FetchAPI> = {},
4957
): (req: Request) => Promise<Response> {
5058
const isProd = process.env.NODE_ENV === 'production';
5159
const api: FetchAPI = {
52-
Response: fetchApi.Response || Response,
53-
TextEncoder: fetchApi.TextEncoder || TextEncoder,
54-
ReadableStream: fetchApi.ReadableStream || ReadableStream,
60+
Response: reqCtx.Response || Response,
61+
TextEncoder: reqCtx.TextEncoder || TextEncoder,
62+
ReadableStream: reqCtx.ReadableStream || ReadableStream,
5563
};
5664
const handler = createRawHandler(options);
5765
return async function handleRequest(req) {

src/use/koa.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@ import type { Middleware } from 'koa';
22
import type { IncomingMessage } from 'http';
33
import {
44
createHandler as createRawHandler,
5-
HandlerOptions,
5+
HandlerOptions as RawHandlerOptions,
66
OperationContext,
77
} from '../handler';
88

9+
/**
10+
* Handler options when using the koa adapter.
11+
*
12+
* @category Server/koa
13+
*/
14+
export type HandlerOptions<Context extends OperationContext = undefined> =
15+
RawHandlerOptions<IncomingMessage, undefined, Context>;
16+
917
/**
1018
* Create a GraphQL over HTTP Protocol compliant request handler for
1119
* the Koa framework.
@@ -26,7 +34,7 @@ import {
2634
* @category Server/koa
2735
*/
2836
export function createHandler<Context extends OperationContext = undefined>(
29-
options: HandlerOptions<IncomingMessage, undefined, Context>,
37+
options: HandlerOptions<Context>,
3038
): Middleware {
3139
const isProd = process.env.NODE_ENV === 'production';
3240
const handle = createRawHandler(options);

src/use/node.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import type { IncomingMessage, RequestListener } from 'http';
22
import {
33
createHandler as createRawHandler,
4-
HandlerOptions,
4+
HandlerOptions as RawHandlerOptions,
55
OperationContext,
66
} from '../handler';
77

8+
/**
9+
* Handler options when using the node adapter.
10+
*
11+
* @category Server/node
12+
*/
13+
export type HandlerOptions<Context extends OperationContext = undefined> =
14+
RawHandlerOptions<IncomingMessage, undefined, Context>;
15+
816
/**
917
* Create a GraphQL over HTTP Protocol compliant request handler for
1018
* the Node environment.
@@ -23,7 +31,7 @@ import {
2331
* @category Server/node
2432
*/
2533
export function createHandler<Context extends OperationContext = undefined>(
26-
options: HandlerOptions<IncomingMessage, undefined, Context>,
34+
options: HandlerOptions<Context>,
2735
): RequestListener {
2836
const isProd = process.env.NODE_ENV === 'production';
2937
const handle = createRawHandler(options);

0 commit comments

Comments
 (0)