【发布时间】:2021-02-12 20:46:51
【问题描述】:
我正在尝试设置我的 graphql 解析器来处理一组对象,但无法配置 @Args 装饰器。
我创建了自己的 ArgsType
import { ArgsType, Field, Int, ObjectType } from '@nestjs/graphql';
@ArgsType() // to be used as type in the resolver
@ObjectType() // for schema generation
export class Club {
@Field(type => String)
president: string;
@Field(type => Int)
members?: number;
}
添加单个俱乐部的解析器工作得很好!
@Query(() => Int)
async addClub(@Args() club: Club) {
// handle stuff
}
但是如果我想给一个这样的俱乐部数组
@Query(() => Int)
async addClubs(@Args({name: 'clubs', type: () => [Club]}) clubs: Array<Club>) {
// handle stuff
}
nest 启动时会报错
UnhandledPromiseRejectionWarning: Error: Cannot determine a GraphQL input type for the "clubs". Make sure your class is decorated with an appropriate decorator.
虽然我可以使用这样的字符串数组
@Query(() => [String])
async addStrings(@Args({ name: 'clubs', type: () => [String], }) clubs: Array<string>) {
// handle stuff
}
我很确定应该有一个简单的解决方案,但不知道从哪里开始。
【问题讨论】:
标签: typescript graphql nestjs