Я пытаюсь создать страницы сообщений, импортированные из WordPress, запускаю «gatsby development» и перехожу к 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.