conradj / gatsby-source-pocket

Fetch data from Pocket API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GraphQLError: Unknown argument "formatString" on field "time_added" of type "PocketArticle".

rdricco opened this issue · comments

I'm trying to change the date format used by Pocket but it give me this error from title. Looks like Gatsby don't work well with non-iso formats. I've tried to change directly on GraphQl query using time_added(formatString: "YYYY-MM-DD") when got this message. Formating the node before the query didn't work too, using moment or date-fns returns invalid_date.

The field type from Pocket is a Unix Timestamp so you have to multiply it by 1000 to get the millisecond value most date functions expect.

Let me know if that's it. I haven't tried this in GraphQL but I use format from date-fns on this field ok after multiplying it.

I don't know why but changing the node using moment or format didn't work for graphql but using both together works.. I've tried format(node.time_added) and moment(node.timeadded, 'X) when creating my nodes, both returned a Invalid Date but using format(moment(node.time_added, 'X')) works fine. Using only moment for conversion should work, right?

I'm on my phone but looking at my example project I used format(new Date(time_read * 1000), "dddd ha").

@rdricco did you get this working?

I didn't have time to work on a better solution, at moment I'm using this format+moment conversion.

To get a date object from a Pocket time stamp such as time_read, you need to multiply it by 1000, as follows new Date(time_read * 1000). You can then wrap it in a date library of your choosing.