T
tRPC

Query tRPC the right way

Query tRPC the right way

Iippo6/4/2023
If you use graphql, you can precisely query what you exactly need and avoid over fetching, so you can do something like this:
user {
id
username
avatar
}

user {
id
username
avatar
email
updatedAt
}
user {
id
username
avatar
}

user {
id
username
avatar
email
updatedAt
}
how would you do that in tRPC? do you have to implement an interface like this?
getUser({
select: ["id", "avatar", "username"],
orderBy: "ASC"
})
getUser({
select: ["id", "avatar", "username"],
orderBy: "ASC"
})
and what is if you want to query related stuff, like the user and its pets and from the pets you just want the ids but in other cases the names and ids
Nnlucas6/5/2023
Trpc doesn’t offer anything like this directly, but as you’ve proposed it’s possible to do with plain typescript. The problem of over fetching fields is generally not a problem for most apps though
Iippo6/5/2023
@Nick Lucas so is my idea okay and common in tRPC?
Nnlucas6/5/2023
Not really common, no, though I have thought it could be an interesting gap for a library to fill You'll run into issues with varying output types based on input types. TS functions can do that, but tRPC can't since the input/output are isolated from each other

Looking for more? Join the community!

T
tRPC

Query tRPC the right way

Join Server
Recommended Posts
How does trpc subscription actively close/disconnect in the server?How do I actively disconnect my subscription?child router questionlet's say we have a monorepo, one server, two client apps (cat and dog). we make one appRouter, likHow to force SSL on projects using tRPC?Hello everyone, I'm working on a project that uses create-t3-app as boilerplate. My project is hosAWS Lambda / How to set Cookies inside ProceduresHow can I set and remove cookies similar to ctx.res.cookie(..) with Express when using the aws lambdMassive Type Errors on tRPC 10 Legacy Router against MergeRouterWe're trying to upgrade to tRPC 10 but I am running into a massive type clash when trying to merge rIs it possible to create 2 routers inside a single file?I am having an issue in which it is impossible to me to use a class instance within 2 routers. I triUse onError to change an application error into a TRPCError?I want to use the onError handler to change any instance of a custom application error into a TRPCErIncreasing Body 1mb limitHey, Im trying to build an application that allows sending of base64 encoded files to my next.js serNitro and tRPC in vercel-edgeHey there! I hope this is the right place to ask for help. I am trying to deploy an application witHow to retrieve and receive Bigint data to/from TRPC procedureNode: `v16.15.1` I'm trying to return an object which contains an `amount` property from one of my React Router Loaders + tRPC?In Vite project: would it make sense to use React Router loaders with tRPC? I like more the concept TypeError: Cannot read properties of null (reading 'useContext') when using useMutation with TRPC inI'm encountering an error in my Next.js application when trying to use the useMutation hook with TRP