Giter VIP home page Giter VIP logo

Comments (9)

jonathborg avatar jonathborg commented on June 3, 2024 2

Just added @Injectable({ scope: Scope.REQUEST }) on dataloader provider. Btw, I'm using another library: https://github.com/jonathborg/nestjs-graphql-dataloader

from nestjs-dataloader.

liangwei0101 avatar liangwei0101 commented on June 3, 2024

The same is true for me. One dataloader is good,but two will not work。

What about this error? I'm not asking for a fix. But, do you know what means?
I followed the steps, one by one. I tryed to put the interceptor inside local module and app.module.
The error show up only when I implement 2 dataloaders. It works nice with one dataloader.

Nest version: ^7.4.2

The same is true for me. One dataloader is good,but two will not work。

from nestjs-dataloader.

liangwei0101 avatar liangwei0101 commented on June 3, 2024
  {
      provide: APP_INTERCEPTOR,
      useClass: DataLoaderInterceptor,
    }

If this is used twice, the error will be reported.This is the mistake:
Nest could not find xxx element (this provider does not exist in the current context)

from nestjs-dataloader.

krislefeber avatar krislefeber commented on June 3, 2024

Sorry for taking so long to get back. But for starters, you should only place the interceptor in one module. After doing that, if that module is not the global module, import that module to the global module. Let me know if that makes sense, and we can keep troubleshooting from there

from nestjs-dataloader.

krislefeber avatar krislefeber commented on June 3, 2024

@liangwei0101, that's by design. We don't want to instances of this class, as that would defeat the purpose of one thing loading everything at once. That's why we create a single instance in a single module, and then share that module

from nestjs-dataloader.

liangwei0101 avatar liangwei0101 commented on June 3, 2024

Sorry for taking so long to get back. But for starters, you should only place the interceptor in one module. After doing that, if that module is not the global module, import that module to the global module. Let me know if that makes sense, and we can keep troubleshooting from there

It means that all implementations of dataloader should be placed in one place? For example:

@Module({
  imports: [TypeOrmModule.forFeature([XXX1, XXX2, XX3])],
  providers: [
    xxx1DataLoader,
    xxx2DataLoader,
    xxx3DataLoader,
    xxx4DataLoader,
    xxx5DataLoader,
    xxx6DataLoader,
    {
      provide: APP_INTERCEPTOR,
      useClass: DataLoaderInterceptor,
    },
  ],
})
export class DataLoaderModule {}

That's what it means?

from nestjs-dataloader.

krislefeber avatar krislefeber commented on June 3, 2024

That dataloaderinterceptor should be in a single module, generally the global, or in a module for the resolvers. You can then have your specific dataloader classes wherever they need in other modules

from nestjs-dataloader.

krislefeber avatar krislefeber commented on June 3, 2024

This is how I have it setup
@Module({ imports: [ServicesModule], providers: [ AccountResolver, AuthenticationResolver, CompanyResolver, DateTimeScalar, DateScalar, JobBreakdownResolver, JobAreaResolver, MileageRecordingResolver, SupervisorReminderResolver, SupervisorNoteResolver, UserEventResolver, { provide: APP_GUARD, useClass: AuthenticationGuard, scope: Scope.REQUEST, inject: [AuthenticationService], }, { provide: APP_INTERCEPTOR, useClass: DataLoaderInterceptor, }, { provide: APP_INTERCEPTOR, useClass: EventInterceptor, }, ], }) export class ResolversModule {}

And then I have my dataloaders in their specific domain modules, and export them.

@Module({ imports: [ ConfigModule, IntegrationsModule, UserPermissionModule, TypeOrmModule.forFeature([ AccountRepository, AccountRegistrationRepository, ForgottenPasswordRepository, SeedAccountRepository, ]), ], providers: [ AccountLoader, AccountService, RegistrationService, SeedAccountService, ], exports: [ AccountLoader, AccountService, RegistrationService, SeedAccountService, ], }) export class AccountModule { }

Sorry about formatting, I'm on mobile.

from nestjs-dataloader.

liangwei0101 avatar liangwei0101 commented on June 3, 2024

This is how I have it setup
@Module({ imports: [ServicesModule], providers: [ AccountResolver, AuthenticationResolver, CompanyResolver, DateTimeScalar, DateScalar, JobBreakdownResolver, JobAreaResolver, MileageRecordingResolver, SupervisorReminderResolver, SupervisorNoteResolver, UserEventResolver, { provide: APP_GUARD, useClass: AuthenticationGuard, scope: Scope.REQUEST, inject: [AuthenticationService], }, { provide: APP_INTERCEPTOR, useClass: DataLoaderInterceptor, }, { provide: APP_INTERCEPTOR, useClass: EventInterceptor, }, ], }) export class ResolversModule {}

And then I have my dataloaders in their specific domain modules, and export them.

@Module({ imports: [ ConfigModule, IntegrationsModule, UserPermissionModule, TypeOrmModule.forFeature([ AccountRepository, AccountRegistrationRepository, ForgottenPasswordRepository, SeedAccountRepository, ]), ], providers: [ AccountLoader, AccountService, RegistrationService, SeedAccountService, ], exports: [ AccountLoader, AccountService, RegistrationService, SeedAccountService, ], }) export class AccountModule { }

Sorry about formatting, I'm on mobile.

I see. Thank you

from nestjs-dataloader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.