[v2][RFC] Deprecate page queries completely and replace with StaticQuery?
See original GitHub issueSeveral people have suggested this and it’s started feeling better and better over time.
It’d definitely better to have one pattern for queries rather than two. And the reaction to <StaticQuery>
seems positive.
We’d have to add support for <StaticQueries>
getting variables passed to them when they’re on pages. Which felt weird as that’s “magical” but… it’s no less magical than the existing page queries. Less since it has a component tied to it.
Oh hmmm… just had a thought — we could create a <PageQuery>
component that’s identical to <StaticQuery>
except it takes variables 🤔
Thoughts?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:7
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Loading (Static Query) · Issue #6350 · gatsbyjs/gatsby - GitHub
Right now I am doing a page-level query the old way and then have imported components with static queries being performed in them....
Read more >Querying Data in Components using StaticQuery - Gatsby
Please note: As of Gatsby 5 the <StaticQuery /> component is deprecated. Use the useStaticQuery hook instead. <StaticQuery /> will be removed in...
Read more >How to reduce static query code duplication Gatsby JS
I was wondering if it is possible to remove this duplication by using the querying capabilities more efficiently? I've read that Gatsby static ......
Read more >Storybook-addon-gatsby: How to Override Options in babel ...
The addon provides the stage and staticQueryDir options to babel-plugin-remove-graphql-queries , just like your example. It also configures ...
Read more >babel-plugin-remove-graphql-queries | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
FWIW, I personally would find it much more intuitive if there were just a single query component, and that the entire pageQuery magic would be removed.
As I am used to Apollo, I would absolutely love it if the query component was similar. I will show this with a complete example to clarify my thoughts.
Old style:
Suggested style:
Obviously code could be restructured with the query being at the bottom, if desired. It is a little more boilerplate on each page that uses a query - but it would remove all the magic and allow for much more options on how to query.
Also, loading state in Gatsby is now hardcoded to
<div>Loading (StaticQuery)</div>
, and probably error state causes some error handler to be invoked. The Apollo way lets the page handle both as it sees fit.This issue is being closed due to inactivity. Is this a mistake? Please re-open this issue or create a new issue.