[英]Defining entities in nestjs graphql code first approach with custom field results in error
I am using NestJs along with GraphQL with code-first approach as explained in the documentation .我正在使用 NestJs 和 GraphQL 以及文档中解释的代码优先方法。 It works correctly till the time I have to use a custom field in an entity which is an array of objects.它可以正常工作,直到我必须在作为对象数组的实体中使用自定义字段。
@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;
}
When I try to run this, I get the following error:当我尝试运行它时,我收到以下错误:
Error: Cannot determine a GraphQL output type for the "values". Make sure your class is decorated with an appropriate decorator.
This error is only thrown when I add the line仅当我添加该行时才会引发此错误
@Field((type) => [FormDataValue], { nullable: 'itemsAndList' })
values: FormDataValue[];
If I use the code without the above line, then it works perfectly.如果我使用没有上述行的代码,那么它可以完美运行。
Oh this looks familiar.哦,这看起来很熟悉。 I had got a similar error in my project.我在我的项目中遇到了类似的错误。 Try adding a @ObjectType()
decorator on your FormDataValue
class.尝试在FormDataValue
class 上添加@ObjectType()
装饰器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.