Repository navigation
Adding a streaming option for batched requests - #4346
Merged
Merged
Conversation
|
@Sheraff is attempting to deploy a commit to the trpc Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for Git βοΈ
|
1 task done
Sheraff
marked this pull request as ready for review
May 11, 2023 08:26
Sheraff
requested review from
KATT,
bautistaaa,
juliusmarminge,
sachinraja and
trpc-bot
as code owners
May 11, 2023 08:26
12 tasks done
Nick-Lucas
reviewed
May 12, 2023
| @@ -10,6 +10,9 @@ export interface BaseHandlerOptions<TRouter extends AnyRouter, TRequest> { | |||
| batching?: { | |||
| enabled: boolean; | |||
| }; | |||
Contributor
There was a problem hiding this comment.
My opinion of the public facing API:
batching?: { enabled: true, streaming: boolean } | { enabled: false }This branch had an error being deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
βοΈβοΈ
This PR was started on a fork of trpc, and has now been brought into trpc. Work will continue there: #4347
βοΈβοΈ
Closes #4343
π― Changes
Should work as is (though untested), but this doesn't (yet) actually handle the responses as a stream client-side.
yieldits results (still works for non-streamed responses, it's just the way of returning the responses that changes) https://github.com/Sheraff/trpc/blob/main/packages/server/src/adapters/node-http/nodeHTTPRequestHandler.tsresolveHTTPResponseis made to handle the request handlers yielding their results in several steps instead of a single return (https://github.com/Sheraff/trpc/blob/main/packages/server/src/http/resolveHTTPResponse.ts)The only major change (except for the streaming stuff obviously) is that the
datakey of the argument passed toopts.responseMetais now optional, because it cannot be known in the case of a streamed response. I haven't looked too deeply into how thisresponseMetafunction is declared, but if really necessary, we might be able to type it correctly so thatdatais not optional whenbatching: { enabled: boolean }isn't set totrueβ Checklist
π§ TODO
Transfer-Encoding: chunkedresponse header (stream parsing logic is available here: https://github.com/Sheraff/trpc-stream-poc/blob/master/public/script.js)nodeHTTPRequestHandler