Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQLError: String cannot represent an array value: [] #16

Closed
Whaitiri opened this issue Jul 25, 2018 · 1 comment
Closed

GraphQLError: String cannot represent an array value: [] #16

Whaitiri opened this issue Jul 25, 2018 · 1 comment

Comments

@Whaitiri
Copy link

When I run gatsby build/develop, everything works fine, but this plugin causes my console to throw GraphQLError: String cannot represent an array value: [] for every single node in my app, for some nodes it posts a wall of the error repeating itself. This doesn't necessarily cause any issues, as I can still use the search once the site is built, but I'd still like to get to the bottom of this if possible, in case it is the cause of another error down the line.

gatsby-config

module.exports = {
  pathPrefix: `/ctc`,
  siteMetadata: {
    title: `Gatsby Default Starter`,
  },
  plugins: [
    {
      resolve: `@andrew-codes/gatsby-plugin-elasticlunr-search`,
      options: {
      // Fields to index
        fields: [
          'title'
        ],
      // How to resolve each field's value for a supported node type
        resolvers: {
            // For any node of type MarkdownRemark, list how to resolve the fields' values
          BookJson: {
            title: node => node.title,
            gatsby_slug: node => node.gatsby_slug,
            image: node => node.image
          },
          AuthorJson: {
            title: node => node.title,
            gatsby_slug: node => node.gatsby_slug,
            image: node => node.image
          }
        },
      },
    },
    `gatsby-transformer-json`,
    `gatsby-plugin-react-helmet`,
    `gatsby-plugin-sass`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `src`,
        path: `${__dirname}/src/data/final`
      }
    },
  ],
}

gatsby-node

const path = require(`path`);
const { createFilePath } = require(`gatsby-source-filesystem`)
const slugify = require('slugify')
const request = require('request-promise-native')
const crypto = require('crypto');
const fs = require('fs')

//create pages from OutputJson nodes, using id field as path
exports.createPages = ({ graphql, boundActionCreators }) => {
  const { createPage } = boundActionCreators
  return new Promise((resolve, reject) => {
    graphql(`
      {
        allGenreJson {
          edges {
            node {
              slug
              gatsby_slug
              id
              title
              type
            }
          }
        }
        allClipJson {
          edges {
            node {
              slug
              gatsby_slug
              id
              title
              type
            }
          }
        }
        allReadingAgeJson {
          edges {
            node {
              slug
              gatsby_slug
              id
              title
              type
            }
          }
        }
        allNarratorJson {
          edges {
            node {
              slug
              gatsby_slug
              id
              title
              type
            }
          }
        }
        allSeriesJson {
          edges {
            node {
              slug
              gatsby_slug
              id
              title
              type
            }
          }
        }
        allPublisherJson {
          edges {
            node {
              slug
              gatsby_slug
              id
              title
              type
            }
          }
        }
        allAuthorJson {
          edges {
            node {
              slug
              gatsby_slug
              id
              title
              type
            }
          }
        }
        allBookJson {
          edges {
            node {
              slug
              gatsby_slug
              id
              title
            }
          }
        }
      }`
    ).then(result => {
      result.data.allBookJson.edges.forEach(({node}) => {
        createPage({
          path: `${node.gatsby_slug}`,
          component: path.resolve('./src/templates/book.js'),
          context: {
            id: node.id,
            type: node.type,
            title: node.title
          },
        })
      })
      var apiEnds = ['Genre','Author','ReadingAge','Narrator','Series','Publisher']
      apiEnds.forEach((endpoint) => {
        result.data[`all${endpoint}Json`].edges.forEach(({ node}) => {

          createPage({
            path: `${node.gatsby_slug}`,
            component: path.resolve('./src/templates/category.js'),
            context: {
              id: node.id,
              type: node.type,
              title: node.title,
            },
          })
        })
      })
      resolve()
    })
  })
}
@Whaitiri
Copy link
Author

Ah, user error. Completely unrelated to my search functionality (other than it revealing the error). No problemo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant