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.