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:
|
yaacovCR
left a comment
There was a problem hiding this comment.
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.
| 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.
| expect(coerceOutputValue(1n)).to.equal(1n); | |
| expect(coerceOutputValue(1n)).to.equal(1); |
Assuming we take the change with respect to floats.
|
|
||
| expect(astFromValue(9007199254740993n, GraphQLString)).to.deep.equal({ | ||
| kind: 'StringValue', | ||
| value: '9007199254740993', |
There was a problem hiding this comment.
| 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. |
building on prior work: - #3109 - #3973 - #4088 - #4223 - #4276 This PR adds bigint support to: - GraphQLInt, including input/output coercion, throwing if out of bounds, and new default value programmatic default value to literal - GraphQLFloat, including input/output coercion, throwing if cannot be represented, including with any loss of precision. - GraphQLString, output coercion only, like number - GraphQLBoolean, output coercion only, like number - GraphQLID, output and input coercion, in parallel to number, and new default value programmatic default value to literal Also, for custom scalars: - updates the `defaultScalarValueToLiteral` to convert a `bigint` to an Int literal - updates for deprecated `astFromValue` for passthrough custom scalars, i.e. scalars that return `bigint` from coerceOutputValue/serialize, to convert `bigint` to an Int literal. cf. also #3913 Co-authored-by: Arda TANRIKULU <ardatanrikulu@gmail.com> Co-authored-by: jdecroock <decroockjovi@gmail.com> Co-authored-by: Hkmu <3169251+hkmu@users.noreply.github.com> Co-authored-by: xonx <119700621+xonx4l@users.noreply.github.com>
building on prior work: - #3109 - #3973 - #4088 - #4223 - #4276 This PR adds bigint support to: - GraphQLInt, including input/output coercion, throwing if out of bounds, and new default value programmatic default value to literal - GraphQLFloat, including input/output coercion, throwing if cannot be represented, including with any loss of precision. - GraphQLString, output coercion only, like number - GraphQLBoolean, output coercion only, like number - GraphQLID, output and input coercion, in parallel to number, and new default value programmatic default value to literal Also, for custom scalars: - updates the `defaultScalarValueToLiteral` to convert a `bigint` to an Int literal - updates for deprecated `astFromValue` for passthrough custom scalars, i.e. scalars that return `bigint` from coerceOutputValue/serialize, to convert `bigint` to an Int literal. cf. also #3913 Co-authored-by: Arda TANRIKULU <ardatanrikulu@gmail.com> Co-authored-by: jdecroock <decroockjovi@gmail.com> Co-authored-by: Hkmu <3169251+hkmu@users.noreply.github.com> Co-authored-by: xonx <119700621+xonx4l@users.noreply.github.com>
building on prior work: - #3109 - #3973 - #4088 - #4223 - #4276 This PR adds bigint support to: - GraphQLInt, including input/output coercion, throwing if out of bounds, and new default value programmatic default value to literal - GraphQLFloat, including input/output coercion, throwing if cannot be represented, including with any loss of precision. - GraphQLString, output coercion only, like number - GraphQLBoolean, output coercion only, like number - GraphQLID, output and input coercion, in parallel to number, and new default value programmatic default value to literal Also, for custom scalars: - updates the `defaultScalarValueToLiteral` to convert a `bigint` to an Int literal - updates for deprecated `astFromValue` for passthrough custom scalars, i.e. scalars that return `bigint` from coerceOutputValue/serialize, to convert `bigint` to an Int literal. cf. also #3913 Co-authored-by: Arda TANRIKULU <ardatanrikulu@gmail.com> Co-authored-by: jdecroock <decroockjovi@gmail.com> Co-authored-by: Hkmu <3169251+hkmu@users.noreply.github.com> Co-authored-by: xonx <119700621+xonx4l@users.noreply.github.com>
building on prior work: - #3109 - #3973 - #4088 - #4223 - #4276 This PR adds bigint support to: - GraphQLInt, including input/output coercion, throwing if out of bounds, and new default value programmatic default value to literal - GraphQLFloat, including input/output coercion, throwing if cannot be represented, including with any loss of precision. - GraphQLString, output coercion only, like number - GraphQLBoolean, output coercion only, like number - GraphQLID, output and input coercion, in parallel to number, and new default value programmatic default value to literal Also, for custom scalars: - updates the `defaultScalarValueToLiteral` to convert a `bigint` to an Int literal - updates for deprecated `astFromValue` for passthrough custom scalars, i.e. scalars that return `bigint` from coerceOutputValue/serialize, to convert `bigint` to an Int literal. cf. also #3913 Co-authored-by: Arda TANRIKULU <ardatanrikulu@gmail.com> Co-authored-by: jdecroock <decroockjovi@gmail.com> Co-authored-by: Hkmu <3169251+hkmu@users.noreply.github.com> Co-authored-by: xonx <119700621+xonx4l@users.noreply.github.com>
building on prior work: - #3109 - #3973 - #4088 - #4223 - #4276 This PR adds bigint support to: - GraphQLInt, including input/output coercion, throwing if out of bounds, and new default value programmatic default value to literal - GraphQLFloat, including input/output coercion, throwing if cannot be represented, including with any loss of precision. - GraphQLString, output coercion only, like number - GraphQLBoolean, output coercion only, like number - GraphQLID, output and input coercion, in parallel to number, and new default value programmatic default value to literal Also, for custom scalars: - updates the `defaultScalarValueToLiteral` to convert a `bigint` to an Int literal - updates for deprecated `astFromValue` for passthrough custom scalars, i.e. scalars that return `bigint` from coerceOutputValue/serialize, to convert `bigint` to an Int literal. cf. also #3913 Co-authored-by: Arda TANRIKULU <ardatanrikulu@gmail.com> Co-authored-by: jdecroock <decroockjovi@gmail.com> Co-authored-by: Hkmu <3169251+hkmu@users.noreply.github.com> Co-authored-by: xonx <119700621+xonx4l@users.noreply.github.com>
building on prior work: - #3109 - #3973 - #4088 - #4223 - #4276 This PR adds bigint support to: - GraphQLInt, including input/output coercion, throwing if out of bounds, and new default value programmatic default value to literal - GraphQLFloat, including input/output coercion, throwing if cannot be represented, including with any loss of precision. - GraphQLString, output coercion only, like number - GraphQLBoolean, output coercion only, like number - GraphQLID, output and input coercion, in parallel to number, and new default value programmatic default value to literal Also, for custom scalars: - updates the `defaultScalarValueToLiteral` to convert a `bigint` to an Int literal - updates for deprecated `astFromValue` for passthrough custom scalars, i.e. scalars that return `bigint` from coerceOutputValue/serialize, to convert `bigint` to an Int literal. cf. also #3913 Co-authored-by: Arda TANRIKULU <ardatanrikulu@gmail.com> Co-authored-by: jdecroock <decroockjovi@gmail.com> Co-authored-by: Hkmu <3169251+hkmu@users.noreply.github.com> Co-authored-by: xonx <119700621+xonx4l@users.noreply.github.com>
building on prior work: - #3109 - #3973 - #4088 - #4223 - #4276 This PR adds bigint support to: - GraphQLInt, including input/output coercion, throwing if out of bounds, and new default value programmatic default value to literal - GraphQLFloat, including input/output coercion, throwing if cannot be represented, including with any loss of precision. - GraphQLString, output coercion only, like number - GraphQLBoolean, output coercion only, like number - GraphQLID, output and input coercion, in parallel to number, and new default value programmatic default value to literal Also, for custom scalars: - updates the `defaultScalarValueToLiteral` to convert a `bigint` to an Int literal - updates for deprecated `astFromValue` for passthrough custom scalars, i.e. scalars that return `bigint` from coerceOutputValue/serialize, to convert `bigint` to an Int literal. cf. also #3913 Co-authored-by: Arda TANRIKULU <ardatanrikulu@gmail.com> Co-authored-by: jdecroock <decroockjovi@gmail.com> Co-authored-by: Hkmu <3169251+hkmu@users.noreply.github.com> Co-authored-by: xonx <119700621+xonx4l@users.noreply.github.com>
building on prior work: - #3109 - #3973 - #4088 - #4223 - #4276 This PR adds bigint support to: - GraphQLInt, including input/output coercion, throwing if out of bounds, and new default value programmatic default value to literal - GraphQLFloat, including input/output coercion, throwing if cannot be represented, including with any loss of precision. - GraphQLString, output coercion only, like number - GraphQLBoolean, output coercion only, like number - GraphQLID, output and input coercion, in parallel to number, and new default value programmatic default value to literal Also, for custom scalars: - updates the `defaultScalarValueToLiteral` to convert a `bigint` to an Int literal - updates for deprecated `astFromValue` for passthrough custom scalars, i.e. scalars that return `bigint` from coerceOutputValue/serialize, to convert `bigint` to an Int literal. cf. also #3913 Co-authored-by: Arda TANRIKULU <ardatanrikulu@gmail.com> Co-authored-by: jdecroock <decroockjovi@gmail.com> Co-authored-by: Hkmu <3169251+hkmu@users.noreply.github.com> Co-authored-by: xonx <119700621+xonx4l@users.noreply.github.com>
building on prior work: - #3109 - #3973 - #4088 - #4223 - #4276 This PR adds bigint support to: - GraphQLInt, including input/output coercion, throwing if out of bounds, and new default value programmatic default value to literal - GraphQLFloat, including input/output coercion, throwing if cannot be represented, including with any loss of precision. - GraphQLString, output coercion only, like number - GraphQLBoolean, output coercion only, like number - GraphQLID, output and input coercion, in parallel to number, and new default value programmatic default value to literal Also, for custom scalars: - updates the `defaultScalarValueToLiteral` to convert a `bigint` to an Int literal - updates for deprecated `astFromValue` for passthrough custom scalars, i.e. scalars that return `bigint` from coerceOutputValue/serialize, to convert `bigint` to an Int literal. cf. also #3913 Co-authored-by: Arda TANRIKULU <ardatanrikulu@gmail.com> Co-authored-by: jdecroock <decroockjovi@gmail.com> Co-authored-by: Hkmu <3169251+hkmu@users.noreply.github.com> Co-authored-by: xonx <119700621+xonx4l@users.noreply.github.com>
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
valueToASTeven 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
valueToLiteralhowever, 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.