Red Max
Red Max
TtRPC
Created by Red Max on 1/25/2023 in #❓-help
All vanilla client queries fail with 500. Setup problem?
I'm using NextJS but using the vanilla client to integrate trpc calls into my custom hooks. But, even when using the NextJS queries, they also fail with a 500. I am completely stuck with my project until I can get this resolved. Any help is greatly appreciated. The call requires no input so I have tried it two different ways. When the router's .input is omitted the request URL is /api/trpc/generateRandomWorker?batch=1&input={"0":{"json":null,"meta":{"values":["undefined"]}}} and returns a 500. When the router's .input is z.null() the request URL is /api/trpc/generateRandomWorker?batch=1&input={"0":{"json":null}} and returns a 500. Here is the hook I am using with vanilla client queries and the router setup.
const useCreateRandomWorker = (): ReturnType => {

const [isCreating, setIsCreating] = useState(false);

const createWorker = async (): Promise<Worker> => {

setIsCreating(true);

const randomWorker: CreateWorker = await client.generateRandomWorker.query(null);

const createdWorker: Worker = await client.createWorker.mutate(randomWorker);

setIsCreating(false);

return createdWorker;
}

return { createWorker, isCreating };

}
const useCreateRandomWorker = (): ReturnType => {

const [isCreating, setIsCreating] = useState(false);

const createWorker = async (): Promise<Worker> => {

setIsCreating(true);

const randomWorker: CreateWorker = await client.generateRandomWorker.query(null);

const createdWorker: Worker = await client.createWorker.mutate(randomWorker);

setIsCreating(false);

return createdWorker;
}

return { createWorker, isCreating };

}
export const WorkerRouter = router({
generateRandomWorker: procedure
.input(z.null()) // <---- I have tried completely omitting `.input` and with a `null` property
.output(PrismaWorkerCreateInputSchema)
.query(() => WorkerService.generateRandomWorker()),
getAllWorkers: procedure
.input(z.null())
.output(z.array(WorkerSchema))
.query(async () => await WorkerService.getAllWorkers()),
createWorker: procedure
.input(PrismaWorkerCreateInputSchema)
.output(WorkerSchema)
.mutation(async ({ input }) => await WorkerService.createWorker(input)),
});
export const WorkerRouter = router({
generateRandomWorker: procedure
.input(z.null()) // <---- I have tried completely omitting `.input` and with a `null` property
.output(PrismaWorkerCreateInputSchema)
.query(() => WorkerService.generateRandomWorker()),
getAllWorkers: procedure
.input(z.null())
.output(z.array(WorkerSchema))
.query(async () => await WorkerService.getAllWorkers()),
createWorker: procedure
.input(PrismaWorkerCreateInputSchema)
.output(WorkerSchema)
.mutation(async ({ input }) => await WorkerService.createWorker(input)),
});
6 replies