-
Notifications
You must be signed in to change notification settings - Fork 137
Fix BigInt's external representation to string #795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,12 +102,12 @@ describe('BigInt', () => { | |
const { data, errors } = await graphql(schema, validQuery); | ||
expect(errors).toEqual(undefined); | ||
expect(data).toEqual({ | ||
a: 2n, | ||
b: 2147483647n, | ||
c: 2147483648n, | ||
d: 2147483649n, | ||
e: 439857257821346n, | ||
f: 9007199254740993n, | ||
a: '2', | ||
b: '2147483647', | ||
c: '2147483648', | ||
d: '2147483649', | ||
e: '439857257821346', | ||
f: '9007199254740993', | ||
}); | ||
}); | ||
it('4', async () => { | ||
|
@@ -120,9 +120,9 @@ describe('BigInt', () => { | |
); | ||
expect(errors).toEqual(undefined); | ||
expect(data).toEqual({ | ||
a: { result: 2147483647n }, | ||
b: { result: 9007199254740991n }, | ||
d: { result: 2n }, | ||
a: { result: '2147483647' }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we avoid using primitive bigint values? Adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than implicitly intending to lose precision, it's better to let clients handle string correctly. Consider the case of using a long int as an id field. Even considering the JS clients, they may prefer string over numbers with lost precision as the In the case of protobufjs, they already have the correct cast for the But since they doesn't use the bigint primitive yet, it will be fallback empty ( (This problem is already being reproduced in the official example of graphql-mesh, and we should fix this in graphql-mesh anyway. Need a patch for graphql-scalars or protobufjs I think) This is not graphql related and is a specific client issue, but considering that bigint hasn't been used in JavaScript widely, it's potentially more problematic than string. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, the patch would be avoided some cases. it makes the whole library incompatible in sandboxing environments or workers where global scope cannot be modified. |
||
b: { result: '9007199254740991' }, | ||
d: { result: '2' }, | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for using test command with a suite name like:
yarn test BigInt