Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage in @FieldResolver() #61

Open
vinaybedre opened this issue Jan 30, 2023 · 1 comment
Open

Usage in @FieldResolver() #61

vinaybedre opened this issue Jan 30, 2023 · 1 comment

Comments

@vinaybedre
Copy link

vinaybedre commented Jan 30, 2023

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}

@dhritzkiv
Copy link

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 { }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants