【发布时间】:2021-12-30 00:27:37
【问题描述】:
我正在尝试构建从 WordPress 导入的帖子页面,我运行“gatsby develop”并前往 URL。 首页一闪而过,然后我得到这个错误:
Unhandled Rejection (Error): Expected undefined to be a GraphQL schema.
invariant
C:/Users/Phil/Repositories/Zym/node_modules/graphql/jsutils/invariant.mjs:12
assertSchema
C:/Users/Phil/Repositories/Zym/node_modules/graphql/type/schema.mjs:25
validateSchema
C:/Users/Phil/Repositories/Zym/node_modules/graphql/type/validate.mjs:31
graphqlImpl
C:/Users/Phil/Repositories/Zym/node_modules/graphql/graphql.mjs:44
(anonymous function)
C:/Users/Phil/Repositories/Zym/node_modules/graphql/graphql.mjs:20
graphql
C:/Users/Phil/Repositories/Zym/node_modules/graphql/graphql.mjs:18
在我的“PostTemplate.js”中突出显示的查询:
export const query = graphql`
query($id: String!) {
wordpressPost(id: { eq: $id }) {
date
title
slug
content
categories {
name
}
}
}
`;
我通过 GraphiQL 界面运行相同的查询,它会向我发送数据?
真的不确定我在这里做错了什么,请参阅 gatsby-node.js 中的以下代码
exports.createPages = ({ actions, graphql }) => {
const { createPage } = actions
return graphql(`
{
allWordpressPost {
edges {
node {
id
slug
status
}
}
}
}
`)
.then(result => {
if (result.errors) {
result.errors.forEach(e => console.error(e.toString()))
return Promise.reject(result.errors)
}
const postTemplate = path.resolve(`./src/templates/PostTemplate.js`)
const posts = result.data.allWordpressPost.edges
_.each(posts, ({ node: post }) => {
createPage({
path: `/${post.slug}/`,
component: postTemplate,
context: {
id: post.id,
slug: post.slug
},
})
})
})
})
我已经尝试更新 gatsby-cli -g,并卸载了 node_modules。
【问题讨论】:
标签: javascript graphql gatsby