relayjs / relay-examples

A collection of sample Relay applications
MIT License
1.14k stars 433 forks source link

[WIP] Possible evolution of the Relay integration with Next.js v13 #270

Open alunyov opened 1 year ago

alunyov commented 1 year ago

Note: This is WIP and not ready to be merged. I’m sharing for feedback and adjustments on the direction.

Summary:

Note on the API naming: we may want to name these useFragment and fetchQuery differently, to avoid possible confusion with similar APIs for react-relay and relay-runtime.


So, this is a “sketch” of the possible integration, so many things may not work:

Not sure if it’s working:

alvarlagerlof commented 1 year ago

I wonder if this could work with fetch-multipart-graphql. Part of the benefit of server components without GraphQL (right now) is being able to load different things at different rates with different suspense boundaries.

If we can have a fragment await until it get's the data that it needs, and then have them nested, and some of them using @defer, that would make the Server components experience for this very very nice. You could have skeletons at different levels of data fetched while still only using client components at the leafs.

I have been trying to look into how Relay works internally to understand if it's possible. I think, if the hooks right now are able to suspend until deferred data is loaded, it should "in theory" be a matter of instead being able to await the data for a fragment instead.

tbezman commented 1 year ago

@alunyov any updates to share?

alunyov commented 1 year ago

@alunyov any updates to share?

Sorry, no real updates here. I'm on parental leave, maybe I will get back to this in a few month.

tinleym commented 1 year ago

This might run into garbage collection issues without usePreloadedQuery/useQuery or environment.retain()... I ran into this with a similar setup when I was running multiple queries on input events after the page fetch.