简体   繁体   中英

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 . 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM