nestjs-dataloader
nestjs-dataloader copied to clipboard
Usage in @FieldResolver()
Hi,
Is it possible to use nestjs-dataloader with something like below?
@Resolver(() => AccountDto)
export class AccountFieldResolver {
constructor(private queryBus: QueryBus) {}
@ResolveField(() => [AccountDto], { name: 'account' })
async resolveCompanyAbsences(
@Args('input') { id }: AccountKey,
@Loader(CompanyEmployeeAbsenceLoader) accountLoader: DataLoader<AccountKey, Account>,
) {
return accountLoader.load({ id });
}
Seems that the interceptor is not being initialized and it fails with error
You should provide interceptor ${DataLoaderInterceptor.name} globally with ${APP_INTERCEPTOR}
Hey @vinaybedre I was just passing through and saw your question.
What you're trying to do is possible – you're just missing one thing: globally registering your loader.
In your top level app module, make sure to provide CompanyEmployeeAbsenceLoader:
@Module({
providers: [
AccountFieldResolver, // <-- you're probably providing this somewhere, already
CompanyEmployeeAbsenceLoader, // <-- make sure to provide your loader
{
provide: APP_INTERCEPTOR,
useClass: DataLoaderInterceptor,
}, // <-- as well as the library's DataloaderInterceptor
],
})
export class AppModule { }