[RFC] useLazyFragment hook
- Dominant language
- Rust
- Stars
- 19k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
I'd like to be able to fetch parts of a query only when the component calling a new "useLazyFragment" hook is rendered.
Think of a page that has many tabs with a lot of data to be rendered inside these tabs. It would be wasteful to fetch all data from all tabs when the user might not click any of them. Using this hook, when the user clicks a tab the component would suspend and a query generated by the compiler (similar to useRefetchableQuery) would be fired to get the data that tab needs.
Another good case for this is a list of items and when you click an item it expands to show more details. You could write another query for the item's details but with this hook Relay would generate the query for you.
The current solution is to fire separate queries in each tab, which imo isn't a satisfying approach in many cases. This hook would let the user take even more advantage of graphql's schema composability, and the server would need to write less queries.
Contributor guide
Assessment
This issue has not been assessed yet.