TryGhost / gatsby-source-ghost

Source plugin for pulling data into Gatsby.js from the Ghost Public API.
https://ghost.org
MIT License
176 stars 45 forks source link

Gatsby-Node.js returning null #14

Closed ronaldlangeveld closed 5 years ago

ronaldlangeveld commented 5 years ago

Not sure if my bad code or a bug, but it doesn't seem to be building production builds (via Netlify). Throws the error TypeError: expecting an array or an iterable object but got [object Null]

Well on development it also gives that error but still builds everything fine from the my Ghost api.

Here's the full code

const path = require("path")
const _ = require(`lodash`)

exports.createPages = ({ graphql, actions }) => {
  const { createPage } = actions
  const createPosts = new Promise((resolve, reject) => {
    const postTemplate = path.resolve(`./src/templates/blogTemplate.js`)
    resolve(
      graphql(`
        {
 allGhostPost(sort: { order: DESC, fields: [published_at] }) {
    edges {
      node {
        id
        slug
        title
        html
        published_at
      }
    }
 }
        }
      `).then(result => {
        const items = result.data.allGhostPost.edges

        _.forEach(items, ({ node }) => {
          node.url = `/${node.slug}/`
          createPage({
            path: node.url,
            component: path.resolve(postTemplate),
            context: {
              slug: node.slug,
            },
          })
        })

        return resolve()
      }).catch(error => {
        console.log(error);
      })
    )
  })

  return Promise.all(createPosts)
}

Ran a graphql query as well and results seems fine.

Screenshot 2019-03-20 at 16 31 26
ronaldlangeveld commented 5 years ago

Took some code from the Gatsby Ghost Starter and that seemed to work.

https://gist.github.com/ronaldlangeveld/ff6fa578515bcc4a0a0750390007dc07