小编cyb*_*ode的帖子

使用解析器类继承时如何注入服务

我尝试在 TypeGraphQL 中与 Nestjs 一起使用解析器类继承,但不知道如何PostService注入BaseResolver

import { ClassType } from 'type-graphql';
import { Query, Resolver, Args } from '@nestjs/graphql';
import { UseGuards } from '@nestjs/common';
import { PostService } from './post.service';
import { GqlAuthGuard } from 'src/account/auth/auth.guard';

export const createPostBaseResolver = <T extends ClassType>(
  suffix: string,
  objectTypeCls: T,
) => {
  @Resolver(() => objectTypeCls, { isAbstract: true })
  abstract class PostBaseResolver {
    constructor(private readonly postService: PostService) {}

    @Query(() => objectTypeCls, { name: `${suffix}` })
    @UseGuards(GqlAuthGuard)
    async getPostById(@Args('id') …
Run Code Online (Sandbox Code Playgroud)

nestjs typegraphql

8
推荐指数
0
解决办法
542
查看次数

标签 统计

nestjs ×1

typegraphql ×1