Skip to content

Instantly share code, notes, and snippets.

@bonface221
Last active August 9, 2024 11:30
Show Gist options
  • Save bonface221/d7b43a50fd3d00629a32e6bb84324503 to your computer and use it in GitHub Desktop.
Save bonface221/d7b43a50fd3d00629a32e6bb84324503 to your computer and use it in GitHub Desktop.
Prisma relationship type generator

Since Prisma queries do not include relations by default (you have to use the include option), the generated types do not include them either. You can create the type you are looking for using one of our built-in utility types, though.

import { Prisma } from '@prisma/client'
type FactionWithOwner = Prisma.FactionGetPayload<{
  include: { owner: true }
}>

Here we use the FactionGetPayload type and pass in some query options as the generic parameter to get the desired type.

Let me know if you have any questions about this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment