0

I am a beginner at Gatsby. Recently start to build a headless website with WordPress & Gatsby. I want to create dynamic pages & post via gatsby-node.js. When querying into http://localhost:8000/___graphql then shows query result. How can I fix the issue?

gatsby-node.js
code link: https://codeshare.io/8pz3qJ enter image description here

Monzur Alam
  • 512
  • 4
  • 11

1 Answers1

0

The issue here, besides your gatsby-node.js looks good and the pages should be created correctly, is that you don't have a connection to your WordPress site and the code breaks at:

_.each(result.data.allWpPage.edges, edge => {

Because allWpPage is undefined.

In addition, your promise rejection is not doing what it should (because it's not throwing any exception:

if (result.errors) {
  console.log(result.errors)
  reject(result.errors)
}

Should be something like:

if (!result) {
  console.log(result.errors)
  reject(result.errors)
}

The issue is:

{
    resolve: 'gatsby-source-wordpress',
    options: {
      "url": "http://learn.test/graphql"
    }

This URL doesn't seem to be providing any valid GraphQL schema.

I'd recommend following one of the gatsby-plugin-wordpress tutorials or diving directly on one of the starters which has a minimum default configuration:

  resolve: `gatsby-source-wordpress`,
  options: {
    url: `https://wpgatsbydemo.wpengine.com/graphql`,
  },

Here's one of the starters with a valid and running WordPress GraphQL configuration: https://www.gatsbyjs.com/starters/gatsbyjs/gatsby-starter-wordpress-blog

Ferran Buireu
  • 28,630
  • 6
  • 39
  • 67