Repository navigation
feat: pass adapter options to tRPC HTTP adapters - #118
yardenhochman wants to merge 1 commit into
Conversation
|
@yardenhochman is attempting to deploy a commit to the Kevin's Projects Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Thanks — the passthrough is something the library genuinely needs, and the ownership handling (module keys always win) is the right instinct. I want to change the shape before it merges, though, because this PR surfaced a bigger inconsistency in the options API that I'd rather fix once than paper over. Today TRPCModule.forRoot({
basePath: '/trpc',
context: AppContext, // DI class, module-owned
onError: AppErrorHandler, // DI class, module-owned
trpc: {
transformer: superjson,
allowMethodOverride: true,
responseMeta: (opts) => ({ ... }),
},
});The rule this gives users: NestJS-shaped options (DI classes, What that means concretely, beyond this PR's diff:
That's a fair bit more than you signed up for, so no pressure either way: happy to have you rework this PR to that shape, or I'll take it from here and credit this PR for the design push. Let me know which you'd prefer. |
Summary
TRPCModule.forRootcan now pass adapter-specific HTTP options through to the active tRPC Express or Fastify adapter. This keeps the existing behavior whenadapterOptionsis omitted and preserves NestJS tRPC's ownership of the router, context, and error handler.Problem
TRPCModule.forRootexposescontext,errorFormatter, andtransformer, but it has no way to configure the underlying adapter's other options. For example, tRPC v11'sallowMethodOverridelets a query procedure accept POST instead of GET. This matters when a query accepts a bulk array of IDs that exceeds URL-length limits, or contains PII that should not appear in query strings or access logs.The current workarounds require patching the driver or mounting translation middleware before NestJS tRPC's own mount point.
Solution
Add an optional, typed
adapterOptionsfield and pass it to both HTTP adapters. The adapter options are spread first, followed by the module-ownedrouter,createContext, andonErrorvalues, so callers cannot override them. This is a non-breaking change.Validation
bun run test— 17 suites and 78 tests passedts-heavy bun run build— passed