Ref数组的TypeGraphQL和Typegoose输入类型
我很难找到解释如何处理TypeGraphQL和Typegoose对象引用数组的资源 鉴于以下模型:Ref数组的TypeGraphQL和Typegoose输入类型,graphql,typegraphql,typegoose,Graphql,Typegraphql,Typegoose,我很难找到解释如何处理TypeGraphQL和Typegoose对象引用数组的资源 鉴于以下模型: @ObjectType({description: "Blog Tag Model"}) export class BlogTag { @Field(() => ID) id: number; @Field(_type => String) @Property({required: true, unique: true, index: true,
@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>[];
}
我想要实现的是为BlogPost
模型提供存储BlogTag
模型的引用/obejctid数组的可能性
我不熟悉这个框架,我不知道这是否是一个好的实践。
如何创建一个接受ID数组的InputType?您需要使用
@InputType
创建一个单独的BlogTagInput
,或者查看常见问题解答以获得一些方便的“doatyourownrisk”解决方法:
谢谢,最后我找不到更好的解决方案,所以我创建了一个BlogTagInput@inputype,并将BlogPost-input-tags更改为:@Field(_type=>[BlogTagInput],{nullable:'itemsAndList'})@Property({ref:BlogTag})tag:BlogTagInput[];
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?