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

Request and transient-scoped providers can't be used in combination with \"get()\" method. Please, use \"resolve()\" instead." #13

Open
Dr-Phone opened this issue Aug 11, 2020 · 2 comments

Comments

@Dr-Phone
Copy link

Hi,
Thanks for the library. I experimented with it and got stuck the following error.

CityLoader is marked as a scoped provider. Request and transient-scoped providers can't be used in combination with \"get()\" method. Please, use \"resolve()\" instead."

Any help is appreciated.

Here's how my CityLoader looks like -

import { Injectable } from '@nestjs/common';
import { OrderedNestDataLoader } from 'nestjs-graphql-dataloader';
import { ProfileService } from './profile.service';
import { Profile } from './entities/profile.entity';

@Injectable()
export class CityLoader extends OrderedNestDataLoader<number, City> {
  constructor(
    private readonly profileService: ProfileService) {
    super()
  }

  protected getOptions = () => ({
    query: (keys: Array<number>) => this.profileService.findCityByIds(keys),
  });
}

And this is how I'm trying to resolve it.

import DataLoader from 'dataloader';
import { Loader } from 'nestjs-graphql-dataloader';
import { CityLoader } from './profile.dataloader';

@ResolveField(returns => CityType)
    async city(
        @Parent() parent: Profile,
        @Loader(CityLoader) cityLoader: DataLoader<number, City>
    ) {
        // return this.profileService.getCity(parent.cityId);
        return cityLoader.load(parent.cityId);
    }
@Dr-Phone
Copy link
Author

For anybody else facing the same issue -

replace the following in the library src file - index.ts

await this.moduleRef.resolve<NestDataLoader<any, any>>(
                    type,
                    ctx[NEST_LOADER_CONTEXT_KEY].contextId,
                    { strict: false }
                  )

with the following

this.moduleRef.get<NestDataLoader<any, any>>(
                    type,
                    ctx[NEST_LOADER_CONTEXT_KEY].contextId,
                  )

And it will work.

@TreeMan360
Copy link
Owner

Hi @Dr-Phone, sorry for not getting back to you on this. I will take a look at this as I previously switched this from get to resolve and it was my understanding that this should work in all scenarios.

I am rather snowed under at the moment but I will do my best to look at this in the next 48 hours.

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