Imagine a main page at url path /
with components ComponentA
, ComponentB
and ComponentMain
. So maybe something like this:
Instead of ComponentA
, ComponentB
and ComponentMain
each making a single GraphQl query on their own, one could hoist up the state and then make one huge query and pass down the needed data to each component. All fine with that. But imagine a user navigates and the content of ComponentMain
changes. There are two different ways of navigating:
- User is already on
/
and clicks some link which changes the content ofMainComponent
. In that case the data forComponentA
andComponentB
is already available from the user's initial call to/
. I only want to load the data forMainComponent
, not again the data forComponentA
andComponentB
. - User is not already on the page, but directly uses a link like
/someOtherMainContent
. In that case, the data forComponentA
andComponentB
isn't loaded yet. All data (ComponentA
,ComponentB
,ComponentMain
) needs to be loaded.
I could code all that logic manually from ground up, but that would be very cumbersome. Is relayjs
capable of exactly doing such things? Is that possible with Apollo Client
? Is there any pattern for this?
I am using React via NextJs 13 and a GraphQl backend (currently independent from NextJs, coded using ASP.Net Core and HotChocolate GraphQl server).