Javascript Gatby控制台警告数据中存在冲突的字段类型;在同一查询上使用createPage两次时
我使用Javascript Gatby控制台警告数据中存在冲突的字段类型;在同一查询上使用createPage两次时,javascript,graphql,gatsby,Javascript,Graphql,Gatsby,我使用createPages进行了两次查询,并使用结果。使用createPages进行了两次数据查询: 对于每个页面节点 对于每页包含多个摘录的listpages,构建页面节点 现在我收到一条警告说 warn There are conflicting field types in your data. If you have explicitly defined a type for those fields, you can safely ignore this warning messag
createPages
进行了两次查询,并使用结果。使用createPages
进行了两次数据查询:
对于每个页面节点
对于每页包含多个摘录的listpages,构建页面节点
现在我收到一条警告说
warn There are conflicting field types in your data. If you have explicitly defined a type for those fields, you can safely ignore this warning message. Otherwise, Gatsby will omit those fields from the GraphQL schema.
所以我的问题是,
- 这究竟意味着什么
- 为这些字段显式定义类型是什么
- 我可以安全地忽略这一点吗
这是我精简的gatby-node.js文件
我解决了。我在两个上下文对象(博客文章和分页的博客摘要)上使用了相同的键(data:posts.slice(//…
),并将其中一个键更改为不同的键(content:posts.slice(//…
)
const path = require(`path`)
const { slash } = require(`gatsby-core-utils`)
// Gatsby API “createPages”.
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions
const result = await graphql(`
{
allWordpressPost {
edges {
node {
id
path
status
template
format
title
content
excerpt
date
}
}
}
}
`)
// Check for any errors
if (result.errors) {
throw new Error(result.errors)
}
// Access query results via object destructuring
const { allWordpressPost } = result.data
// create pages for each post node.
const postTemplate = path.resolve(`./src/templates/Post.js`)
allWordpressPost.edges.forEach(edge => {
createPage({
path: `/post${edge.node.path}`,
component: slash(postTemplate),
context: { data: edge.node },
})
})
//create summary pages for post nodes.
const blogTemplate = path.resolve(`./src/templates/Blog.js`)
const posts = allWordpressPost.edges //All posts
const postPerPage = 3 //Post excerpts per page
const pages = Math.ceil(posts.length / postPerPage) // Number of pages needed
Array.from({ length: pages }).forEach((edge, index) => {
createPage({
path: index === 0 ? "/blog/" : `/blog/${index + 1}`, //route based on index
component: slash(blogTemplate),
context: {
data: posts.slice(
index * postPerPage,
index * postPerPage + postPerPage
),
pages,
currentPage: index + 1,
},
})
})
}