Skip to content
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

Merged
merged 4 commits into from
Sep 26, 2017

Conversation

pedrouid
Copy link
Contributor

@pedrouid pedrouid commented Sep 13, 2017

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

screenshot 2017-09-13 01 37 39

After

screenshot 2017-09-13 01 39 23

@pedrouid pedrouid changed the title serialize big integers for gatsby-medium-source timestamps [gatsby-medium-source] serialize big integers for timestamps Sep 13, 2017
@gatsbybot
Copy link
Collaborator

gatsbybot commented Sep 13, 2017

Deploy preview ready!

Built with commit 5c1bbe9

https://deploy-preview-2099--gatsbygram.netlify.com

@pedrouid pedrouid changed the title [gatsby-medium-source] serialize big integers for timestamps [gatsby-medium-source] serialise big integers for timestamps Sep 13, 2017
@KyleAMathews
Copy link
Contributor

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.

@pedrouid pedrouid changed the title [gatsby-medium-source] serialise big integers for timestamps [gatsby-medium-source] convert timestamps to ISO 8601 date string Sep 22, 2017
if (typeof nextObj === 'object') {
Object.keys(nextObj).map(key => convertTimestamps(nextObj[key], nextObj, key));
} else {
if (typeof nextObj === 'number' && nextObj >> 0 !== nextObj) {
Copy link
Contributor

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?

Copy link
Contributor Author

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)

Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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!

@KyleAMathews KyleAMathews merged commit 2c96699 into gatsbyjs:master Sep 26, 2017
@jlengstorf
Copy link
Contributor

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:

  1. We’d like to send you some Gatsby swag. As a token of our appreciation, you can go to the Gatsby Swag Store and log in with your GitHub account to get a coupon code good for one free piece of swag. (We’ve got t-shirts and hats, plus some socks that are really razzing our berries right now.)
  2. If you’re not already part of it, we just invited you to join the Gatsby organization on GitHub. This will add you to our team of maintainers. You’ll receive an email shortly asking you to confirm. By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.

If you have questions, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’.

Thanks again! 💪💜

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants