【发布时间】:2022-08-20 04:38:03
【问题描述】:
如documentation 中所述,我正在使用 NestJs 和 GraphQL 以及代码优先方法。它可以正常工作,直到我必须在作为对象数组的实体中使用自定义字段。
@InputType(\'FormAnswerTaskDataInput\')
@ObjectType()
export class FormAnswerTaskData extends BaseTaskData {
@Field()
id: string;
@Field((type) => Int)
order: number;
@Field()
title: string;
@Field()
widget: string;
@Field((type) => Boolean)
required: boolean;
@Field((type) => [FormDataValue], { nullable: \'itemsAndList\' })
values: FormDataValue[];
}
@InputType()
class FormDataValue {
@Field()
value: string;
}
当我尝试运行它时,我收到以下错误:
Error: Cannot determine a GraphQL output type for the \"values\". Make sure your class is decorated with an appropriate decorator.
仅当我添加该行时才会引发此错误
@Field((type) => [FormDataValue], { nullable: \'itemsAndList\' })
values: FormDataValue[];
如果我使用没有上述行的代码,那么它可以完美运行。
标签: graphql nestjs code-first