@@ -14,49 +14,60 @@ import type Koa from 'koa';
1414// the `koa-bodyparser` types "polyfill" the `koa` types
1515import type * as _ from 'koa-bodyparser' ;
1616
17- export interface KoaContextFunctionArgument {
18- ctx : Koa . Context ;
17+ export interface KoaContextFunctionArgument <
18+ StateT = Koa . DefaultState ,
19+ ContextT = Koa . DefaultContext ,
20+ > {
21+ ctx : Koa . ParameterizedContext < StateT , ContextT > ;
1922}
2023
21- interface KoaMiddlewareOptions < TContext extends BaseContext > {
22- context ?: ContextFunction < [ KoaContextFunctionArgument ] , TContext > ;
24+ interface KoaMiddlewareOptions < TContext extends BaseContext , StateT , ContextT > {
25+ context ?: ContextFunction <
26+ [ KoaContextFunctionArgument < StateT , ContextT > ] ,
27+ TContext
28+ > ;
2329}
2430
2531export function koaMiddleware <
2632 StateT = Koa . DefaultState ,
2733 ContextT = Koa . DefaultContext ,
2834> (
2935 server : ApolloServer < BaseContext > ,
30- options ?: KoaMiddlewareOptions < BaseContext > ,
36+ options ?: KoaMiddlewareOptions < BaseContext , StateT , ContextT > ,
3137) : Koa . Middleware < StateT , ContextT > ;
3238export function koaMiddleware <
3339 TContext extends BaseContext ,
3440 StateT = Koa . DefaultState ,
3541 ContextT = Koa . DefaultContext ,
3642> (
3743 server : ApolloServer < TContext > ,
38- options : WithRequired < KoaMiddlewareOptions < TContext > , 'context' > ,
44+ options : WithRequired <
45+ KoaMiddlewareOptions < TContext , StateT , ContextT > ,
46+ 'context'
47+ > ,
3948) : Koa . Middleware < StateT , ContextT > ;
4049export function koaMiddleware <
4150 TContext extends BaseContext ,
4251 StateT = Koa . DefaultState ,
4352 ContextT = Koa . DefaultContext ,
4453> (
4554 server : ApolloServer < TContext > ,
46- options ?: KoaMiddlewareOptions < TContext > ,
55+ options ?: KoaMiddlewareOptions < TContext , StateT , ContextT > ,
4756) : Koa . Middleware < StateT , ContextT > {
4857 server . assertStarted ( 'koaMiddleware()' ) ;
4958
5059 // This `any` is safe because the overload above shows that context can
5160 // only be left out if you're using BaseContext as your context, and {} is a
5261 // valid BaseContext.
5362 const defaultContext : ContextFunction <
54- [ KoaContextFunctionArgument ] ,
63+ [ KoaContextFunctionArgument < StateT , ContextT > ] ,
5564 any
5665 > = async ( ) => ( { } ) ;
5766
58- const context : ContextFunction < [ KoaContextFunctionArgument ] , TContext > =
59- options ?. context ?? defaultContext ;
67+ const context : ContextFunction <
68+ [ KoaContextFunctionArgument < StateT , ContextT > ] ,
69+ TContext
70+ > = options ?. context ?? defaultContext ;
6071
6172 return async ( ctx ) => {
6273 if ( ! ctx . request . body ) {
0 commit comments