【发布时间】:2023-01-07 05:32:08
【问题描述】:
我在 Mongo 中有这样的模型:
{
...
settings: {
positions: [
{
column: number,
row: number,
buttonId: (ref to Button model)
}
]
}
}
在架构中:
@Schema({ _id: false })
@ObjectType()
class Settings {
@Field(() => [Object])
@Prop({ type: [{ column: Number, row: Number, buttonId: String }] })
positions: { column: number; row: number; buttonId: string };
}
const SettingsSchema = SchemaFactory.createForClass(Settings);
@Schema()
@ObjectType()
export class Keyboard {
@Field(() => ID)
_id: string;
@Field(() => User)
@Prop({ type: mongoose.Schema.Types.ObjectId, ref: 'User' })
author: User;
@Field(() => Group, { nullable: true })
@Prop({ type: mongoose.Schema.Types.ObjectId, ref: 'Group' })
group?: Group;
@Field(() => Settings, { nullable: true })
@Prop({ type: SettingsSchema })
settings?: Settings;
}
export const KeyboardSchema = SchemaFactory.createForClass(Keyboard);
我该如何解决?
需要使用 GraphQl 在我的模式中使用嵌套对象。 @Field 装饰器不能正确处理嵌套对象字段
【问题讨论】:
标签: javascript graphql nestjs mongoose-schema nest