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

Add date formatting query options to lists of date strings in YAML in addition to scalars #3556

Closed
lourd opened this issue Jan 16, 2018 · 3 comments · Fixed by #3688
Closed

Comments

@lourd
Copy link
Contributor

lourd commented Jan 16, 2018

Description

The gatsby-transformer-yaml plugin has a great behavior for parsing date strings and exposing them as rich Dates with the ability to format them through GraphQL query parameters! The ability to write simple, human-readable date strings like 2018-01-01 in YAML and have a rich date to query against for things like days of the week, abbreviations, etc., is excellent.

I was disappointed to discover that this feature is limited to scalars. Creating a list of date strings exposes no ability to format all of them through the query.

My workaround is to add another object layer, e.g. a list of objects that have a single property called date, but it would be nice to not have to do that.

Environment

Gatsby version: 1.9.151
Node.js version: 8.9
Operating System: macOS Siera 10.12.6

Example

Data

# events.yaml
# assume configured for processing with gatsby-source-filesystem

- name: Greatest show on earth
  dates:
    - 2018-01-01
    - 2018-01-02
    - 2018-01-03
- name: Average show
  dates:
    - 2018-01-04
    - 2018-01-05
    - 2018-01-06

Query

query EventsQuery {
  allEventsYaml {
    edges {
      node {
        name
        dates(formatString: "ddd MMMM Do, YYYY")
      }
    }
  }
}

Desired result

{
  "data": {
    "allEventsYaml": {
      "edges" : [
        {
          "node": {
            "name": "Greatest show on earth",
            "dates": [
              "Monday January 1st, 2018",
              "Tuesday January 2nd, 2018",
              "Wednesday January 3rd, 2018",
            ],
          },
        },
        {
          "node": {
            "name": "Average show",
            "dates": [
              "Thursday January 4th, 2018",
              "Friday January 5th, 2018",
              "Saturday January 6th, 2018",
            ]
          }
        }
      ]
    }
  }
}

Current result

{
  "errors": [
    {
      "message": "Unknown argument \"formatString\" on field \"dates\" of type \"EventsYaml\".",
      "locations": [
        {
          "line": 30,
          "column": 23
        }
      ]
    }
  ]
}
@KyleAMathews
Copy link
Contributor

Oooo yeah, we're missing this still.

Check out the code here:

When a scalar is a date it works but when we create a list (scroll up a bit), we correctly infer that the items within the list are a date but we're not add the date arguments to the list.

Do you feel up to doing a PR to add support for this? We'd need to abstract out the arguments and resolve function for the date field so it works for both scalar and list values.

@lourd
Copy link
Contributor Author

lourd commented Jan 16, 2018

Yeah, I'm happy to help 🙂

Can you point me towards the tests that cover this?

@KyleAMathews
Copy link
Contributor

Great!!

Here's the tests for inferring dates

Just add an array of date strings similar to your example in the initial issue description.

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 a pull request may close this issue.

2 participants