David Jensen
David Jensen

Reputation: 61

getting graphQL error when compiling

i am going through this tutorial: https://www.gatsbyjs.org/blog/2017-07-19-creating-a-blog-with-gatsby/

I have completed everything, and I am getting a graphQL compile error:

GraphQL Error There was an error while compiling your site's GraphQL queries.
Invariant Violation: GraphQLParser: Unknown argument `formatString`. 
Source: document `BlogPostByPath` file: `GraphQL request`.

Here is my query:

export const pageQuery = graphql`
  query BlogPostByPath($path: String!) {
    markdownRemark(frontmatter: { path: { eq: $path } }) {
      html
      frontmatter {
        date(formatString: "MMMM DD, YYYY")
        path
        title
      }
    }
  }
`
;

The compile error points to the date object, and when i remove it, the date compile error goes away. What is wrong with my date object?

Upvotes: 6

Views: 1464

Answers (3)

Dr Rob Lang
Dr Rob Lang

Reputation: 6883

I had a similar issue; fixed all my dates as recommended but the error still persisted. At the time of testing, I was running in Powershell:

gatsby develop

I stopped that using CTRL-C and Y to cancel, restarted the gatsby development server and the query then worked. When in development mode, gatsby caches certain things and it wasn't picking up the frontmatter changes to my files.

Upvotes: 4

jaegs
jaegs

Reputation: 509

There is nothing wrong with your date object date(formatString: "MMMM DD, YYYY") itself.

Rather, check your markdown file and make sure you are using the proper format in your frontmatter. I assume that's where your issue is stemming from.

Examples:

A date like this (there's no 77th month in a year) will throw the error you are getting:

---
path: "/hello-world"
date: "2017-77-12"
title: "My First Gatsby Post"
---

Similarly, a date like this (there's no 88th day in a month) will also throw the error you are getting:

---
path: "/hello-world"
date: "2017-07-88"
title: "My First Gatsby Post"
---

Those are extreme examples, but I think you catch my drift by now, so try fixing your frontmatter date so that the month, day, and year make calendrical sense.

Upvotes: 4

Sibaprasad Maiti
Sibaprasad Maiti

Reputation: 557

It should be "MMM" rather than "MMMM".

Upvotes: -4

Related Questions