INNER CODE UNIT · TypeScript
ExplicitLoaderImpl
slaypni/type-graphql-dataloader · src/decorators/typeorm/ExplicitLoaderImpl.ts:13
export function ExplicitLoaderImpl<V>(
keyFunc: KeyFunc,
option?: TypeormLoaderOption
): PropertyDecorator {
return (target: Object, propertyKey: string | symbol) => {
UseMiddleware(async ({ root, context }, next) => {
const tgdContext = context._tgdContext as TgdContext;
if (tgdContext.typeormGetConnection == null) {
throw Error("typeormGetConnection is not set");
}
const relation = tgdContext
.typeormGetConnection()
.getMetadata(target.constructor)
.findRelationWithPropertyPath(propertyKey.toString());
if (relation == null) {
return await next();
}