I want to use Facebook's DataLoader with Koa2 in Typescript. I want per-request DataLoader instances to go with my per-request database connections. How is this best achieved?
My current approach is to augment the Koa2 context but I'm failing because I don't know how to fix the type definition.
Here is my attempt at module augmentation...
import 'koa';
declare module 'koa' {
namespace Application {
interface BaseContext {
dataLoader(): any;
}
}
}
Application.BaseContext.prototype.dataLoader = function() {
console.log("Cannot find name 'Application' at line 11 col 1");
}
In addition to the error shown in the log call, I also get Property 'dataLoader' does not exist on type 'BaseContext'
when I import the above and attempt to call dataLoader
.
Cheers