I use react-router and both pages preload those queries. Both pages also render , the difference is that details page also renders some additional component on the page
Question:
When I go to the details page I want to be immediately displayed since all the data is already in the cache and suspend rendering only for components that require someOtherPropN. How am I supposed to achieve this? Since queries requires different set of fields useReadQuery will suspend until all the data is fetched.
I think what I’m wishing for is something like useReadQuery(queryRef, {fragment: ItemCardFragment})
Workarounds:
I can think of a couple of workarounds:
Split the query for the details page, e.g. itemCardProps: item() {...ItemCardFragment} and item() {someOtherPropN}. Then I can use useReadQuery for specific queryRef. The downside is that Apollo will make two network request when I go to that page by url. (maybe can be worked around with some batching technique?)
Use useFragment for the part that uses ItemCard. Move useReadQuery under suspense somewhere along the tree. I’m currently using this approach
That is currently still on our Roadmap. We are currently working on Data Masking, and as soon as that’s done we’ll get to the suspenseful useFragment story.
Both of your workarounds seem currently viable - you’ll have to decide for yourself, which tradeoffs work better for you.