-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

5
  • Could you give an example of the actual input and the desired output? Commented Jan 2, 2020 at 23:10
  • @SwetankPoddar: Sure, Just updated the original post. Thanks! Commented Jan 2, 2020 at 23:16
  • @user85421: The code is in TypeScript. So, do you know how I could use "Long.valueOf()" in TypeScript. Thanks! Commented Jan 2, 2020 at 23:19
  • 1
    java != javascript Commented Jan 2, 2020 at 23:30
  • Sorry about the confusion. I tagged Java to highlight that the API implementation in Java is Long Commented Jan 3, 2020 at 16:47

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

3 Comments

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.
I am trying to convert it to Long which is like an object form of long
@vv1129 it's also a datatype that does not exist in JavaScript
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.

1 Comment

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.