typestack / typeorm-typedi-extensions

Dependency injection and service container integration with TypeORM using TypeDI library.
MIT License
262 stars 37 forks source link

question: repository type returns as empty object when used with `type-graphql` field resolver #29

Closed csim-sg closed 3 years ago

csim-sg commented 6 years ago
@Service()
@Resolver(of => CampaignItem)
export class CampaignItemsResolver implements ResolverInterface<CampaignItem> {
  constructor(@injectRepository() private readonly campaignItemReposiory: CampaignItemRepository) {
  }
@FieldResolver({name: "publisherMetrics"})
  async publisherMetrics(@Root() data: CampaignItem):Promise<CampaignItemPublisherMetrics[]> {    
    return this.itemMetricsRepository.getMetricsByItemPublisher(data.id)
  }
}

When used with ResolverInterface & FieldResolver, the respository passed will be a function that empty object

uapasha commented 5 years ago

@monkeymon make sure you call both

TypeGraphQL.useContainer(Container);
TypeORM.useContainer(Container);
NoNameProvided commented 3 years ago

Closing as solved via @uapasha answer, if your issue persists, please open a new issue.

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.