[英]How to validate graphql in gatsby blog site
我正在嘗試在 Gatsby 中建立一個博客網站,一切都運行良好,直到我刪除了我的假測試員博客文章。
我的錯誤是:
gatsby-node.js" threw an error while running the createPages lifecycle:
Cannot query field "frontmatter" on type "MarkdownRemark".
GraphQL request:8:13
7 | id
8 | frontmatter {
| ^
9 | path
所以我的問題是如何在繼續之前確保這是有效的?
const { createPage } = actions;
const postTemplate = path.resolve('src/templates/blog-post.js');
return graphql(`
{
allMarkdownRemark {
edges {
node {
html
id
frontmatter {
path
title
date
featuredImage
}
}
}
}
}
`).then((res) => {
if (res.errors) {
return Promise.reject(res.errors);
}
if (res.data === undefined) {//Validation attempt
return;
}
res.data.allMarkdownRemark.edges.forEach(({ node }) => {
createPage({
path : node.frontmatter.path,
component : postTemplate
});
});
});
確保你告訴 gatsby 你的 Markdown 內容文件在哪里
在gatsby-config.js
,確保 plugins 數組包含以下內容:
{
resolve: 'gatsby-source-filesystem',
options: {
path: `${__dirname}/content`,
name: 'content',
},
},
如果您的降價位於內容目錄中,這只是一個示例
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.