rlindskog/covid19-graphql

change date format with GraphQL

Closed this issue · 3 comments

Hello!

I need different time format for date (like. 2020-01-01). Can you help me with that?
I don't have experience with GraphQL but I want dive in, so if you help me with schema, I will try do my best

Hi! Is this for the return type or the input?

Return type: GraphQL and JSON don't have a date type, so dates are returned as Strings. I recommend converting the date string to a date object on the client. In javascript, that would be as simple as const d = new Date('2020-01-01')

Input: For the results query, it requires an input object, so you can do conditionals (eq, lt, gt - equals, less than, greater than). example below

# Write your query or mutation here

query {
  # results
  results(countries: ["US"], date: { eq: "2020-03-16" })  {
    growthRate
    confirmed
  }
}

Hope this helps, please let me know if you have any more questions!

@jeetiss Also, check out the docs tab on the right, it shows a bunch of methods you can use.

Screen Shot 2020-03-17 at 11 36 22 AM

@rlindskog thanks for answer.

I recommend converting the date string to a date object on the client.

I don't need date as object. I need date in different format. Date is formatting like yyyy-M-d, I need yyyy-MM-dd. I can do it on the client, but it costs much more than if it be converted on server.

I'm using date-fns and it size is like:
Снимок экрана 2020-03-18 в 08 50 53

I found where I saw that solution:
https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/schema/types/date.js

What do you think about this?