Closed masimplo closed 4 years ago
We currently don't support static queries defined in places other than current site. This is something we will need to implement, just not yet sure how exactly we will do that, because we need to parse all files to extract those queries and examining all files in node_modules
is just very expensive and not very viable.
This is also why we didn't yet publish standalone SEO component that we use in our starters (f.e. in https://github.com/gatsbyjs/gatsby-starter-default/blob/master/src/components/seo.js) because that StaticQuery would not be currently picked up by Gatsby
/cc @DSchau
Hey,
I'm facing the same problem in a different context. My theme has a component that uses useStaticQuery
hooks. My theme works fine.
But when my website want to use this hook, it's another story. I have this error (Error: The result of this StaticQuery could not be fetched.). If I remove the hooks, I don't have error.
I don't understand because I took inspiration from jason-theme(https://github.com/jlengstorf/gatsby-theme-jason-blog/blob/master/src/hooks/use-site-metadata.js).
@jlengstorf: you did something specific to bypass this error? (gatsby-theme-jason-blog
and lengstorf.com
doesn't seems to be a monorepo...).
Cheers
@maxpou do you have the code somewhere we can poke at? Iβm pretty sure this got patched, but I could be wrong. @ChristopherBiscardi didn't we get static queries working in themes, or am I doing magic somehow?
@maxpou the algorithm for this is here. If you're using your theme in gatsby-config.js it should make its way into the query compiler and be extracted.
If at all possible, as @jlengstorf mentioned, a reproduction would be super helpful!
Hey guys, Thank you so much for your time. It seems that the problem disappear after clearing the cache folder. I didn't cleaned Gastby's cache since a while... that's what happens when we play with experimental features. Cheers
Hiya!
This issue has gone quiet. Spooky quiet. π»
We get a lot of issues, so we currently close issues after 30 days of inactivity. Itβs been at least 20 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!
Thanks for being a part of the Gatsby community! πͺπ
@maxpou had another issue involving static queries in a theme that has been resolved but I think @masimplo's originial issue is still unresolved.
Supporting static queries defined in places other than the current site
It looks like there is some potential to resolve this using themes or potentially listing packages that contain static queries in the gatsby-config
but it's unclear what that would look like and a PR is missing.
To anyone landing here that still can't resolve their issue, make sure you're not using a component inside wrapRootElement
(in gatsby-browser.js) that uses StaticQuery
or useStaticQuery
. Tricky, but that was the problem for me.
We've since added support for queries in arbitrary packages as long as the package has gatsby
in its name.
Closing this since this is no longer an issue as a result. Thanks!
We've since added support for queries in arbitrary packages as long as the package has
gatsby
in its name.Closing this since this is no longer an issue as a result. Thanks!
Hi @sidharthachatterjee, does this mean as per https://www.gatsbyjs.org/blog/2019-01-01-publish-multiple-gatsby-sites/ the package.json name key needs to contain the word gatsby in it for it to work with static queries?
Is it possible to expose a way to configure this keyword(s)?
Ref:
Yes. The package name needs to contain the gatsby
keyword. Configuration is currently not supported.
We do this to keep expectations clear for users that a library contains gatsby
components (React components that use Gatsby queries)
We did consider using peer dependencies for this heuristic but that was slow and there is prior art for a name based heuristic (like babel and eslint plugins)
I faced the same issue and I can confirm that by following the solution provided by @sidharthachatterjee works!
In summary, if you have a package called shared-ui
:
gatsby-shared-ui
Now you should be able to use StaticQuery
and useStaticQuery
π
We've since added support for queries in arbitrary packages as long as the package has gatsby in its name. Closing this since this is no longer an issue as a result. Thanks!
Wish I had seen this before
If you have a gatsby-ui package written in TypeScript, and you have static query in there (in hooks or components), it will fail if you compile that package to .js files.
What I did is import my src TypeScript files directly so Gatsby would stop seeing the same queries twice
IMO that behavior should be explicit and controllable by user cc @sidharthachatterjee
Description
I have a StaticQuery inside a component that is not executed. The component is part of a shared-ui package of a monorepo. Another package of the monorepo imports the shared-ui package in order to use it.
Steps to reproduce
Following this Gatsby blog post I have created a project that has 3 packages. One shared-ui and two Gatsby sites. In the shared-ui I have defined a SEO component that has this static query:
I then include this component in a gatsby site package (called site) like:
shared-ui package.json:
site package.json:
root package.json:
Expected result
The query should be executed as normal and results should be returned.
Actual result
I get an error:
Note: this query executes correctly and brings back data when executed inside the GraphQL explorer.
Moving the component in the site package instead of the shared-ui, makes the error go away.
Environment
Run
gatsby info --clipboard
in your project directory and paste the output here.