eggheadio / gatsby-starter-egghead-blog

This is an example Gatsby blog site that we use as a reference at egghead.
https://egghead-gatsby-starter.netlify.com/
MIT License
517 stars 82 forks source link

warning The GraphQL query in the non-page component ".../Header.js" will not be run. #21

Closed frankstallone closed 5 years ago

frankstallone commented 5 years ago

Getting the following warning when running npm run build:

warning The GraphQL query in the non-page component "[local folder]/src/components/Header.js" will not be run.
Exported queries are only executed for Page components. It's possible you're
trying to create pages in your gatsby-node.js and that's failing for some
reason.

If the failing component(s) is a regular component and not intended to be a page
component, you generally want to use a <StaticQuery> (https://gatsbyjs.org/docs/static-query)
instead of exporting a page query.

If you're more experienced with GraphQL, you can also export GraphQL
fragments from components and compose the fragments in the Page component

This can be recreated by doing a gatsby new gatsby-starter-egghead-blog https://github.com:eggheadio/gatsby-starter-egghead-blog.git and running npm run build.

theianjones commented 5 years ago

Thanks for reporting this @frankstallone!

frankstallone commented 5 years ago

Np @ijones16 -- I wish I was knowledgeable enough with GraphQL to send a pull request instead. Soon!

theianjones commented 5 years ago

My solution is here if you want to take a look https://github.com/eggheadio/gatsby-starter-egghead-blog/pull/23/files.

The other way to do it is just get rid of the StaticQuery method altogether and pass in the siteTitle in as a prop. I chose to use graphql in the case because I dont want siteTitle to be a dependency everytime you pull in the header.