GraphQL错误:预期类型为Int。整数不能表示非整数值

时间:2020-02-11 09:17:20

标签: reactjs error-handling graphql react-apollo apollo-client

我目前正在与GraphQL学习Apollo来学习React,但有一个问题,我无法在线找到答案: 我已经完成了一个表单来为我的mongoDB发送数据,并且我有这个查询:

const addContactMutation = gql`
    mutation($name: String!, $address: String!, $vat: Int!, $zip: String!, $email: String!, $contact: Int!){
        addContact(name: $name, address: $address, vat: $vat, zip: $zip, email: $email, contact: $contact){
            name
            vat
            email
        }
    }
`

但是,我的$vat$contact是很大的数字,在提交表格时,我收到此错误:

变量“ $ vat”的值无效“ 232214336”;预期类型为Int。整数不能代表非整数值

我应该使用哪种类型?

1 个答案:

答案 0 :(得分:2)

String不太大,最大int数为232214336

9007199254740991

我认为问题在于,当由于错误提示console.log(Number.MAX_SAFE_INTEGER);而需要一个Int值时,您已经传递了一个字符串值"232214336",因此您需要在传递之前或传递时将值转换为整数使用Expected type Int

进行突变的变量
parseInt()
相关问题