小编sha*_*adw的帖子

如何将 frontmatter 添加到 qraphQL?

我正在学习 Gatsby.js 并遇到一个问题。我尝试从 markdown 获取 html 文档,但首先我需要阅读 markdown 文档的 frontmatter。所以,我下载了 gatsby-transformer-remark,并将其添加到 gatsby-config.js 中。但是当我打开 localhost:8000/__graphql 并尝试获取 frontmatter 时,没有这样的选项。

这是我使用的查询:

{
    allMarkdownRemark{
        nodes{
            frontmatter{
               title
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

它在“frontmatter”一词下划线,并写道“无法在类型“MarkdownRemark”上查询字段 frontmatter”。我究竟做错了什么?这就是它在 graphql 中的样子

gatsby-config.js

{
    allMarkdownRemark{
        nodes{
            frontmatter{
               title
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

降价文档

---
title: "first post"
date: 2019-11-12
---

# this is a header

Lorem ipsum...
Run Code Online (Sandbox Code Playgroud)

似乎 graphql 根本没有看到任何 Markdown 文档。

graphql gatsby

3
推荐指数
1
解决办法
1932
查看次数

标签 统计

gatsby ×1

graphql ×1