Skip to content

feat: streamable procedure support - #4530

Closed
helmturner wants to merge 11 commits into
trpc:mainfrom
helmturner:feat-helmturner-streaming-procedures
Closed

helmturner wants to merge 11 commits into
trpc:mainfrom
helmturner:feat-helmturner-streaming-procedures

Conversation

@helmturner

@helmturner helmturner commented Jun 15, 2023 •

Copy link
Copy Markdown

revert(server): roll back node adapter to 0aaf147;
revert(server): roll back fetch adapter to 0aaf147;
revert(server): roll back fastify adapter to ababea8;

Closes #4477

🎯 Changes

What changes are made in this PR? Is it a feature or a bug fix?

  • Reverts adapters to pre-httpBatchLink versions and extracts response-body creation logic into separate modules
  • Enables ReadableStream bodies to be created by and returned from resolveHTTPResponse
  • Sets the stage for eagerly streaming queries

✅ Checklist

  • I have followed the steps listed in the Contributing guide.
  • If necessary, I have added documentation related to the changes made.
  • I have added or updated the tests related to the changes made.

@vercel

vercel Bot commented Jun 15, 2023

Copy link
Copy Markdown

@helmturner is attempting to deploy a commit to the trpc Team on Vercel.

A member of the Team first needs to authorize it.

@vercel

vercel Bot commented Jun 15, 2023 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
trpc-next-app-dir ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 22, 2023 0:12am
www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 22, 2023 0:12am

@helmturner helmturner changed the title revert(server): roll back node adapter to 0aaf147; feat: streamable procedure report Jun 15, 2023
@helmturner helmturner changed the title feat: streamable procedure report feat: streamable procedure support Jun 15, 2023
@marschr marschr mentioned this pull request Sep 15, 2023
1 task done
@helmturner

helmturner commented Oct 12, 2023 •

Copy link
Copy Markdown
Author

On further, further investigation... I'm not actually reading out of order, at least in most cases. Everything works pretty well, actually. There are plenty of successful tests for both batch and single procedure calls. Save for some edge cases and some adapter issues, looks like this is working? Merging main brought it to 50 failing tests, but I made some small changes and cut that to 36 failing tests - a personal best, so far!

Edit: 13 of the failing tests (namely, those for Next.js and custom http response codes are failing because they expect status codes–which are impossible to determine before we start streaming. That's why I chose to default to 207 (multi-status), but it was a bit of a quick decision that I forgot to RFC 😅

How do we want to handle that? My thought was to include "status codes" in the response body (indicated by the 207 status code) and parse them back out on the client.

Comment on lines +193 to +197
// We're not streaming, so we need to resolve the generator and return the complete result
let done;
let value;

while (!done) ({ done, value } = await chunks.next());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should just throw here instead and have the rule if you request an async generator, you have to use a transport/http link that supports it

@helmturner helmturner Oct 12, 2023 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It seems intuitive that returning a generator from a tRPC resolver wouldn't work without additional configuration. I guess my thought was preserving compatibility in the case you have multiple clients in heterogenous runtimes with varying degrees of streaming support, e.g. native mobile and web.

My toy use-case for the SSE side of things was the GPT4 API, but blocking in a native app until the response completes is a pretty crap experience in that scenario, so it's probably an unrealistic edge-case unless there's some other scenario where blocking for an otherwise-streamed response is acceptable UX.

@KATT

KATT commented Nov 17, 2023

Copy link
Copy Markdown
Member

#4911

@KATT KATT closed this Nov 17, 2023
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Dec 17, 2023

This branch was successfully deployed

3 active deployments
Preview – www — eb65321d Deployed Oct 22, 2023 by vercel[bot]
Preview – trpc-next-app-dir — eb65321d Deployed Oct 22, 2023 by vercel[bot]
Preview – todomvc — eb65321d Deployed Oct 22, 2023 by vercel[bot]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Streaming Mutations / Queries

2 participants