Graphql gatsbyjs从GraphCM查询数据,状态条件为抛出错误对象未定义
你好,我有一个gatsbyjs网站,我试图从graphcms中提取模型“job”的数据。如果我把所有的工作都干掉。该查询工作正常,但如果我尝试设置条件以仅获取状态字段为published的作业。它没有提取任何数据并抛出错误: TypeError:无法读取未定义的属性“allJob” 下面是我的gatsby-node.js:Graphql gatsbyjs从GraphCM查询数据,状态条件为抛出错误对象未定义,graphql,gatsby,Graphql,Gatsby,你好,我有一个gatsbyjs网站,我试图从graphcms中提取模型“job”的数据。如果我把所有的工作都干掉。该查询工作正常,但如果我尝试设置条件以仅获取状态字段为published的作业。它没有提取任何数据并抛出错误: TypeError:无法读取未定义的属性“allJob” 下面是我的gatsby-node.js: const path = require(`path`); const makeRequest = (graphql, request) => new Promise(
const path = require(`path`);
const makeRequest = (graphql, request) => new Promise((resolve, reject) => {
resolve(
graphql(request).then(result => {
if (result.errors) {
reject(result.errors)
}
return result;
})
)
});
exports.createPages = ({ boundActionCreators, graphql }) => {
const { createPage } = boundActionCreators;
const getJobs = makeRequest(graphql, `
{
allJob(where: {status: PUBLISHED}) {
edges{
node{
id
}
}
}
}
`).then(result => { result.data.allJob.edges.forEach(({ node }) => {
createPage({
path: `/job/${node.id}`,
component: path.resolve(`src/templates/jobTemplate.js`),
context: {
id: node.id,
}
})
console.log(node.id)
})
}
)
return getJobs;
};
盖茨比不理解
allJob(其中:{status:PUBLISHED})
,因为它的语法错误
您可能希望改用过滤器。我不能给你一个例子,因为我不知道结构是如何的,但我可以建议你运行gatsby develope
并转到GraphiQL(http://localhost:8000/___graphql
)并使用其自动完成功能(Ctrl+Space
)获取正确的筛选器
更多信息: