Ability to let the client select the fields it wants from the returned data. Half done, need help to fix the types for the returned data, type for select works already #5487
Unanswered
jgb-solutions
asked this question in
Q&A
Replies: 1 comment 1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'll go straight to the point. I added a select field that allows to field and nested fields based on the return data for a query. Now I also have a function that does the picking, but the returned type is not good. Partially it gets the nested fields right, but not the base object.
Here's the type for the
select
param:That way it works just like Prisma select where you provide true for the keys you want. That works on the client side for type and functionality. Here's a sample of the client code:
Like I said intellisense works. Here's how I use it on the schema:
It's used a custom type and it's optional.
Here's what my query in TRPC looks like:
That's when things start to stop working with the types, typeof select is not compatible with the argument of the following function, defined like this:
Functionality wise I got my select fields working like GraphQL, great! But the type breaks. I'm not a TypeScript guru yet to figure out what didn't work out. I adapted the types with the help of ChatGPT but it can't figure everything out. I'm looking to have end to end type safety just like I would using Prisma select, but using TRPC instead. I saw a similar issue where people said there was a limitation of typescript. But I know this time that it's possible. I'm also there. Just need to fix the type and have nice DX everywhere. And how knows may TRPC could improve that idea and incorporate it in future versions. Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions