graphql - 如何将前端添加到 qraphQL?
问题描述
我正在学习 Gatsby.js 并面临一个问题。我试图从 Markdown 中获取一个 html 文档,但首先我需要阅读 markdown 文档的 frontmatter。所以,我下载了 gatsby-transformer-remark,将其添加到 gatsby-config.js。但是当我打开 localhost:8000/__graphql 并尝试获取 frontmatter 时,没有这样的选项。
这是我使用的查询:
{
allMarkdownRemark{
nodes{
frontmatter{
title
}
}
}
}
它在“frontmatter”一词下划线并写下“无法查询类型“MarkdownRemark”的字段frontmatter”。我究竟做错了什么?这就是它在 graphql 中的样子:image
盖茨比-config.js
module.exports = {
siteMetadata: {
title: `Gatsby Default Starter`,
description: `Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need.`,
author: `@gatsbyjs`,
},
plugins: [
`gatsby-plugin-react-helmet`,
{
resolve: `gatsby-source-filesystem`,
options: {
name: `images`,
path: `${__dirname}/src/images`,
},
},
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`,
{
resolve: `gatsby-plugin-manifest`,
options: {
name: `gatsby-starter-default`,
short_name: `starter`,
start_url: `/`,
background_color: `#663399`,
theme_color: `#663399`,
display: `minimal-ui`,
icon: `src/images/gatsby-icon.png`,
},
},
{
resolve: `gatsby-transformer-remark`,
options: {
commonmark: true,
footnotes: true,
pedantic: true,
gfm: true,
name: 'md-files',
path: '${__dirname}/src/pages/md-files',
},
},
],
}
降价文件
---
title: "first post"
date: 2019-11-12
---
# this is a header
Lorem ipsum...
似乎graphql根本看不到任何降价文档。
解决方案
解决了。源文件系统位于图像文件夹中gatsby-config.js
,因此 qraphql 没有看到所有降价文件。我换了gatsby-source-filesystem
。这是一个代码:
{
resolve: `gatsby-source-filesystem`,
options: {
name: `pages`,
path: `${__dirname}/src/pages`,
},
},
pages
文件夹包含 md 文件
(感谢 EliteRaceElephant 的帮助)
推荐阅读
- php - {{asset('css/app.css')}} 和 laravel 中的 {{mix('css/app.css')}} 一样吗
- twitter-bootstrap - 如何在 Asp.net core 2.0.9 Web 应用程序中启用引导程序
- python - 如何通过双击文件在空闲编辑器中打开python文件(Windows 10)
- java - java clone() 是如何真正使用浅拷贝的?
- java - 如何在 pom.xml 中的 Maven Jetty 插件中设置 web.xml 的路径?
- php - 无法使用 Symfony 4.1 创建数据库:找不到驱动程序
- c# - 在 for 循环打字稿和休眠死锁中调用异步函数
- flutter - 水平扩展以适应文本内容的文本字段
- kotlin - 如何从 lambda 引用外部函数?
- java - uso e declaração de namespace Saxon em codigo java