-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
[gatsby-medium-source] convert timestamps to ISO 8601 date string #2099
Conversation
Deploy preview ready! Built with commit 5c1bbe9 |
So I don't think this would work as is because it'll make the type of the fields inconsistent as some would be numbers and others strings. Why not just change them to an ISO 8601 date string? Then Gatsby will also know they're dates so you can format them, etc. when writing queries. |
if (typeof nextObj === 'object') { | ||
Object.keys(nextObj).map(key => convertTimestamps(nextObj[key], nextObj, key)); | ||
} else { | ||
if (typeof nextObj === 'number' && nextObj >> 0 !== nextObj) { |
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.
Is there a lodash helper method you can use here? I have no idea what you're doing 😅
Also… is the Medium schema not set? Don't we just know what the schema will be?
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.
Maybe there's a lodash helper method for this but I'm not sure.
It's recursively crawling down all nested objects until it finds a primitive value then it checks if it's a number and if that number overflows a 32-bit integer.
This method would be schema agnostic which wouldn't break if it were to change also I'm not sure if there is much advantage to tie it to the Medium as this could be used elsewhere where the source provides timestamps instead of ISO 8601 date string (which Gatsby uses)
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.
Will date fields always be a number which overflows a 32-bit integer? We're not going to get into a situation where some date fields are numbers and others are strings?
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.
For Medium this shouldn't be a problem because we are not going to see posts from the 70's even then it would only miss seven weeks from 7 December 1969 to 25 January 1970
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.
Cool, let's get this published! Thanks for the PR!
Hiya @pedrouid! 👋 This is definitely late, but on behalf of the entire Gatsby community, I wanted to say thank you for being here. Gatsby is built by awesome people like you. Let us say “thanks” in two ways:
If you have questions, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’. Thanks again! 💪💜 |
Serialise values typeof numbers that overflow 32-bit signed integer for graphql Int values.
More specifically the dates of Medium posts use timestamps which would return null.
Before
After