我使用typegoose + type-graphql
我尝试通过_id查找管理员,但在Graphiql中出错:
“类型为\“ AdminSchema \”的预期值,但得到:{_id:{_bsontype:> \“ ObjectID \”,id:},>登录名:\“ admin \”}。“
这是我的猫鼬+ Graphql模式:
@ObjectType()
class AdminSchema extends Typegoose {
@Field()
@prop()
login?: string;
}
@Resolver(AdminSchema)
export default class AdminResolver {
@Query(returns => AdminSchema)
admin() {
return Admin.findOne({ login: 'admin' })
}
}
const Admin = new AdminSchema().getModelForClass(AdminSchema, {
schemaOptions: { collection: 'admin' }
});
如何将返回值转换为“ AdminSchema”类型?