Introduce <DeferredQuery>
and useDeferredQuery
?
#35053
Unanswered
njbmartin
asked this question in
Ideas / Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
These are two GraphQL hooks I have been thinking about for some time, and looks like I'm not the only one: #2080 (@KyleAMathews)
Deferred Queries
This would be useful in instances where might want to keep the initial page query as light as possible (eg. SEO and placeholders), but once the client has loaded, you load the rest of the page data.
As a prime example, one of our
page-data.json
files is currently about 150kbs, mainly due to all the images. That's a considerable amount of "bloat" that would benefit from a trim, but at the moment we would have to use a server-side API query to achieve this (or, create a plugin?).Playing on the idea of
@defer
and using https://graphql.org/blog/2020-12-08-improving-latency-with-defer-and-stream-directives/ as an example:}
Data from fields marked with
@defer
would be separated out into a separate JSON file, and the page query would return adeferredRef
, which is derived from the payload, eg.There would then be a
deferred
JSON file generated at/deferred-data/d677628f-83ca-5d50-a746-22641fded3d5.json
:<DeferredQuery>
Your page might look something like this:
DeferredQuery
component is designed to reduce the impact of re-renders.useDeferredQuery
The alternative is the
useDeferredQuery
hook:Given that
@defer
is still in RFC, it might be best to use a Gatsby-specific directive like@GatsbyDefer
.Beta Was this translation helpful? Give feedback.
All reactions