tRPCttRPC
Powered by
hashwarpH
tRPC•17mo ago•
1 reply
hashwarp

Typing on trpc.createClient?

Basically I want an asyncQuery I can call later, the way asyncMutate works. I can do this:
          const profileData = await trpcClient.query(
            'seer.evolution.getProfile',
            'name'
          );
          const profileData = await trpcClient.query(
            'seer.evolution.getProfile',
            'name'
          );

But I can't do this:
          const profileData = await trpcClient.seer.evolution.getProfile.query('name');
          const profileData = await trpcClient.seer.evolution.getProfile.query('name');

My code is like this:

// Define the merged router type
type MergedRouter = {
  relay: RelayRouter;
  evolution: EvolutionRouter;
  seer: SeerRouter;
};

// Initialize tRPC with the merged context if needed
const t = initTRPC
  .context<{
    // Define any shared context here if necessary
  }>()
  .create();

// Create the root router
export const createRouter = () =>
  t.router<MergedRouter>({
    relay: createRelayRouter(),
    evolution: createEvolutionRouter(),
    seer: createSeerRouter(),
  });

// Create a single tRPC instance
export const trpc = createTRPCReact<AppRouter>();

// Create the tRPC client with the combined link
export const trpcClient = trpc.createClient({
  links: [combinedLink],
});
// Define the merged router type
type MergedRouter = {
  relay: RelayRouter;
  evolution: EvolutionRouter;
  seer: SeerRouter;
};

// Initialize tRPC with the merged context if needed
const t = initTRPC
  .context<{
    // Define any shared context here if necessary
  }>()
  .create();

// Create the root router
export const createRouter = () =>
  t.router<MergedRouter>({
    relay: createRelayRouter(),
    evolution: createEvolutionRouter(),
    seer: createSeerRouter(),
  });

// Create a single tRPC instance
export const trpc = createTRPCReact<AppRouter>();

// Create the tRPC client with the combined link
export const trpcClient = trpc.createClient({
  links: [combinedLink],
});


Version: v11
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

How does trpc typing work
Mohammed AnasMMohammed Anas / ❓-help
3y ago
Typing a shared TRPC provider for testing
itsravenousIitsravenous / ❓-help
3y ago
Property 'createClient' does not exist on type
Answer OverflowAAnswer Overflow / ❓-help
3y ago
Why are `new QueryClient` and `trpc.createClient` run inside a component in the React setup?
functiondjFfunctiondj / ❓-help
2y ago