Skip to content

feat(httpBatchLink): alternative DX streamRequester for batch streaming - #4403

Merged
Sheraff merged 7 commits into
feat/out-of-order-batch-responsefrom
feat/out-of-order-batch-response-alternative-dx
May 25, 2023
Merged

Sheraff merged 7 commits into
feat/out-of-order-batch-responsefrom
feat/out-of-order-batch-response-alternative-dx

Conversation

@Sheraff

@Sheraff Sheraff commented May 22, 2023 •

Copy link
Copy Markdown
Contributor

Proposal for #4347

πŸ“° Update

The requester option proposal was rejected, but this PR is still better for code-sharing between regular batch link and stream batch link, so I used it as a base to refactor into 2 separate links httpBatchLink and unstable_httpBatchStreamLink that share most of their code. This still allows for DRY and tree-shakeable code.

🎯 Changes

Avoid duplicating httpBatchLink logic into httpBatchStreamLink by simply allowing for the single part that is different (the fetch method) to be passed as an option in the instantiation of the link.

Allows for

  • DRYer code
  • tree shaking

The new option is called requester and defaults to the "normal" batchRequester:

httpBatchLink({
  requester: unstable_streamRequester,
})

Another possibility (though not what is implemented here) would be to have a loader option (instead of the requester option) which would include the validate method in addition to the fetch method. While it's not required in this case, it might be a good way to future-proof this option.

βœ… 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 May 22, 2023 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
next-prisma-starter βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback May 25, 2023 6:42pm
og-image βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback May 25, 2023 6:42pm
www βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback May 25, 2023 6:42pm

Comment thread www/docs/client/links/httpBatchLink.md Resolved

This branch was successfully deployed

4 active deployments
Preview – www β€” 75669853 Deployed May 25, 2023 by vercel[bot]
Preview – next-prisma-starter β€” 75669853 Deployed May 25, 2023 by vercel[bot]
Preview – todomvc β€” 75669853 Deployed May 25, 2023 by vercel[bot]
Preview – og-image β€” 75669853 Deployed May 25, 2023 by vercel[bot]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

@trpc/client @trpc/server πŸ•Έ www Stuff to do with the website (`/www` folder)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants