未处理的拒绝(错误):预期未定义为 GraphQL 架构
Unhandled Rejection (Error): Expected undefined to be a GraphQL schema
我正在尝试构建从 WordPress 导入的 post 页面,我 运行 "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。
我认为您的查询在 gatsby-node.js
文件中的格式不正确。应该是这样的:
return graphql(`
query {
allWordpressPost {
edges {
node {
id
slug
status
}
}
}
}
`);
试一试,如果对你有用,请告诉我。
我遇到了同样的错误,并且能够通过确保我直接从 gatsby
导入 graphql
来解决它:
错误原因:
// template file
import { graphql } from 'graphql'
如何修复:
// template file
import { graphql } from 'gatsby'
我正在尝试构建从 WordPress 导入的 post 页面,我 运行 "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。
我认为您的查询在 gatsby-node.js
文件中的格式不正确。应该是这样的:
return graphql(`
query {
allWordpressPost {
edges {
node {
id
slug
status
}
}
}
}
`);
试一试,如果对你有用,请告诉我。
我遇到了同样的错误,并且能够通过确保我直接从 gatsby
导入 graphql
来解决它:
错误原因:
// template file
import { graphql } from 'graphql'
如何修复:
// template file
import { graphql } from 'gatsby'