Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exploration for Apollo Client integration #2698

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

phryneas
Copy link

@phryneas phryneas commented Nov 4, 2024

I made a 15 minute video explaining some of the thoughts behind this, so that might be a starting point :)

https://www.youtube.com/watch?v=G-8Q_o2eKhg


This just copies over another example page so you can kinda ignore the first commit when looking at the diff.

Comment on lines +125 to +135
streamedValues: new Proxy(
{},
{
set(t, key, v) {
const res = Reflect.set(t, key, v)
window.__TSR__ROUTER__ &&
__TSR__ROUTER__.emit({ type: 'onStreamedValue', key })
return res
},
},
),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Streamed values arriving now emits a router event.


const handledEvents = new WeakSet<object>()

export const ApolloProvider = WrapApolloProvider((props) => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is essentially all that's needed for Apollo Client streaming SSR integration with fetch-as-you-render (useSuspenseQuery etc).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would end up in it's own package, I guess?

// @ts-ignore unavoidable due to the ternary in arguments
router.options.context.preloadQuery =
createTransportedQueryPreloader(apolloClient)
router.options.transformer = defaultTransformer.withTransformers([
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm gonna be honest, I would prefer to have a router.options.transformers option - that way we could merge user-supplied transformers with "library-supplied" ones, which is currently not possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant