Gatsby: [1.0] Adding graphql query in layouts/index.js is not allowed

Created on 15 Jun 2017  路  11Comments  路  Source: gatsbyjs/gatsby

  • Request a feature where I can add the graphql query (for instance a sitemap) to automatically load the sidebar links.
  • The index.js contains the body of the page with the sidebar being one of the component in the tree.
  • Now if I use the graphql query as any other query in pages/<>, I get a violation as show below:
UNHANDLED REJECTION Invariant Violation: Path /Users/vaitsund/my-blog/src/layouts/index.js not found in the store pages: {"/Users/vaitsund/my-blog/.cache/dev-404-page.js":{"componentPath":"/User
<snip>
  • This is required since I cannot feed the props into the sidebar from pages/<>

Excerpt from #gatsby channel with @KyleAMathews

ideally layouts could have their own query
but that hasn't been implemented yet
so... yeah, the situation isn't too ideal

Details:

  • OS: Mac OS
  • Node: v7.7.4
  • NPM: 4.1.2
  • Gatsby: 1.0.0-alpha.23
help wanted

Most helpful comment

Upvoting for this feature. Layout querying is really helpful when adding global component with data props. eg. a Nav bar component requiring the pathnames from graphql for Linking

All 11 comments

Upvoting for this feature. Layout querying is really helpful when adding global component with data props. eg. a Nav bar component requiring the pathnames from graphql for Linking

Has anyone else looked at this yet? I've spent a bunch of time this week and last trying to figure out how to best take care of this. It really cuts into the guts of Gatsby though so a lot of code to cover. I would greatly appreciate any assistance!

I suspect we will end up taking care of #1255 at the same time.

1206 is a duplicate.

@jbolda I gave it a shot because I really need it but gave up for the moment. As you said, it's not just a one-line fix to change the search directory.

I started working on dealing with layouts as page components. It... feels kind of... dirty? @KyleAMathews Have you thought about it at all? Wondering if we add another api for createLayout similar to createPage.
https ://github.com/jbolda/gatsby/commit/9fe2b1b84fca1d00697285b7a12d1f9e8de9195a

I can work on it some tonight, and maybe tomorrow and then I need to get back on client work for a while. Looking like I might not get this shipped.

cc @delta98 as he is taking a look at things as well.

Actually had started to talk about this in #553

This was added in #1503.

Appreciate an example of the implementation

@GoChartingAdmin

Example here

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andykais picture andykais  路  3Comments

signalwerk picture signalwerk  路  3Comments

KyleAMathews picture KyleAMathews  路  3Comments

dustinhorton picture dustinhorton  路  3Comments

magicly picture magicly  路  3Comments