Documentation
Modules
use/koa

Module: use/koa

Server/koa

HandlerOptions

Ƭ HandlerOptions<Context, KoaState, KoaContext>: HandlerOptions<IncomingMessage, ParameterizedContext<KoaState, KoaContext>, Context>

Handler options when using the koa adapter.

Type parameters

NameType
Contextextends OperationContext = undefined
KoaStateDefaultState
KoaContextDefaultContext

Defined in

src/use/koa.ts:19


createHandler

createHandler<Context, KoaState, KoaContext>(options): Middleware<KoaState, KoaContext>

The ready-to-use handler for Koa.

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 Koa from 'koa'; // yarn add koa
import mount from 'koa-mount'; // yarn add koa-mount
import { createHandler } from 'graphql-sse/lib/use/koa';
import { schema } from './my-graphql';
 
const app = new Koa();
app.use(
  mount('/graphql/stream', async (ctx, next) => {
    try {
      await handler(ctx, next);
    } catch (err) {
      console.error(err);
      ctx.response.status = 500;
      ctx.response.message = 'Internal Server Error';
    }
  }),
);
 
app.listen({ port: 4000 });
console.log('Listening to port 4000');

Type parameters

NameType
Contextextends OperationContext = undefined
KoaStateDefaultState
KoaContextDefaultContext

Parameters

NameType
optionsHandlerOptions<Context, KoaState, KoaContext>

Returns

Middleware<KoaState, KoaContext>

Defined in

src/use/koa.ts:68