我正在尝试将 typegoose 与 graphql 一起使用。我在另一个对象中有一个嵌套对象列表。我已经定义了类如下
@ObjectType()
export class ChildClass {
@prop()
@Field({ nullable: true })
someField: string;
@prop()
@Field({ nullable: true })
anotherField: string;
}
@ObjectType()
@modelOptions()
export class ParentClass extends Typegoose {
@prop()
@Field(() => String)
someField: string;
@prop()
@Field(() => [ChildClass], { nullable: 'itemsAndList' })
children: ChildClass[];
}
当我调用以下查询时
query {
parentClass {
someField
children {
someField
anotherField
}
}
}
它总是给我null
孩子的someField
和anotherField
。但是,如果我使用猫鼬而不是 typegoose,它可以正常工作。MongoDb 在使用 typegoose 时返回正常。它转换为 graphql 很不稳定。
我在这里想念什么?