【问题标题】:Int cannot represent non-integer value: IntInt 不能表示非整数值:Int
【发布时间】: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


    【解决方案1】:

    看来我的解析器出错了:

    const ReturnCurrentUser = gql`
      query currentUser($id: Int!) {
        currentUser(id: $id) {
          id
        }
      }
    `;
    

    修复了问题。

    【讨论】:

      猜你喜欢
      • 2023-03-13
      • 2023-03-17
      • 2017-12-12
      • 1970-01-01
      • 2021-03-31
      • 1970-01-01
      • 2021-12-04
      • 2011-12-25
      • 1970-01-01
      相关资源
      最近更新 更多