Documentation
Modules
use/fetch

Module: use/fetch

Interfaces

Server/fetch

HandlerOptions

Ƭ HandlerOptions<Context>: HandlerOptions<Request, RequestContext, Context>

Type parameters

NameType
Contextextends OperationContext = undefined

Defined in

src/use/fetch.ts:19


createHandler

createHandler<Context>(options, reqCtx?): (req: Request) => Promise<Response>

The ready-to-use fetch handler. To be used with your favourite fetch framework, in a lambda function, or have deploy to the edge.

Errors thrown from the provided options or callbacks (or even due to library misuse or potential bugs) will reject the handler or bubble to the returned iterator. They are considered internal errors and you should take care of them accordingly.

For production environments, its recommended not to transmit the exact internal error details to the client, but instead report to an error logging tool or simply the console.

import { createHandler } from 'graphql-sse/lib/use/fetch';
import { schema } from './my-graphql';
 
const handler = createHandler({ schema });
 
export async function fetch(req: Request): Promise<Response> {
  try {
    return await handler(req);
  } catch (err) {
    console.error(err);
    return new Response(null, { status: 500 });
  }
}

Type parameters

NameType
Contextextends OperationContext = undefined

Parameters

NameType
optionsHandlerOptions<Context>
reqCtxPartial<RequestContext>

Returns

fn

▸ (req): Promise<Response>

Parameters
NameType
reqRequest
Returns

Promise<Response>

Defined in

src/use/fetch.ts:53