Repository navigation
Conversation
|
@iamnafets is attempting to deploy a commit to the trpc Team on Vercel. A member of the Team first needs to authorize it. |
react-query server client) Streaming results from mutations and queries
|
|
I really wish you hadn't done this much work already because I don't think a generator is the right API for streaming. This also complicates the code a lot right now and in the future (adds 2 new procedure types!). Something like what SvelteKit does would probably be better. |
I'm not too worried about it. This is mostly a draft. If you have a better idea on what the API should be, feel free to comment on the attached feature issue. |
|
Remix does something similar to what SvelteKit does, doesn't it? I find their implementation a little more readable:
and they only parse promises at level 0 of the object, no recursion, nesting, ... It's not too complicated to do. But my eternal question is always the same: what do you give the client and when, what to do put in the cache? Receiving a And if you want an "arbitrarily long list" of promises (à la openAI API for chatGPT) you need recursion. Which can probably be done, but again, not sure about the client-side DX. |
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
Superseded #4911 |
Closes #4477
🎯 Changes
This change (1) introduces a
queryGeneratorandmutationGeneratormethod to the client, and (2) adds a streamingData state to useQuery and useMutation. The developer experience is that you can now implement your query or mutation function with an AsyncGenerator (e.g.async function*) and retrieve every emitted event on the client side.Caveats:
next-minimal-starter, I'll fix that (among other things) before requesting a proper review.Notes:
queryandmutation. It forces the developer to think properly about the boundaries of the request as opposed to callbacks or observables which seem like they can be persistent but actually are not.useQuerythat simply overrode the data throughsetQueryDataeach time it had a new chunk. This blew up theloadingsemantics and felt rather hacky so thestreamingDatastate is a bit cleaner.✅ Checklist