graphql-http / use/fetch
Ƭ HandlerOptions<Context
>: HandlerOptions
<Request
, FetchAPI
, Context
>
Handler options when using the fetch adapter.
Name | Type |
---|---|
Context |
extends OperationContext = undefined |
▸ createHandler<Context
>(options
, reqCtx?
): (req
: Request
) => Promise
<Response
>
Create a GraphQL over HTTP spec compliant request handler for a fetch environment like Deno, Bun, CloudFlare Workers, Lambdas, etc.
You can use @whatwg-node/server to create a server adapter and isomorphically use it in any environment. See an example:
import http from 'http';
import { createServerAdapter } from '@whatwg-node/server'; // yarn add @whatwg-node/server
import { createHandler } from 'graphql-http/lib/use/fetch';
import { schema } from './my-graphql-schema';
// Use this adapter in _any_ environment.
const adapter = createServerAdapter({
handleRequest: createHandler({ schema }),
});
const server = http.createServer(adapter);
server.listen(4000);
console.log('Listening to port 4000');
Name | Type |
---|---|
Context |
extends OperationContext = undefined |
Name | Type | Description |
---|---|---|
options |
HandlerOptions <Context > |
- |
reqCtx |
Partial <FetchAPI > |
Custom fetch API engine, will use from global scope if left undefined. |
fn
▸ (req
): Promise
<Response
>
Name | Type |
---|---|
req |
Request |
Promise
<Response
>