Checking Joined Data Directly from Type Recommendation and Retrieved Data in Dynamic findMany
When implementing a join using with in findMany, I wrote the following code to dynamically change the object to be set in with.
my code
I wrote this code because I wanted to allow users of the API to choose which objects to join.
Is there a way to check the joined data directly from the type recommendation and the retrieved data?
Or is this approach itself wrong?
3 Replies
This approach would work if you wrap the db call in a generic function
Check out this example https://discord.com/channels/1043890932593987624/1176396088895356959/1176537371764867155
Thanks so much Angelelz, I'll check that out quickly.
Thanks, I can define the with type in advance.
However, since the items in the with are determined dynamically, I have no way of knowing what types are in the result.
I'm happy with this though.
schema.ts
handler.ts
Yes, there is. In the typescript playground, the function
getEmployeeById
accepts a withInput
argument, which is dynamic. You can check that if you change it, the resulting type will change
I you add photos: true, you can see how the type of user changes