tRPCttRPC
Powered by
njwagsN
tRPC•3y ago•
2 replies
njwags

One router multiple adapters?

Hey all!
This might be misguided question, but I'm working on building an api with tRPC that will be connected to via two clients. One is a Next app and one is a CLI built with node.js via yargs. The next app is hosted via vercel, and the api is running on the vercel instance with
experimental_createTRPCNextAppDirServer
experimental_createTRPCNextAppDirServer
and the
fetchRequestHandler
fetchRequestHandler
from the fetch adapter.
The cli can connect and the web app works and all is well, but...
I'm trying to write integration tests for the CLI and I was hoping to use the standalone adapter to run the api during tests. https://trpc.io/docs/server/adapters/standalone

The error I'm running into is a type mismatch for the
createContext
createContext
option. The two adapters seem to expect different types for the createContext option. Because of the line of generics associated with the two types, the actual type error message is about 43,000 characters... So including it here isn't possible.
It boils down to:
'(opts?: FetchCreateContextFnOptions | undefined) => Promise<{ session: Session; responseCookies: ResponseCookies; headers: { [k: string]: string; } | undefined; }>'
'(opts?: FetchCreateContextFnOptions | undefined) => Promise<{ session: Session; responseCookies: ResponseCookies; headers: { [k: string]: string; } | undefined; }>'
is not assignable to
type 'NodeHTTPCreateContextFn<CreateRouterInner<RootConfig<... and so on
type 'NodeHTTPCreateContextFn<CreateRouterInner<RootConfig<... and so on
.

TL;DR; My questions are:
Has anyone tried using the same router with multiple adapters?
Is there a better approach to setting up a tRPC api that's used via two different adapters?
Is there some other way to accomplish these kind of integration tests?
Maybe I'm just making somekind of dumb typescript mistake?

Thanks for any advice!
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

CreateCaller for router with AWS Adapters
MaxMMax / ❓-help
11mo ago
Multiple .meta in one route
DevPandaDDevPanda / ❓-help
9mo ago