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

Sporadic GraphQL Error #6

Closed
pgegenfurtner opened this issue Jan 14, 2018 · 16 comments
Closed

Sporadic GraphQL Error #6

pgegenfurtner opened this issue Jan 14, 2018 · 16 comments

Comments

@pgegenfurtner
Copy link

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
Copy link
Owner

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
Copy link
Owner

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
Copy link
Author

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
Copy link

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Owner

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
Copy link

joemidi commented Feb 20, 2018

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

@andrew-codes
Copy link
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
Copy link

cmwall commented Mar 23, 2018

Checking in to say I'm also getting this error

@mathieuforest
Copy link
Contributor

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
Copy link

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
Copy link
Contributor

@shwanton what is your data source?

@shwanton
Copy link

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
Copy link
Owner

@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! :-)

@ngnclht1102
Copy link

hey Andrew, I have just faced into that problem. I am using

"@gatsby-contrib/gatsby-plugin-elasticlunr-search": "^2.3.0",
 "gatsby": "^2.13.25",

My gatsby config:

...
{
      resolve: `@gatsby-contrib/gatsby-plugin-elasticlunr-search`,
      options: {
        // Fields to index
        fields: [`title`, `tags`],
        // 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
          MarkdownRemark: {
            title: node => node.frontmatter.title,
            tags: node => node.frontmatter.tags,
            path: node => node.frontmatter.path,
          },
        },
        // Optional filter to limit indexed nodes
        filter: (node, getNode) =>
          node.frontmatter.tags !== 'exempt',
      },
    }
...

The output message is:

success update schema - 0.077 s

 ERROR #85907  GRAPHQL

There was an error in your GraphQL query:

- Unknown field 'siteSearchIndex' on type 'Query'.

File: src/templates/blog-post/index.js

success extract queries from components - 0.372 s

I also cleared .cache, but it doesn't help!

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

No branches or pull requests

8 participants