Closed Srishtichambail closed 3 years ago
Any update on this?
Hiya!
This issue has gone quiet. Spooky quiet. 👻
We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!
Thanks for being a part of the Gatsby community! 💪💜
Hey again!
It’s been 60 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it.
Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY
. Please feel free to comment on this issue or create a new one if you need anything else.
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!
Thanks again for being part of the Gatsby community! 💪💜
Description
WPGraphQL menu data
not merging properly with theGatsby schema & Node model
. Not able to see menu data when querying allWpMenu or allWpMenuItem. Menu items are visible in Wordpress GraphiQL IDE but not in Gatsby GraphiQL IDE.Steps to reproduce
gatsby-node.js
// This is a simple debugging tool // dd() will prettily dump to the terminal and kill the process // const { dd } = require('dumper.js')
/**
See https://www.gatsbyjs.com/docs/node-apis/#createPages for more info. */ exports.createPages = async gatsbyUtilities => { // Query our posts from the GraphQL server await createAllSitePages(gatsbyUtilities); const posts = await getPosts(gatsbyUtilities)
// If there are no posts in WordPress, don't do anything if (!posts.length) { return }
// If there are posts, create pages for them await createIndividualBlogPostPages({ posts, gatsbyUtilities })
// And a paginated archive await createBlogPostArchive({ posts, gatsbyUtilities }) }
const createAllSitePages = async (gatsbyUtilities) => {
const pageTemplate = path.resolve('./src/templates/page.js') const pages = await gatsbyUtilities.graphql(' { allWpPage { edges { node { id title content slug } } } } ') return Promise.all( pages.data.allWpPage.edges.map(edge => { console.log('page created:', edge.node.title, edge.node.slug); gatsbyUtilities.actions.createPage({ path: '/${edge.node.slug}/', component: pageTemplate, context: { title: edge.node.title, }, }) }) ) }
/**
This function creates all the individual blog pages in this site */ const createIndividualBlogPostPages = async ({ posts, gatsbyUtilities }) => Promise.all( posts.map(({ previous, post, next }) => // createPage is an action passed to createPages // See https://www.gatsbyjs.com/docs/actions#createPage for more info gatsbyUtilities.actions.createPage({ // Use the WordPress uri as the Gatsby page path // This is a good idea so that internal links and menus work 👍 path: post.uri,
}) ) )
/**
This function creates all the individual blog pages in this site / async function createBlogPostArchive({ posts, gatsbyUtilities }) { const graphqlResult = await gatsbyUtilities.graphql(/ GraphQL */ ' { wp { readingSettings { postsPerPage } } } ')
const { postsPerPage } = graphqlResult.data.wp.readingSettings
const postsChunkedIntoArchivePages = chunk(posts, postsPerPage) const totalPages = postsChunkedIntoArchivePages.length
return Promise.all( postsChunkedIntoArchivePages.map(async (_posts, index) => { const pageNumber = index + 1
const getPagePath = page => { if (page > 0 && page <= totalPages) { // Since our homepage is our blog page // we want the first page to be "/" and any additional pages // to be numbered. // "/blog/2" for example return page === 1 ? '/' : '/blog/${page}' }
}
// createPage is an action passed to createPages // See https://www.gatsbyjs.com/docs/actions#createPage for more info await gatsbyUtilities.actions.createPage({ path: getPagePath(pageNumber),
}) }) ) }
async function getPosts({ graphql, reporter }) { const graphqlResult = await graphql(/ GraphQL / ' query WpPosts {
Query all WordPress blog posts sorted by date
')
if (graphqlResult.errors) { reporter.panicOnBuild( 'There was an error loading your blog posts', graphqlResult.errors ) return }
return graphqlResult.data.allWpPost.edges }
allWpMenu { edges { node { menuItems { nodes { label } } } } }