【发布时间】:2021-10-29 19:30:43
【问题描述】:
我有这个 Apollo 查询:
currentUser: async (root, args) => {
const currentUser = await prisma.user.findUnique({
where: {id: Number(args.id)},
});
console.log(currentUser);
return currentUser;
},
在操场上我可以称之为:
query Query {
currentUser(id: 1) {
id
}
}
在 Apollo 服务器日志中显示:"
{
id: 1,
email: 'peter@**.nl',
name: 'Peter **',
password: '$2b$04$Dqo4LN3S5ZOnk1T1MyatOuijbvHpl281oDChHdEu1ZfEOyk7mjLqu'
}
type Query {
currentUser (id: Int!): User
}
但是当我尝试从我的 React 客户端调用查询时,我得到一个错误:
const ReturnCurrentUser = gql`
query Query {
currentUser(id: Int) {
id
}
}
`;
const {loading, error, data} = useQuery(ReturnCurrentUser, {variables: {id: 1}});
错误:
Int 不能表示非整数值:Int
【问题讨论】:
标签: reactjs apollo apollo-client react-apollo apollo-server