RealityShift
RealityShift
TtRPC
Created by RealityShift on 12/12/2023 in #❓-help
useUtils vs useQueryClient
I'm trying to use the useUtils hook but I'm unsure if I'm doing it correctly? It doesn't seem to work but using useQueryClient does. Here is some code:
const queryClient = useQueryClient();
const services = api.list.services({query: query});
const utils = api.useUtils()

return (
<Button onClick={() => {
// doesn't work
utils.list.services.refetch({query: query});

// this does work
const key = getQueryKey(api.list.services, {query: query});
queryClient.refetchQueries(key)
}}>test</Button>
)
const queryClient = useQueryClient();
const services = api.list.services({query: query});
const utils = api.useUtils()

return (
<Button onClick={() => {
// doesn't work
utils.list.services.refetch({query: query});

// this does work
const key = getQueryKey(api.list.services, {query: query});
queryClient.refetchQueries(key)
}}>test</Button>
)
Am I doing something wrong?
8 replies
TtRPC
Created by RealityShift on 11/16/2023 in #❓-help
Retry even when disabled
No description
5 replies
TtRPC
Created by RealityShift on 11/10/2023 in #❓-help
Zod transform types
No description
3 replies
TtRPC
Created by RealityShift on 10/25/2023 in #❓-help
Generic Zod as Input Type
I'm not positive if this is a TRPC question, typescript in general, or failure to understand Zod in this usecase. Our API has a several endpoints that all work the same way just pass in different payloads. I'm trying to create a single function to assign to all my TRPC routes:
enum Endpoint {
"Person" = "/users/person",
"Company" = "/core/company",
}

update: createTRPCRouter({
person: updateGeneric(ZPersonUpdate, Endpoint.Person),
company: updateGeneric(ZCompanyUpdate, Endpoint.Company),
})

function createUpdateApiProcedure<T extends z.SomeZodObject>(schema: T, path: Endpoint) {
return protectedProcedure.input(
z.object({id: z.number()}).extend(schema)
).mutation(async ({ ctx, input }) => {
//call api with payload
})
}
enum Endpoint {
"Person" = "/users/person",
"Company" = "/core/company",
}

update: createTRPCRouter({
person: updateGeneric(ZPersonUpdate, Endpoint.Person),
company: updateGeneric(ZCompanyUpdate, Endpoint.Company),
})

function createUpdateApiProcedure<T extends z.SomeZodObject>(schema: T, path: Endpoint) {
return protectedProcedure.input(
z.object({id: z.number()}).extend(schema)
).mutation(async ({ ctx, input }) => {
//call api with payload
})
}
I'm not sure what should be in the input section to make this work?
6 replies