【问题标题】:Defining entities in nestjs graphql code first approach with custom field results in error使用自定义字段在nestjs graphql代码优先方法中定义实体会导致错误
【发布时间】: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


    【解决方案1】:

    哦,这看起来很熟悉。我在我的项目中遇到了类似的错误。 尝试在 FormDataValue 类上添加 @ObjectType() 装饰器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-21
      • 2020-07-14
      • 2021-10-30
      • 2020-08-17
      相关资源
      最近更新 更多