-
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
astFromValue - JavaScript BigInt support #4088
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for compassionate-pike-271cb3 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Hi @ardatan, 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.
@saihaj Isn't it for |
Oh I see what you mean, its like we are coercing |
In terms of default values, that use case should probably be re-examined after #3814 lands, which should hopefully be soon! We are halfway-through the stack. I suppose we will need to support conversion from BigInt to Int/Float when possible if the received JSON is parsed with a BigInt supporting parser. I think it probably would require some discussion at the WG in terms of whether to include it, but I would be in favor. |
In terms of output, I am of two minds in terms of whether we should be supporting conversion from bigint to int, because that means that a custom scalar probably should have been used, in case the value was greater than the int threshold. Maybe it's better to fail overall? For conversion to string or id, I imagine we would want to support it, I can't see why not? |
2268937
to
e78d663
Compare
@@ -96,6 +121,11 @@ describe('astFromValue', () => { | |||
value: '123', | |||
}); | |||
|
|||
expect(astFromValue(9007199254740993n, GraphQLFloat)).to.deep.equal({ |
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.
The change in type of this test is because astFromValue is not safe, set to be replaced by valueToLiteral()
for all remaining uses in #3814
But a bigint of sufficient size, -- as far as I know -- cannot be converted to a JS float.
We also in this PR do not properly handle GraphQLFloat scalar parsing and serialization of small BigInts, I will push a failing test to demonstrate what I mean.
We also probably should update the logic within the new valueToLiteral()
utility. It's possible that overall we can just delay landing this PR until after #3814
This PR adds support for BigInt values to
astFromValue
.It coerces whenever possible instead of failing.
This will also allow custom scalars like https://the-guild.dev/graphql/scalars/docs/scalars/big-int to get a
BigInt
as a default value. Similar to #4085