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

@andrew-codes/gatsby-plugin-elasticlunr-search plugin has generated no Gatsby nodes. #11

Open
devinswett opened this issue May 29, 2018 · 12 comments

Comments

@devinswett
Copy link

Hello,

I don't think this is an issue, more just my misunderstanding of how to properly integrate this plugin.

I'm having a miserable time trying to integrate this into a gatsby site that's using the gatsby-source-WordPress plugin.

I'm able to pull all of my Wordpress info, into regular templates, so that's not an issue. It's just whenever I run gatsby develop I receive the " @andrew-codes/gatsby-plugin-elasticlunr-search plugin has generated no Gatsby nodes." warning. Followed by another GraphQL warning, "GraphQL Error Unknown field siteSearchIndex on type RootQueryType."

Clearning or deleting the .cache folder doesn't seem to have any effect.

It's like it's just not creating the siteSearchIndex.

Here's my gatsby-config.js file

module.exports = {
    siteMetadata: {
        title: `RMFA Walking Tour`,
    },
    plugins: [
        `gatsby-plugin-react-helmet`,
        `gatsby-plugin-catch-links`,
        {
            resolve: `gatsby-source-filesystem`,
            options: {
                path: `${__dirname}/src/pages`,
                name: 'pages',
            },
        },
        {
            resolve: "gatsby-source-wordpress",
            options: {
                baseUrl: "rochesternharts.local",
                protocol: "http",
                hostingWPCOM: false,
                useACF: true,
                verboseOutput: false,
                perPage: 100,
                concurrentRequests: 10,
            },
        },
        {
            resolve: `@andrew-codes/gatsby-plugin-elasticlunr-search`,
            options: {
                // Fields to index
                fields: [
                    'id',
                    'title',
                    'artwork_number',
                    'artist_name',
                ],
                // 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
                    artwork: {
                        id: node=> node.id,
                        title: node => node.title,
                        artwork_number: node => node.acf.artwork_number,
                        artist_name: node => node.acf.artist_name,
                    },
                },
            },
        },
    ],
}

and my gatsby-node.js

const _ = require(`lodash`)
const Promise = require(`bluebird`)
const path = require(`path`)
const slash = require(`slash`)

const fs = require('fs');
const { createFilePath } = require(`gatsby-source-filesystem`);

const rootDir = path.resolve(__dirname);

exports.onCreateNode = ({ node, getNode, boundActionCreators }) => {
  const { createNodeField } = boundActionCreators;
  if (node.internal.type === `artwork`) {
    const slug = node.slug;

    createNodeField({
      node,
      name: `slug`,
      value: slug,
    });

    const template = path.resolve(`./src/templates/single.js`);
    createNodeField({
      node,
      name: `template`,
      value: template,
    });
  }
};

exports.createPages = ({ graphql, boundActionCreators }) => {
    const { createPage } = boundActionCreators;

    return new Promise((resolve, reject) => {
        graphql(
            `
            {
                allWordpressWpArtwork {
                    edges {
                        node {
                            id
                            title
                            slug
                            acf {
                                artwork_number
                                artist_name
                                artist_bio
                            }
                        }
                    }
                }
            }
            `
        ).then(result => {
            if (result.errors) {
                console.log(result.errors);
                reject(result.errors);
            }
            const template = path.resolve(`./src/templates/single.js`);
            _.each(result.data.allWordpressWpArtwork.edges, edge => {
                createPage({
                    path: `${edge.node.slug}`,
                    component: slash(template),
                    context: {
                        slug: edge.node.slug,
                    },
                });
            });
        });

        resolve();
    });
}

Just for clarification, when I console.log the node.internal.type it returns 'artwork' as that's my Wordpress custom post type name.

I realize that this issue encompasses way more than just the elasticlunr-search plugin. So if it's just too broad an issue, I understand. But if you have any advice, I'd really appreciate it, I've hit a brick wall.

@dylanpinn
Copy link

For those that come here searching for a solution to this. It appears that a fork has been created for V2 https://github.com/gatsby-contrib/gatsby-plugin-elasticlunr-search.

This fixes the issue for me.

@seanngpack
Copy link

I'm still having the same issue @devinswett, the siteSearchIndex doesn't seem to be created. Maybe it's an issue with how the gatsby-config is set up?

@seanngpack
Copy link

@dylanpinn Hey, can you post your gatsby-config? The nodes are not being generated for me and I'm using the forked version and Gatsby V2.

resolve: `@gatsby-contrib/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
          wordpressPost: {
            title: node => node.title,
            // path: node => node.slug,
            // tags: node => node.tags,
            // keywords: node => node.acf.keywords,
          },
        },
      },
    },

@dylanpinn
Copy link

@seanngpack Here is our config. It works though I am still not 100% finished with it yet.

    {
      resolve: `@gatsby-contrib/gatsby-plugin-elasticlunr-search`,
      options: {
        fields: ['title', 'content'],
        resolvers: {
          wordpress__POST: {
            title: node => node.title,
            link: node => node.link,
            filter: () => 'page-content',
          },
          wordpress__PAGE: {
            title: node => node.title,
            content: node => {
              return node;
            },
            link: node => node.link,
            filter: () => 'page-content',
          },
          wordpress__wp_document: {
            title: node => node.title,
            link: node => node.link,
            filter: () => 'document',
          },
        },
      },
    },

@seanngpack
Copy link

@dylanpinn OHHHHH, I was using the wrong resolvers. Thank you!

@ashokballolli
Copy link

ashokballolli commented Dec 28, 2018

Hi @dylanpinn @seanngpack i am facing the similar issue Actually i am dynamically creating the pages by reading the content from excel sheet using gatsby-source-filesystem and gatsby-transformer-excel and i want to use @gatsby-contrib/gatsby-plugin-elasticlunr-search for search on the nodes created from the excel data. But i am getting the error message in graphiql "Cannot query field "siteSearchIndex" on type "RootQueryType".". Need your help in understanding what i am doing wrong here. Thanks in advance.

Details:

Plugins:

    {
      resolve: `gatsby-source-filesystem`,
      options: {
        path: `${__dirname}/src/pages`,
        name: "pages",
      },
    },
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `data`,
        path: `${__dirname}/src/data/`,
        ignore: [`**/\.*`], // ignore files starting with a dot
        },
     },
     `gatsby-transformer-excel`,
    {
      resolve: `gatsby-transformer-remark`,
      options: {
        plugins: [
          {
            resolve: `gatsby-remark-responsive-iframe`,
            options: {
              wrapperStyle: `margin-bottom: 1.05rem`,
            },
          },
          `gatsby-remark-prismjs`,
          `gatsby-remark-copy-linked-files`,
          `gatsby-remark-autolink-headers`,
          `gatsby-remark-smartypants`,
        ],
      },
    },
    `gatsby-plugin-stylus`,
    `gatsby-plugin-react-helmet`,
    {
        resolve: `@gatsby-contrib/gatsby-plugin-elasticlunr-search`,
        options: {
            // Fields to index
            fields: [
                'Summary',
                'Description',
            ],
            // 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
                JobsdataXlsmGovtJobs: {
                    Summary: node => node.Summary,
                    Description: node => node.Description,
                },
            },
        },
    },
  ] ```

Thanks

@dylanpinn
Copy link

@ashokballolli Sorry, I haven't seen that error before. Maybe try posting on Stack Overflow or creating a new issue.

@dw235
Copy link

dw235 commented Feb 26, 2019

@dylanpinn How did you determine the resolvers (i.e. wordpress__POST, wordpress__PAGE, wordpress__wp_document)?

I'm trying to implement the plugin using Drupal source data. I keep coming up with the same error @seanngpack was experiencing, "The @gatsby-contrib/gatsby-plugin-elasticlunr-search plugin has generated no Gatsby nodes." I'm thinking my issue is due to not knowing the correct resolvers in my case.

Thanks.

@dylanpinn
Copy link

@dw235 I can't remember exactly but it was probably logging out all of the results from using the onCreateNode API (https://www.gatsbyjs.org/docs/node-apis/#onCreateNode) in my gatsby-node.js.

Easiest way I found to do this was to output the build results to a file which was easier to search through: gatsby build > output.log etc.

@dw235
Copy link

dw235 commented Feb 28, 2019

@dylanpinn Very helpful!

In my case, when using the gatsby-source-drupal plugin, my working gatsby-config.js looks like this:

   {
      resolve: `@gatsby-contrib/gatsby-plugin-elasticlunr-search`,
      options: {
        fields: [`title`],
        resolvers: {
          node__topic: {
            title: node => node.title,
            path: node => node.path.alias,
          },
        },
      },
    },

The resolver for content is node__content_type_name. In my case I have a Drupal content type called topic.

Thanks again!

@skrbnv
Copy link

skrbnv commented Mar 4, 2021

Just in case, if you are using prismic, this plugin is looking not for node.type but for node.internal.type which is different (for example "PrismicBlogPage" instead of "BlogPage")

@sean-gilmore
Copy link

For anyone using the gatsby-source-craft plugin, you can use the GraphQLI explorer to query for the expected Entry type and include the __typename field in the query to return the correct type for your resolver.

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

7 participants