-
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export function isInteger(value: unknown): value is number | bigint { | ||
const valueTypeOf = typeof value; | ||
if (valueTypeOf === 'number') { | ||
return Number.isInteger(value); | ||
} | ||
return valueTypeOf === 'bigint'; | ||
} | ||
|
||
export function isNumeric(value: unknown): value is number | bigint { | ||
const valueTypeOf = typeof value; | ||
if (valueTypeOf === 'number') { | ||
return Number.isFinite(value); | ||
} | ||
return valueTypeOf === 'bigint'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -31,6 +31,16 @@ describe('astFromValue', () => { | |||||
value: false, | ||||||
}); | ||||||
|
||||||
expect(astFromValue(0n, GraphQLBoolean)).to.deep.equal({ | ||||||
kind: 'BooleanValue', | ||||||
value: false, | ||||||
}); | ||||||
|
||||||
expect(astFromValue(1n, GraphQLBoolean)).to.deep.equal({ | ||||||
kind: 'BooleanValue', | ||||||
value: true, | ||||||
}); | ||||||
|
||||||
expect(astFromValue(undefined, GraphQLBoolean)).to.deep.equal(null); | ||||||
|
||||||
expect(astFromValue(null, GraphQLBoolean)).to.deep.equal({ | ||||||
|
@@ -65,6 +75,16 @@ describe('astFromValue', () => { | |||||
value: '123', | ||||||
}); | ||||||
|
||||||
// Note: outside the bounds of 32bit signed int. | ||||||
expect(() => astFromValue(9007199254740991, GraphQLInt)).to.throw( | ||||||
'Int cannot represent non 32-bit signed integer value: 9007199254740991', | ||||||
); | ||||||
|
||||||
// Note: outside the bounds of 32bit signed int as BigInt. | ||||||
expect(() => astFromValue(9007199254740991n, GraphQLInt)).to.throw( | ||||||
'Int cannot represent non 32-bit signed integer value: 9007199254740991', | ||||||
); | ||||||
|
||||||
expect(astFromValue(1e4, GraphQLInt)).to.deep.equal({ | ||||||
kind: 'IntValue', | ||||||
value: '10000', | ||||||
|
@@ -111,6 +131,11 @@ describe('astFromValue', () => { | |||||
kind: 'FloatValue', | ||||||
value: '1e+40', | ||||||
}); | ||||||
|
||||||
expect(astFromValue(9007199254740993n, GraphQLFloat)).to.deep.equal({ | ||||||
kind: 'IntValue', | ||||||
value: '9007199254740993', | ||||||
}); | ||||||
}); | ||||||
|
||||||
it('converts String values to String ASTs', () => { | ||||||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There is a loss of precision when converting a bigint to a float |
||||||
}); | ||||||
|
||||||
expect(astFromValue(undefined, GraphQLString)).to.deep.equal(null); | ||||||
}); | ||||||
|
||||||
|
@@ -163,6 +193,11 @@ describe('astFromValue', () => { | |||||
value: 'VA\nLUE', | ||||||
}); | ||||||
|
||||||
expect(astFromValue(9007199254740993n, GraphQLID)).to.deep.equal({ | ||||||
kind: 'IntValue', | ||||||
value: '9007199254740993', | ||||||
}); | ||||||
|
||||||
// Note: IntValues are used when possible. | ||||||
expect(astFromValue(-1, GraphQLID)).to.deep.equal({ | ||||||
kind: 'IntValue', | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Assuming we take the change with respect to floats.