首页 > 解决方案 > 带有 GraphQL 的 Nestjs:如何在 @Resolver 方法的 @Arg 中传递 where 子句?

问题描述

我想让 Nestjs 中的 Graphql 解析器接受 where 子句,然后 Prisma 服务使用它来动态接受给定资源的不同搜索类型。我现在拥有的是:

//task.resolver.ts

  @Resolver((of) => Task)
  export class TaskResolver {
   constructor(private repository: TaskRepository) {}

   @Query((returns) => [Task])
   @UseGuards(JwtAuthGuard)
   async tasks(
    @Args('where', { type: () => <Dont know the type> }) where: Prisma.TaskWhereInput,
   ) {
     return await this.repository.tasks({
       where,
     });
   }
}

我只是希望解析器方法能够处理 where 子句,例如:

// GraphQL client query

  query GetTasks($id: ID!, $level: Int!) {
    tasks(
      where: { user: { id: $id }, taskTemplate: { level: $level } }
    ) {
      id
      state
      taskTemplate {
        title
        level
      }
    }
  }

标签: graphqlnestjsprismaprisma-graphql

解决方案


推荐阅读