Hi. I know about <prisma validator>, but i don’t ...
# orm-help
y
Hi. I know about prisma validator, but i don’t know how to use prisma validator to implement the functionality i want. Below is the approximate code of the function i want.
getUser
must return a value containing only information about the select object received as an argument. and it must be type safe !
👀 1
a
Hey there! Could you use
Prisma.UserSelect
to type the parameter to the
getUser
function? If not, could you explain your use case a little more?
v
👋 hey @YeonHoPark! Did you have a chance to see Austin's comment? Let us know if you still need help with this!
y
Hi !! Could you use
Prisma.UserSelect
to type the parameter to the
getUser
function?
that’s one of the things i want. I add a bit more to the code above to explain what i want… The getUser function receive the various prisma
include
and
select
object received as arguments, retrieve them, and return the object in a type safe way. As the getUser function receives as an arguments, the prisma is searched, and the type is specified. e.g.. 1. I want the user and his posts.
Copy code
const userWithPosts = await getUser({ include: { posts:true }})

// userWithPosts type
const userWithPosts: (User & {
    posts: Post[];
})
2. I want the user and hi profile.
Copy code
const userWithProfile = await getUser({ include: { profile:true } })

// userWithProfile type
const userWithProfile: (User & {
    profile: Profile;
})
3. I want the user and his id.
Copy code
const userWithIdSelect = await getUser({ select: { id:true } }) 

// userWithIdSelect type
const userWithPosts: {
    id: string;
}
4. many other case…
v
@Austin can you please check this out?
a
Have you tried:
Copy code
const getUser = async (select: Prisma.UserSelect) => {...}