我正在编写一个内置于 TypeScript 和 TypeGoose 的 CRUD API。
我收到一条错误消息,
CannotDetermineGraphQLTypeError:无法确定“用户”类的“_id”的 GraphQL 输出类型。用作其 TS 类型或显式类型的值是用适当的装饰器装饰还是适当的输出值?
我有一个用户实体。
import { Field, ObjectType } from 'type-graphql';
import { ObjectId } from 'mongodb';
import { prop as Property, getModelForClass } from '@typegoose/typegoose';
@ObjectType()
export class User {
@Field()
readonly _id: ObjectId;
@Field()
@Property({ required: true })
email: string;
@Field({ nullable: true })
@Property()
nickname?: string;
@Property({ required: true })
password: string;
constructor(email: string, password: string) {
this.email = email;
this.password = password;
}
}
export const UserModel = getModelForClass(User);
这就是我的查询解析器的样子。
@Query(() => [User])
async users() {
const users = await UserModel.find();
console.log(users);
return users;
}
我该如何解决这个问题?好像 TypeGraphQL 不明白 MongoDB ID 是什么?