-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Add an API to load some data at runtime #24292
Comments
FIrst of all - the stacked pages is pretty slick! Nice job!
I'd like to clarify - what's the environemnt/context where this would be used - would this be in frontend code or in gatsby-node? |
In gatsby-node. We define the “static API” beforehand, the id being its “endpoint” |
If that's the case - I do wonder if this need to be in
|
I'm not saying we completely wouldn't want it in core (eventually) - we are working on something that while not exactly touch on this subject, can be somewhat related - #18689 (comment) - particularly
for above case - we could actually be solved with using What I'm getting on here is - we want stuff like this to have coherent API and not duplicate very similar APIs multiple times - with potential solution being done in user land today (at least in meantime) I think there is no "rush" to implement this in core. What are your thoughts on that? |
Oh yeah for sure a consistent API is key. Agree there is no rush, I’m happy with my workaround for now (as I don’t expect Feel free to consider this as a use case for the API you have in mind then 🙂 |
For sure! There are also other possibilities here (but those might not fit the use case for stacked pages): Like you could have export const pageQuery = graphql`
{
someCriticalData {
fieldsForCriticalData
}
someNotCriticalData @lazy {
fields
}
}
` and inside component you could do data.someNotCriticalData().then(lazyData => { /* do stuff */}) We are exploring lot of options like this. They might not fit this use case because powerful part of your proposal is running them in gatsby-node which means you have a lot more flexibility when it comes to query construction or even deciding how to chunk those (creating results for each possible page that could be "stacked" might not really be possible with just |
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. Thanks for being a part of the Gatsby community! 💪💜 |
Hey again! It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it. Thanks again for being part of the Gatsby community! 💪💜 |
Summary
Add an API to load some specific queries from graphql at runtime.
I can imagine a new plugin API to expose a query with an id:
and a client-side method to fetch it:
This is different from
useStaticQuery
because the client can dynamically fetch any static query, effectively creating a "static API".Expose
window.___loader
as an API so that React code can leverage its functionality (or perhaps only part of it)Motivation
I wanted to create a "stacked" page navigation like this: https://twitter.com/aravindballa/status/1263112947670245377?s=20
That means loading data from notes at runtime (because it'd be too complex to generate all possible permutations at build time).
Workaround
I had a
stupidcrazy idea but had an epiphany that the data I wanted was already accessible: it's the pages data. So I foundwindow.___loader
and managed to dynamically load the data from a page (like gatsby is doing withLink
). The code is here: https://github.com/mathieudutour/gatsby-n-roamresearch/tree/master/packages/react-stacked-pages-hook.While this works (and a quick and dirty first step could be to expose
window.___loader
as an official API), I believe my proposal is more generic, powerful, and unlocks more use cases.References
https://twitter.com/kylemathews/status/1263254949816709120?s=20
The text was updated successfully, but these errors were encountered: