Skip to content

Commit

Permalink
Allow for serializing int as BigInt
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Oct 11, 2024
1 parent 50607e4 commit 99dca99
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/type/__tests__/scalars-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ describe('Type System: Specified scalar types', () => {
expect(serialize(123)).to.equal('123');
expect(serialize(0)).to.equal('0');
expect(serialize(-1)).to.equal('-1');
expect(serialize(BigInt(123))).to.equal('123');

const valueOf = () => 'valueOf ID';
const toJSON = () => 'toJSON ID';
Expand Down
2 changes: 1 addition & 1 deletion src/type/scalars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export const GraphQLID = new GraphQLScalarType<string>({
if (typeof coercedValue === 'string') {
return coercedValue;
}
if (Number.isInteger(coercedValue)) {
if (Number.isInteger(coercedValue) || typeof coercedValue === 'bigint') {
return String(coercedValue);
}
throw new GraphQLError(
Expand Down

0 comments on commit 99dca99

Please sign in to comment.