@@ -14,49 +14,60 @@ import type Koa from 'koa';
14
14
// the `koa-bodyparser` types "polyfill" the `koa` types
15
15
import type * as _ from 'koa-bodyparser' ;
16
16
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 > ;
19
22
}
20
23
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
+ > ;
23
29
}
24
30
25
31
export function koaMiddleware <
26
32
StateT = Koa . DefaultState ,
27
33
ContextT = Koa . DefaultContext ,
28
34
> (
29
35
server : ApolloServer < BaseContext > ,
30
- options ?: KoaMiddlewareOptions < BaseContext > ,
36
+ options ?: KoaMiddlewareOptions < BaseContext , StateT , ContextT > ,
31
37
) : Koa . Middleware < StateT , ContextT > ;
32
38
export function koaMiddleware <
33
39
TContext extends BaseContext ,
34
40
StateT = Koa . DefaultState ,
35
41
ContextT = Koa . DefaultContext ,
36
42
> (
37
43
server : ApolloServer < TContext > ,
38
- options : WithRequired < KoaMiddlewareOptions < TContext > , 'context' > ,
44
+ options : WithRequired <
45
+ KoaMiddlewareOptions < TContext , StateT , ContextT > ,
46
+ 'context'
47
+ > ,
39
48
) : Koa . Middleware < StateT , ContextT > ;
40
49
export function koaMiddleware <
41
50
TContext extends BaseContext ,
42
51
StateT = Koa . DefaultState ,
43
52
ContextT = Koa . DefaultContext ,
44
53
> (
45
54
server : ApolloServer < TContext > ,
46
- options ?: KoaMiddlewareOptions < TContext > ,
55
+ options ?: KoaMiddlewareOptions < TContext , StateT , ContextT > ,
47
56
) : Koa . Middleware < StateT , ContextT > {
48
57
server . assertStarted ( 'koaMiddleware()' ) ;
49
58
50
59
// This `any` is safe because the overload above shows that context can
51
60
// only be left out if you're using BaseContext as your context, and {} is a
52
61
// valid BaseContext.
53
62
const defaultContext : ContextFunction <
54
- [ KoaContextFunctionArgument ] ,
63
+ [ KoaContextFunctionArgument < StateT , ContextT > ] ,
55
64
any
56
65
> = async ( ) => ( { } ) ;
57
66
58
- const context : ContextFunction < [ KoaContextFunctionArgument ] , TContext > =
59
- options ?. context ?? defaultContext ;
67
+ const context : ContextFunction <
68
+ [ KoaContextFunctionArgument < StateT , ContextT > ] ,
69
+ TContext
70
+ > = options ?. context ?? defaultContext ;
60
71
61
72
return async ( ctx ) => {
62
73
if ( ! ctx . request . body ) {
0 commit comments