᲼᲼᲼
᲼᲼᲼
TTCTheo's Typesafe Cult
Created by ᲼᲼᲼ on 4/27/2023 in #questions
Using tRPC to connect to two different apis
I have a create-t3-app where I am using tRPC for the api. It works great but I need to run a separate server for some long-running tasks (which won't fit on vercel) and I want to use trpc for that too. I created a separate createTRPCNext for it, and in _app.tsx I have:
return secondApi.withTRPC(api.withTRPC(MyApp));
return secondApi.withTRPC(api.withTRPC(MyApp));
The problem is that tRPC only looks at the inner context no matter which api I use in my code, and requests are sent to it. Is there a way to have the 2 contexts not get confused by tRPC?
5 replies
TTCTheo's Typesafe Cult
Created by ᲼᲼᲼ on 4/19/2023 in #questions
In create-t3-app how to get tRPC zod schema on client?
I know we have RouterInputs to get the input type, but can we get the zod schema to validate things on the client? Of course we could just export the schema from each router file and import it in the client, but I imagine something like this would be very ergonomic:
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { api } from "~/utils/api";

const App = () => {
const { mutate, inputSchema } = api.exampleRouter.example.useMutation();
const { handleSubmit, register } = useForm({
resolver: zodResolver(inputSchema)
});
// ...
}
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { api } from "~/utils/api";

const App = () => {
const { mutate, inputSchema } = api.exampleRouter.example.useMutation();
const { handleSubmit, register } = useForm({
resolver: zodResolver(inputSchema)
});
// ...
}
(this is just an example, it could be a different object for the schemas) What do you think?
9 replies