-
Notifications
You must be signed in to change notification settings - Fork 134
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
fix: Unix timestamps are not serialized correctly for scalar DateTime #2141
base: master
Are you sure you want to change the base?
Changes from 6 commits
1e99e7d
b25f6da
9ebe318
cac243a
53462c4
46db488
1b31c93
00ed44b
7a116ad
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 |
---|---|---|
|
@@ -28,7 +28,7 @@ const schema = new GraphQLSchema({ | |
}, | ||
validUnixTimestamp: { | ||
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. Does this have the same prop name with the one below? |
||
type: GraphQLDateTime, | ||
resolve: () => 854325678000, | ||
resolve: () => 854325678, | ||
}, | ||
invalidDateString: { | ||
type: GraphQLDateTime, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,12 +86,12 @@ describe('GraphQLDateTime', () => { | |
|
||
// Serializes Unix timestamp | ||
[ | ||
[854325678000, '1997-01-27T00:41:18.000Z'], | ||
[876535000, '1970-01-11T03:28:55.000Z'], | ||
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 did we remove this? |
||
[854325678, '1997-01-27T00:41:18.000Z'], | ||
[866478, '1970-01-11T00:41:18.000Z'], | ||
// The maximum representable unix timestamp | ||
[2147483647000, '2038-01-19T03:14:07.000Z'], | ||
[2147483647, '2038-01-19T03:14:07.000Z'], | ||
// The minimum representable unit timestamp | ||
[-2147483648000, '1901-12-13T20:45:52.000Z'], | ||
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 is this changed? |
||
[-2147483648, '1901-12-13T20:45:52.000Z'], | ||
].forEach(([value, expected]) => { | ||
it(`serializes unix timestamp ${stringify(value)} into date-string ${expected}`, () => { | ||
expect(GraphQLDateTime.serialize(value).toJSON()).toEqual(expected); | ||
|
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.
Instead of getting the current
Date
, we can check the number of digits with a fixed value likevalue.toString().length === X
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.
@yamatsafi Do you have time to fix this? I could help otherwise.
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.
I'd appreciate if you can :)
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 future-proof instead of checking for 13-digits today which may not be true in a few years :-) I know it is a long way but still. @jeremyzahner Please feel free to add unit tests as @ardatan suggested or I can add it quickly.
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.
made changes, ready for review
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.
@ardatan ^