-1

The backend API implementation is expecting an array of Long .

I need to pass the value through front-end which is a GraphQL implementation. Initially I have the value as a string and want to convert it to an array of Long so that it is compatible with the API. I have tried the following:

input1 = [JSON.parse(input1)]

The desired payload should be as follows where 140 is a "Long"

"rolls": [140]

I currently see my graphQL query variables as follows where 140 is a string.

rolls: 140

Currently, I am seeing the GraphQL error: enter image description here

vv1129
  • 37
  • 1
  • 1
  • 6

2 Answers2

2

use Number to convert value from string to number

const someValueStr = "140";
const someValueNum = Number(someValue);

in JavaScript there is number type not long or double or int

Ali Faris
  • 17,754
  • 10
  • 45
  • 70
  • I did try this, but am still seeing the same GraphQL error as I believe it would work if the API implementation expected a primitive data type like int, float, long, etc. – vv1129 Jan 03 '20 at 04:50
  • I am trying to convert it to **Long** which is like an object form of **long** – vv1129 Jan 03 '20 at 04:57
  • @vv1129 it's also a datatype that does not exist in JavaScript – VLAZ Jan 03 '20 at 08:18
1

Typescript (the whole javascript actually) has just one data type for numbers, i.e Number, and they store numbers in 64 bits (or double-precision floating point format).

There is a library called BigInteger.js which can help you to represent numbers bigger than what javascript supports.

Swetank Poddar
  • 1,257
  • 9
  • 23
  • Thanks for your help. But, I've had no luck either with Number or BigInt and still seeing the same error that I posted above. – vv1129 Jan 03 '20 at 05:21