Skip to content

Commit

Permalink
fix(client): include types
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Apr 22, 2020
1 parent 940e6f4 commit 398ef65
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/packages/client/.packwatch.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "limit": "447.9 kB", "packageSize": "447.9 kB", "unpackedSize": "1.6 MB" }
{"limit":"448.1 kB","packageSize":"448.1 kB","unpackedSize":"1.6 MB"}
20 changes: 12 additions & 8 deletions src/packages/client/fixtures/blog/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ generator client {
}

model User {
id String @default(cuid()) @id
email String @unique
name String?
posts Post[]
treeHouseMaterial Tree?
id String @default(cuid()) @id
email String @unique
name String?
posts Post[]
}

model Post {
Expand All @@ -27,7 +26,12 @@ model Post {
author User? @relation(fields: [authorId], references: [id])
}

enum Tree {
OAK
DOUGLAS
model Like {
id String @default(cuid()) @id
userId String
user User @relation(fields: [userId], references: [id])
postId String
post Post @relation(fields: [postId], references: [id])
@@unique([userId, postId])
}
29 changes: 29 additions & 0 deletions src/packages/client/src/__tests__/types/blog/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,35 @@ async function main() {
})

const id = users[0].posts[0].author?.id

const like = await prisma.like.findOne({
where: {
userId_postId: {
postId: '',
userId: '',
},
},
include: { post: true },
})

like!.post

const like2 = await prisma.like.upsert({
where: {
userId_postId: {
userId: '',
postId: '',
},
},
create: {
post: { connect: { id: '' } },
user: { connect: { id: '' } },
},
update: {},
include: { post: true },
})

like2!.post
}

main().catch((e) => {
Expand Down
10 changes: 10 additions & 0 deletions src/packages/client/src/__tests__/types/blog/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,14 @@ model MachineData {
procFreq Float
procCores Int
ram Int
}

model Like {
id String @default(cuid()) @id
userId String
user User @relation(fields: [userId], references: [id])
postId String
post Post @relation(fields: [postId], references: [id])
@@unique([userId, postId])
}
2 changes: 1 addition & 1 deletion src/packages/client/src/generation/TSClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ export type ${getPayloadName(name)}<
? ${name}
: S extends undefined
? never
: S extends ${getModelArgName(name, DMMF.ModelAction.findMany)}
: S extends ${argsName} | ${getModelArgName(name, DMMF.ModelAction.findMany)}
? 'include' extends U
? ${name} ${include.length > 0 ? ` & ${include}` : ''}
: 'select' extends U
Expand Down

0 comments on commit 398ef65

Please sign in to comment.