Skip to content

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

Open
@Dr-Phone

Description

@Dr-Phone

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);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions