【发布时间】:2021-01-09 13:25:57
【问题描述】:
我的解析器:
@Resolver()
class UserResolver{
@Query(() => Boolean)
async userExists(@Arg('email') email: string) {
const user = await User.findOne({email});
return user ? true : false;
}
@Mutation(() => LoginObject)
async login(
@Arg('email') email: string,
@Arg('password') password: string
): Promise<LoginObject>{
const user = await User.findOne({email});
if(!user) throw new Error('User not found!');
const match = await cmp(password, user.password);
if(!match) throw new Error('Passwords do not match!');
return {
accessToken: createAccessToken(user),
user
};
}
}
和对象类型:
import {ObjectType, Field} from "type-graphql";
import User from "../entity/User";
@ObjectType()
class LoginObject {
@Field()
user: User;
@Field()
accessToken: string;
}
我得到的错误是 - 错误:无法确定“LoginObject”类的“用户”的 GraphQL 输出类型。用作其 TS 类型或显式类型的值是用适当的装饰器装饰的还是适当的输出值?
如何让它发挥作用?
【问题讨论】:
-
你可能需要用
@ObjectType()装饰器注释类型User -
是的,我愿意。完全忘记了,谢谢
-
@Eldar 你能把你的评论作为答案吗?
标签: node.js typescript graphql typegraphql