question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unknown argument "formatString" on field "date" of type "MarkdownRemarkFrontmatter".

See original GitHub issue

Referencing: #26893 (and from a few years ago #2096) I tried removing all of my md files, then running gatsby clean and then npm run develop but I am still getting the

Unknown argument "formatString" on field "date" of type "MarkdownRemarkFrontmatter".

I am getting this error on three files:

blog-post.js graphql query in question:

export const pageQuery = graphql`
  query BlogPostBySlug($slug: String!) {
    site {
      siteMetadata {
        title
      }
    }
    markdownRemark(fields: { slug: { eq: $slug } }) {
      id
      excerpt(pruneLength: 160)
      html
      frontmatter {
        title
        date(formatString: "MMMM DD, YYYY")
        description
      }
    }
  }
`

search.js graphql query in question:

export const pageQuery = graphql`
    query {
        allMarkdownRemark(sort: { order: DESC, fields: frontmatter___date }) {
            edges {
                node {
                    excerpt
                    id
                    frontmatter {
                        title
                        description
                        date(formatString: "MMMM DD, YYYY")
                    }
                    fields {
                        slug
                    }
                }
            }
        }
    }
`

index.js graphql query in question:

export const pageQuery = graphql`
  query {
    site {
      siteMetadata {
        title
      }
    }
    allMarkdownRemark(sort: { fields: [frontmatter___date], order: DESC }) {
      edges {
        node {
          excerpt
          fields {
            slug
          }
          frontmatter {
            date(formatString: "MMMM DD, YYYY")
            title
            description
          }
        }
      }
    }
  }
`

Interestingly after deleting all the md files I got a new message:

 ERROR #85923  GRAPHQL

There was an error in your GraphQL query:

Cannot query field "frontmatter" on type "MarkdownRemark".

If you don't expect "frontmatter" to exist on the type "MarkdownRemark" it is most likely a typo.
However, if you expect "frontmatter" to exist there are a couple of solutions to common problems:

- If you added a new data source and/or changed something inside gatsby-node.js/gatsby-config.js, please try a restart of your development server
- The field might be accessible in another subfield, please try your query in GraphiQL and use the GraphiQL explorer to see which fields you can query and what shape they have
- You want to optionally use your field "frontmatter" and right now it is not used anywhere. Therefore Gatsby can't infer the type and add it to the GraphQL schema. A quick fix is to add at least one entry with that field ("dummy content")

It is recommended to explicitly type your GraphQL schema if you want to use optional fields. This way you don't have to add the mentioned "dummy content". Visit our docs to learn how you can define the schema for "MarkdownRemark":
https://www.gatsbyjs.org/docs/schema-customization/#creating-type-definitions

A few days ago this bug popped up after a git commit. Everything was working fine then I pushed some mobile header/tailwind adjustments to my repo and this error popped up. My temporary workaround is to delete

(formatString: "MMMM DD, YYYY)

from the query.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

21reactions
rburgstcommented, Sep 20, 2020

the type of your frontmatter date field has changed from Date to String. Most likely the reason (at least for me) it is that one of your posts has an invalid date (in my case I had date: 2020-079-20T08:11:45+02:00). Check all your frontmatter dates and ensure that they are valid.

1reaction
Isaac-Taitcommented, Sep 21, 2020

@osseonews Per chance did you try gatsby clean before running gatsby develop? I read that had helped some folks… Fortunately for me I only 16 md files to go through, but 14 of those md files the date field had been wrapped in "" which was causing my error.

I ended up going in and changing all the date fields from this format: date: "April 15, 2015" into this format: date: 2015-04-15T03:13:00+02:00 running gatsby clean and then gatsby develop and the error was gone

Read more comments on GitHub >

github_iconTop Results From Across the Web

getting graphQL error when compiling - Stack Overflow
GraphQL Error There was an error while compiling your site's GraphQL queries. Invariant Violation: GraphQLParser: Unknown argument `formatString ...
Read more >
Gatsby Development 101 - A Condensed Tutorial
This caused me 2 hours of debugging, so if you get "Unknown argument "formatString" on field "date" of type "MarkdownRemarkFrontmatter" when ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found