reactjs - Int 不能表示非整数值:Int
问题描述
我有这个阿波罗查询:
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
解决方案
看起来我的解析器错了:
const ReturnCurrentUser = gql`
query currentUser($id: Int!) {
currentUser(id: $id) {
id
}
}
`;
解决了这个问题。
推荐阅读
- flutter - 当用户水平拖动时显示带有额外图标的 Flutter ListTile
- server - 在 Visual Studio 2019 上将 asp.net mvc 项目发布到远程服务器时出错
- tkinter - 用于智能合约事件处理程序的 Tkinter GUI
- python - 如何在输入中的两件事之间用python打印一些东西
- django - Django ORM注释计数项目并按特定顺序排序?
- reactjs - 在 react native 中设置视图的 backgroundColor 覆盖了另一个元素
- wordpress - WP:提交后立即从表单值显示cookie
- yaml - 从 dbt yaml 文件中的 md 文件引用表值
- asp.net - 如何在每天一次的特定时间运行 asp.net 控制器方法
- java - Wicket 9 和弹出窗口(非模态)