11import {
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 */
4654export 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 ) {
0 commit comments