我很难找到资源,这说明了如何使用TypeGraphQL和Typegoose来处理对对象的一系列引用。
鉴于以下模式:
@ObjectType({description: "Blog Tag Model"})
export class BlogTag {
@Field(() => ID)
id: number;
@Field(_type => String)
@Property({required: true, unique: true, index: true, trim: true })
name: string;
}
@ObjectType({ description: "Blog post model" })
export class BlogPost {
@Field(() => ID)
id: number;
@Field()
@Property({required: true})
title: string;
@Field()
@Property({required: true})
description: string;
@Field(_type => [BlogTag], {nullable: false})
@Property({default: [], ref: 'BlogTag'})
tags: Ref<BlogTag>[];
}
@InputType({ description: "Blog post input" })
export class BlogPostInput implements Partial<BlogPost>{
@Field()
@Property()
title: string;
@Field()
@Property()
description: string;
// Here is the problem / question
@Field(_type => [BlogTag], {nullable: false})
@Property({ref: BlogTag})
tags: Ref<BlogTag>[];
}这是为此代码获得的错误:
CannotDetermineGraphQLTypeError: Cannot determine GraphQL input type for 'tags' of 'BlogPostInput' class. Is the value, that is used as its TS type or explicit type, decorated with
a proper decorator or is it a proper input value?我想要实现的是给BlogPost模型提供存储BlogTag模型的引用/ObejctID数组的可能性。
我是这个框架的新手,我不知道这是否是一个很好的实践。如何创建接受ID数组的InputType?
发布于 2021-02-01 13:08:00
您需要使用BlogTagInput创建一个单独的@InputType,或者检查FAQ以找到一些方便的、但“做好准备”的解决方法:
https://stackoverflow.com/questions/65982685
复制相似问题