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

Sporadic GraphQL Error #6

Closed
pgegenfurtner opened this Issue Jan 14, 2018 · 15 comments

Comments

Projects
None yet
7 participants
@pgegenfurtner

pgegenfurtner commented Jan 14, 2018

I'd like to implement this plugin into my site, but most of the times when I run gatsby develop, I get a GraphQL Error.

success delete html files from previous builds — 0.006 s
success open and validate gatsby-config.js — 0.004 s
success copy gatsby files — 0.022 s
success onPreBootstrap — 0.007 s
success source and transform nodes — 0.044 s
success building schema — 0.144 s
success createLayouts — 0.007 s
success createPages — 0.005 s
success createPagesStatefully — 0.014 s
success onPreExtractQueries — 0.001 s
success update schema — 0.092 s
GraphQL Error There was an error while compiling your site's GraphQL queries.
  Invariant Violation: GraphQLParser: Unknown field `siteSearchIndex` on type `RootQueryType`. Source: document `SearchIndexExampleQuery` file: `GraphQL request`.
    
success extract queries from components — 0.118 s
success run graphql queries — 0.013 s
success write out page data — 0.003 s
success write out redirect data — 0.001 s
success onPostBootstrap — 0.001 s

info bootstrap finished - 1.908 s

Here is my gatsby configuration:

module.exports = {
  plugins: [
    `gatsby-plugin-react-helmet`,
    `gatsby-plugin-catch-links`,
    `gatsby-plugin-styled-components`,
    `gatsby-plugin-sass`,
    {
      resolve: `gatsby-plugin-typography`,
      options: {
        pathToConfigModule: `src/utils/typography.js`,
      },
    },
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `posts`,
        path: `${__dirname}/src/pages/posts`,
      },
    },
    {
      resolve: `gatsby-transformer-remark`,
      options: {
        plugins: [
          {
            resolve: `gatsby-remark-prismjs`,
            options: {
              classPrefix: "language-",
            },
          },
        ],
      },
    },
    {
      resolve: `@andrew-codes/gatsby-plugin-elasticlunr-search`,
      options: {
        fields: [
          'title',
          'tags',
        ],
        resolvers: {
          MarkdownRemark: {
            title: node => node.frontmatter.title,
            tags: node => node.frontmatter.tags,
          },
        },
      },
    },
  ],
};

It seems it doesn't matter in which order the plugins are listed. 90% of the time, I get the error, sometimes it works.
Could this be a timing problem?

Thanks!

@andrew-codes

This comment has been minimized.

Owner

andrew-codes commented Jan 14, 2018

Hi, thanks for opening an issue :-)

Would you also post the SearchIndexExampleQuery query? In the times that it does not throw the above error, does the graphql query come through in the consuming component?

@andrew-codes

This comment has been minimized.

Owner

andrew-codes commented Jan 14, 2018

Actually, would you also try changing your graphql query to use SiteSearchIndex instead of siteSearchIndex? I am wondering if I have a typo in the example.

@pgegenfurtner

This comment has been minimized.

pgegenfurtner commented Jan 14, 2018

Thanks for your fast response!

Here is the query:

export const query = graphql`query
SearchIndexExampleQuery {
    siteSearchIndex {
        index
    }
}`;

The times it works it comes through to the consuming component.
When I change it to SiteSearchIndex it doesn't work either.

I tried to debug your plugin a bit (I'm not yet an expert in gatsbyjs) and found out, that on the exports.onCreateNode the check Object.keys(resolvers).indexOf(node.internal.type) === -1 resolves to true, so the node doesn't get created. Why that is I don't know, but maybe that helps you a bit.

@zelaznymarek

This comment has been minimized.

zelaznymarek commented Jan 16, 2018

I have same problem. I add plugin to gatsby-config.js as in Readme and then just try reach siteSearchIndex via GraphiQL, but its not there.

Edit: Seems that clearing gatsby's .cache folder helps. Maybe this will help :)

@pgegenfurtner

This comment has been minimized.

pgegenfurtner commented Jan 16, 2018

Clearing the cache works for me too. But I have to do it every time I restart the dev server. But it's a temporary solution :-)

@andrew-codes

This comment has been minimized.

Owner

andrew-codes commented Jan 18, 2018

Thank you for all the feedback and help. I will take a closer look at it this weekend possibly. Out of town across the country atm, but I'm going to try to take a closer look. Any additional help is greatly appreciated. :-)

@andrew-codes

This comment has been minimized.

Owner

andrew-codes commented Jan 26, 2018

Clearing the cache does seem like a workaround, but less than ideal. I am still trying to track down this issue. I have a demo site repo to use as a test bed (https://github.com/andrew-codes/gatsby-plugin-elasticlunr-search-demo)

@joemidi

This comment has been minimized.

joemidi commented Feb 20, 2018

Is this related to gatsbyjs/gatsby#3139 and subsequently fixed with gatsbyjs/gatsby#3218 ?

@andrew-codes

This comment has been minimized.

Owner

andrew-codes commented Feb 20, 2018

I upgraded to the latest gatsby@^1.0.0 version (1.9.203) and I still run into this issue. Without clearing gatsby's .cache directory, I get the error. The current workaround is to clear this directory before running, but this is intended as a workaround only and not a solution.

@cmwall

This comment has been minimized.

cmwall commented Mar 23, 2018

Checking in to say I'm also getting this error

@mathieuforest

This comment has been minimized.

Contributor

mathieuforest commented Mar 25, 2018

I've found out that the node get deleted in the gatsby staleNodes functions when rebuilded from cache. I still dont know why.

https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/utils/source-nodes.js

@shwanton

This comment has been minimized.

shwanton commented Mar 28, 2018

Seeing this issue as well, on latest versions of everything.

I've added a cache clearing script that runs before develop for the time being.

@andrew-codes andrew-codes reopened this Mar 30, 2018

@mathieuforest

This comment has been minimized.

Contributor

mathieuforest commented Mar 30, 2018

@shwanton what is your data source?

@shwanton

This comment has been minimized.

shwanton commented Apr 3, 2018

@mathieuforest I'm getting data from GraphCMS and creating my own nodes.

So I tried testing this today and this is working without clearing the cache.
I'm not sure what changed in the interim but all good over here.

@andrew-codes

This comment has been minimized.

Owner

andrew-codes commented Apr 4, 2018

@shwanton I did publish a new version with @mathieuforest's fix almost immediately before you submitted your comment to the issue. Perhaps the latest version fixed the issue for you? It was a patch version I believe.

I was successfully able to get @mathieuforest solution to work for me locally when I published the new version. If someone still has problems after version 1.0.4, please feel free to let me know. In the meantime, I will close this issue.

Thanks for everyone's help! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment