在@ nestjs / graphql中嵌套查询,对于所有先前的查询结果,在更有效的`ResolverProperty`中

时间:2020-08-29 23:25:05

标签: graphql nestjs

我正在使用@nestjs/graphql,我的代码是↓


@Resolver(() => Course)
export default class CourseResolver {
   @Query(() => [Course])
   course(@Args('where', { nullable: true }) where: CourseSearchDto) {
      return Course.find(where);
   }

   @ResolveProperty(() => [Profession])
   async professions(@Parent() course: Course) {
      return await Profession.find({ id: course.id });
   }
}

以下查询时,每个profession都会调用Course方法,但我想像DB中的left join一样运行一次。


{
  course {
    key,
    id,
    professions{
      id, key
    }
  }
}

是否有解决方案可以执行一次,然后为每个profession加入每个course

0 个答案:

没有答案