简体   繁体   English

使用自定义字段在nestjs graphql 代码优先方法中定义实体导致错误

[英]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.

相关问题 使用代码优先方法在 NestJS 中使用 GraphQL 模型出错 - Getting error with GraphQL model in NestJS, using code-first approach GraphQL 架构未使用 NestJS 更新(代码优先方法) - GraphQL Schema not updated with NestJS (code-first approach) 在 NestJS 中实现 GraphQL 全局 Object 识别(代码优先方法) - Implementing GraphQL Global Object Identification in NestJS (code-first approach) NestJS:在使用 GraphQL 和 MongoDB 定义 InputType 和 ObjectType 字段时,我们可以使用自定义类型和类吗 - NestJS: Can we use custom Type and Classes when defining InputType and ObjectType Field with GraphQL & MongoDB NestJS + GraphQL - @InputType 中的可选数据(代码优先) - NestJS + GraphQL - optional data in @InputType (code first) 如何使用 GraphQL 在 NestJS 中创建自定义字段验证装饰器 - How to create custom field validation decorators in NestJS with GraphQL NestJs Graphql(CLI 插件代码优先)+ Mongoose 无法解析“../../../../mongoose” - NestJs Graphql (Code first with CLI Plugin)+ Mongoose cannot resolve "../../../../mongoose" NestJS Schema 先 GraphQL 序列化 - NestJS Schema First GraphQL Serialization 如何使用代码优先方法在 graphql 中创建更复杂的类型 - How to create more complex types in graphql using code first approach NestJS GraphQL 自定义参数类型 - NestJS GraphQL custom argument type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM