Javascript 自定义查询的Gatsby GraphQL中的未知字段错误
我在用盖茨比和GraphQL。获取未知字段错误,如下所示:Javascript 自定义查询的Gatsby GraphQL中的未知字段错误,javascript,graphql,gatsby,Javascript,Graphql,Gatsby,我在用盖茨比和GraphQL。获取未知字段错误,如下所示: GraphQL Error Encountered 2 error(s): - Unknown field 'allBlogPost' on type 'Query'. Source: document `homeAymanDesktopFirstSrcPagesIndexJs2258072279` file: `GraphQL request` GraphQL request:3:3 2 | { 3 |
GraphQL Error Encountered 2 error(s):
- Unknown field 'allBlogPost' on type 'Query'. Source: document `homeAymanDesktopFirstSrcPagesIndexJs2258072279` file: `GraphQL request`
GraphQL request:3:3
2 | {
3 | posts: allBlogPost {
| ^
4 | nodes {
- Unknown field 'blogPost' on type 'Query'.
file: /home/ayman/Desktop/first/src/templates/post.js
这是我的post.js
模板文件:
从“React”导入React
从“盖茨比”导入{graphql}
导出默认值({data})=>{
console.log(数据)
返回(
{data.post.title}
)
}
export const query=graphql`
查询($id:String!){
post:blogPost(id:{eq:$id}){
标题
html
}
}
`
我的gatsby node.js
配置可以在这个
我的GraphiQL:
更新 在
content/posts
和content/articles
中添加ascidoc文件后,出现以下错误:
Cannot query field "slug" on type "BlogPost".
File: gatsby-node.js:89:16
ERROR #11321 PLUGIN
"gatsby-node.js" threw an error while running the createPages lifecycle:
Cannot read property 'posts' of undefined
TypeError: Cannot read property 'posts' of undefined
- gatsby-node.js:99
您的代码在
gatsby node.js
中被破坏,而不是在模板中(至少目前是这样)
在createPage
API中尝试使用async
/await
方法,例如:
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions
const postTemplate = path.resolve(`./src/templates/post.js`)
const postsQuery = await graphql(`
{
posts: allBlogPost {
nodes {
id
slug
}
}
}
`);
if (postsQuery.errors) {
reporter.panicOnBuild(`Error while running GraphQL query.`);
return;
}
postsQuery.data.posts.nodes.forEach( node => {
createPage({
path: node.slug,
component: postTemplate,
context: {
id: node.id,
},
})
})
您似乎无法正确创建自己的模式。确保您的验证是正确的:
if (node.internal.type === `Asciidoc`)
我猜您的查询要么在
localhost:8000/\uuuuuu图形ql
中被破坏了,要么没有?添加了有问题的屏幕截图以供参考冷却错误reporter.panicOnBuild([
ayman`+postsQuery.errors]);`给出GraphQLError:无法查询类型“query”上的字段“allBlogPost”。你是说“allBlogPostCollection”吗?
是的,allBlogPost
它不是一个节点:/。在您的localhost:8000/\uuuuuuu图形ql
中,您正在查询的allBlogPostCollection
allBlogPost
不存在。请参阅更新的屏幕截图。我需要allBlogPost
和allBlogPostCollection
是否验证此条件node.internal.type===“ascidoc”
我忘了添加ascidoc文件。添加后,获取此错误-类型“[BlogPost!!”上的未知字段“slug”。来源:文档homeAymanDesktopFirstSrcPagesIndexJs2258072279文件:GraphQL请求