我目前正在与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。整数不能代表非整数值
我应该使用哪种类型?
答案 0 :(得分:2)
String
不太大,最大int数为232214336
9007199254740991
我认为问题在于,当由于错误提示console.log(Number.MAX_SAFE_INTEGER);
而需要一个Int值时,您已经传递了一个字符串值"232214336"
,因此您需要在传递之前或传递时将值转换为整数使用Expected type Int
parseInt()