Markdown Gatsby.js中带有标记备注的自定义frontmatter变量

Markdown Gatsby.js中带有标记备注的自定义frontmatter变量,markdown,graphql,gatsby,yaml-front-matter,remarkjs,Markdown,Graphql,Gatsby,Yaml Front Matter,Remarkjs,我正在使用Gatsbyjs和NetlifyCMS建立一个网站。我已经开始使用这款起动器,现在我正在尝试定制它 我希望在标记文件的前端使用自定义变量,如下所示: --- templateKey: mirror nazev: Černobílá title: Black and White cena: '2700' price: '108' thumbnail: /img/img_1659.jpeg --- 我想用GraphQL访问这些数据。我使用盖茨比源文件系统和盖茨比转换注释。这是我的疑问:

我正在使用Gatsbyjs和NetlifyCMS建立一个网站。我已经开始使用这款起动器,现在我正在尝试定制它

我希望在标记文件的前端使用自定义变量,如下所示:

---
templateKey: mirror
nazev: Černobílá
title: Black and White
cena: '2700'
price: '108'
thumbnail: /img/img_1659.jpeg
---
我想用GraphQL访问这些数据。我使用盖茨比源文件系统和盖茨比转换注释。这是我的疑问:

  {
  allMarkdownRemark {
    edges {
      node {
        frontmatter {
          templateKey
          nazev
          title
          cena
          price
        }
      }
    }
  }
}
我无法让GraphQL读取我自己的变量,它只识别
title
templateKey
(那些已经在初学者中使用过的变量)。我得到这个错误:

{
  "errors": [
    {
      "message": "Cannot query field \"nazev\" on type \"frontmatter_2\".",
      "locations": [
        {
          "line": 7,
          "column": 11
        }
      ]
    },
    {
      "message": "Cannot query field \"cena\" on type \"frontmatter_2\".",
      "locations": [
        {
          "line": 9,
          "column": 11
        }
      ]
    },
    {
      "message": "Cannot query field \"price\" on type \"frontmatter_2\". Did you mean \"pricing\"?",
      "locations": [
        {
          "line": 10,
          "column": 11
        }
      ]
    }
  ]
}
我找了好几天,但什么也没找到。有人能帮帮我吗?

解决了

问题是在我的降价文件的frontmatter中新添加的属性没有显示在我的GraphQL中

我所要做的就是用“gatsby develop”重新启动服务器。

一些背景信息可能有助于您在将来预测类似的问题
gatsby transformer remark
和所有其他依赖于GraphQL查询的插件只能在运行GraphQL查询时读取新添加的变量

在Gatsby中,GraphQL查询在开发服务器启动时运行一次。 如果在
gatsby develope
仍处于活动状态时更改代码,则不会刷新查询。通过使用
gatsby develop
重新启动,可以再次运行GraphQL查询

盖茨比文档有自己的条目,显示查询的确切运行时间:

success open and validate gatsby-configs - 0.051 s
// ...
success onPostBootstrap - 0.130 s
⠀
info bootstrap finished - 3.674 s
⠀
success run static queries - 0.057 s — 3/3 89.08 queries/second  // GraphQL queries here
success run page queries - 0.033 s — 5/5 347.81 queries/second   // GraphQL queries here
success start webpack server - 1.707 s — 1/1 6.06 pages/second
作为我从经验中学到的经验法则,如果您想知道为什么您的代码更改不是热重新加载

  • 刷新浏览器
  • 如果不起作用,重新启动盖茨比开发公司
  • 如果不起作用,请运行
    gatsby clean
    ,清除浏览器的站点缓存,然后运行
    gatsby develope
  • 如果这不起作用,你几乎可以100%肯定你犯了错误

你能解释更多吗?我搞不懂!只要重新启动盖茨比,让“盖茨比变形金刚评论”知道你已经对前台做了更改:)我真的很高兴你几天都不需要重新启动盖茨比。我每5分钟就重新启动一次,因为出现了错误。如果您使用GraphiQL,可能也需要重新加载浏览器。@RobertWolf非常感谢,我也有同样的问题,我在文档中没有找到任何内容,但重新启动服务并重新加载GraphiQL页面是所有需要的。谢谢