编译时出现graphQL错误

问题描述 投票:3回答:3

我正在阅读本教程:https://www.gatsbyjs.org/blog/2017-07-19-creating-a-blog-with-gatsby/

我已经完成了所有事情,我收到了graphQL编译错误:

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`.

这是我的查询:

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

编译错误指向日期对象,当我删除它时,日期编译错误消失。我的约会对象有什么问题?

javascript reactjs graphql gatsby
3个回答
2
投票

您的约会对象date(formatString: "MMMM DD, YYYY")本身没有任何问题。

而是,检查您的降价文件,并确保您在frontmatter中使用正确的格式。我认为这是你的问题所源自的地方。

例子:

像这样的日期(一年中没有第77个月)会抛出你得到的错误:

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

同样,这样的日期(一个月内没有第88天)也会抛出你得到的错误:

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

这些是极端的例子,但我认为你现在已经抓住了我的漂移,所以尝试修复你的前置日期,以便月,日和年具有日历意义。


1
投票

我有类似的问题;修复了我推荐的所有日期,但错误仍然存​​在。在测试时,我在Powershell中运行:

gatsby develop

我停止使用CTRL-C和Y取消,重新启动gatsby开发服务器,然后查询工作。在开发模式下,gatsby会缓存某些内容,并且没有对我的文件进行前端更改。


-4
投票

它应该是“MMM”而不是“MMMM”。

© www.soinside.com 2019 - 2024. All rights reserved.