graphql-js icon indicating copy to clipboard operation
graphql-js copied to clipboard

Support for bigint in ID

Open vwkd opened this issue 2 years ago • 1 comments

It's desirable to represent an ID on the server as a bigint instead of a number.

Currently, the ID scalar type supports serializing number to string, but not bigint.

I'd like to see support for serialization of bigint to string similar to number.

I think it would require changing this code https://github.com/graphql/graphql-js/blob/d766c8eb34fb03c5ee63c51380f2b012924e970c/src/type/scalars.ts#L225-L227 to

if (Number.isInteger(coercedValue) || typeof coercedValue == "bigint") { 
  return String(coercedValue); 
}

vwkd avatar Jun 18 '23 09:06 vwkd

This is correct, the spec supports 128-bit numbers https://spec.graphql.org/draft/#sec-ID

JoviDeCroock avatar Oct 11 '24 07:10 JoviDeCroock