Module: use/koa
Interfaces
Server/koa
HandlerOptions
Ƭ HandlerOptions<Context
>: HandlerOptions
<IncomingMessage
, RequestContext
, Context
>
Handler options when using the koa adapter.
Type parameters
Name | Type |
---|---|
Context | extends OperationContext = undefined |
Defined in
src/use/koa.ts:21 (opens in a new tab)
createHandler
▸ createHandler<Context
>(options
): Middleware
The ready-to-use handler for Koa (opens in a new tab).
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
Name | Type |
---|---|
Context | extends OperationContext = undefined |
Parameters
Name | Type |
---|---|
options | HandlerOptions <Context > |
Returns
Middleware