-
Notifications
You must be signed in to change notification settings - Fork 2k
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
BigInt support in scalars #4276
Conversation
✅ Deploy Preview for compassionate-pike-271cb3 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Hi @JoviDeCroock, I'm @github-actions bot happy to help you with this PR 👋 Supported commandsPlease post this commands in separate comments and only one per comment:
|
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.
Would be great to get this in. Some comments inline are with respect to how to handle bigint => float
In terms of valueToLiteral()
, I think it can be upgrade to handle bigint in the same way as astFromValue
. valueToLiteral
is a typed function that ends up calling the individual scalar .valueToLiteral()
methods just like astFromValue()
and so when supplied a bigint someBigInt
like so: valueToLiteral(someBigInt, GraphQLInt)
, it would call GraphQLInt.valueToLiteral()
and the idea would be that this should work as long as the bigint can be coerced.
This would not be about adding a bigint literal type.
@@ -280,6 +283,7 @@ describe('Type System: Specified scalar types', () => { | |||
expect(coerceOutputValue('-1.1')).to.equal(-1.1); | |||
expect(coerceOutputValue(false)).to.equal(0.0); | |||
expect(coerceOutputValue(true)).to.equal(1.0); | |||
expect(coerceOutputValue(1n)).to.equal(1n); |
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.
expect(coerceOutputValue(1n)).to.equal(1n); | |
expect(coerceOutputValue(1n)).to.equal(1); |
Assuming we take the change with respect to floats.
@@ -143,6 +168,11 @@ describe('astFromValue', () => { | |||
kind: 'NullValue', | |||
}); | |||
|
|||
expect(astFromValue(9007199254740993n, GraphQLString)).to.deep.equal({ | |||
kind: 'StringValue', | |||
value: '9007199254740993', |
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.
value: '9007199254740993', | |
value: '9007199254740992', |
There is a loss of precision when converting a bigint to a float
I think typo => |
Taking a step back:
Just some longer thoughts, meant to rehearse my understanding of Lee's diagram from the default value PR. |
Supersedes #4088
Resolves #3913
This adds support for BigInt values when we serialize a response value from JS to send over the wire.
For Input Values:
This also adds support in
valueToAST
even though it's deprecated because BigInt support has always been in the spec when it comes to the ID Scalar.I've tried adding BigInt to
valueToLiteral
however, for that we'd need to expand the spec to i.e. have an identifier for BigInt as currently we don't really have a way to represent it so we have to treat it like it is a regular number.