GraphQL : Support for BigInt / 64 bits integer

Moved from GitHub dgraph/5459

Posted by Miaourt:

Hi Dgraph team, pretty new to Dgraph so excuse my potential incomprehensions.

Experience Report

I had a discussion with @pawanrawal on Slack over a efficient way to support 64 bits integer via the GraphQL endpoint, which isn’t standard since the only “Int” type supported is 32 bits.

Storing it as a string would have been an option but I need to be able to index with this integer, and do simple operations like ascending / descending sorting or value comparisons, which is something impossible with a string.

What you wanted to do

As you did with DateTime or even ID, storing a “custom type” could be done too, by returning an hex-coded string representing the 64 bits value as suggested Pawan, and still allow us to store the value efficiently and do database operations on it.

Using Javascript’s standard way of returning BigInt could be done too, by suffixing the value with n

Any external references to support your case

https://caniuse.com/#feat=bigint
https://v8.dev/features/bigint

2 Likes

pawanrawal commented :

Thanks. We have added this into our internal discussions. I’ll repost here when we pick it up and start further scoping of this feature.

Bumping it a bit, as it’s really something I wanna see :o

Any updates here, @pawan ? Dgraph supports 64-bit integers, right? Can we expose that via GraphQL?

Yeah, this shouldn’t be hard. We didn’t prioritize it as we didn’t have a lot of users asking for this. Let me get this prioritized, it should be an easy addition.

Yeah, we can have a custom scalar for Int64 and achieve this like we already do for DateTime.

1 Like

@harshil_goel I recall having heard that you created a BigInt support for Dgraph? Is this the same requirement just being extended to GraphQL ?

Nope, that was BigFloat. Dgraph already supports int64 (https://dgraph.io/docs/query-language/#schema-types). That is int in GraphQL± maps to an int64 whereas int in GraphQL maps to int32 because the spec specifies that. We just have to support 64 bit integers in GraphQL.

1 Like

Hi Pawan. I am guessing Dgraph now supports bigint/int64? We have transactional ids that we need to save in integer format for indexing .