GraphQL error: Expected type Int. Int cannot represent non-integer value
Solution 1
232214336
is not so big, the max int number is 9007199254740991
console.log(Number.MAX_SAFE_INTEGER);
I think the problem is you've passed a string value "232214336"
when an Int value is expected as the error says Expected type Int
, so you need to convert the value to an integer before or when passing variables to the mutation using parseInt()
addContact({ variables: { vat: parseInt(vat, 10), contact: parseInt(contact, 10), ... } })
Solution 2
This error also happens when a database field that is typed as an integer, contains a value of NULL, and that field is returned by your GraphQL query. One way to fix this, is to set up your database to give integer fields a default value so that they are never NULL when the row is created.
Related videos on Youtube
JS_LnMstr
A self-taught Frontend developer always trying to learn new technologies!
Updated on June 04, 2022Comments
-
JS_LnMstr almost 2 years
I'm currently learning
GraphQL
withApollo
for React and I have a question that I can't find the answer online: I've done a form to send data for my mongoDB and I have this query: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 } } `
However, my
$vat
and$contact
are big numbers and when submit the form I receive this error:Variable "$vat" got invalid value "232214336"; Expected type Int. Int cannot represent non-integer value
Which type should I use for that?
-
PositiveGuy over 3 yearswhat if the bigint is that big, you can't just parseInt so what do you do for graphQL for true bigint values?
-
Fraction over 3 years@PositiveGuy you can use a custom scalar type or a bigint-graphql js library