Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 679
David Jensen Avatar asked Jan 09 '18 01:01

David Jensen


2 Answers

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.

like image 109
jaegs Avatar answered Oct 19 '22 00:10

jaegs


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.

like image 24
Dr Rob Lang Avatar answered Oct 19 '22 00:10

Dr Rob Lang