I'm getting this error while using Prisma Client 5.0.0:
Type '{ number: number; type: "User" | "Message"; guildId: string; threadId: string; messageId: string | undefined; channelId: string | undefined; author: { connectOrCreate: { where: { userId: string; }; create: { ...; }; }; }; target: { ...; }; trackedContent: { ...; }; }' is not assignable to type '(Without<ReportCreateInput, ReportUncheckedCreateInput> & ReportUncheckedCreateInput) | (Without<...> & ReportCreateInput)'.
Types of property 'author' are incompatible.
Type '{ connectOrCreate: { where: { userId: string; }; create: { userId: string; guildId: string; }; }; }' is not assignable to type 'undefined'.ts(2322)
Code:
await prisma.report.create({
data: {
number,
type: message ? "Message" : "User",
guildId,
threadId: forumPost.id,
messageId: message?.id,
channelId: message?.channel.id,
trackedContent: { createMany: { data: trackedContent } },
author: {
connectOrCreate: { where: { userId: author.id }, create: { userId: author.id, guildId } },
},
target: {
connectOrCreate: { where: { userId: target.id }, create: { userId: target.id, guildId } },
},
},
});
Schema:
model GuildMember {
userId String @id @map("user_id")
guild Guild @relation(fields: [guildId], references: [guildId])
guildId String
// Reports are the reports that the user has made
reports Report[] @relation("reports")
// History is the reports that the user has been reported for
history Report[] @relation("history")
createdTrackedContent TrackedContent[]
@@map("guild_member")
}
model Report {
id String @id @default(cuid()) @map("report_id")
createdAt DateTime @default(now()) @map("created_at")
number Int
guild Guild @relation(fields: [guildId], references: [guildId])
guildId String @map("guild_id")
threadId String @map("thread_id")
type ReportType
author GuildMember @relation(name: "reports", fields: [authorId], references: [userId])
authorId String @map("author_id")
target GuildMember @relation(name: "history", fields: [targetId], references: [userId])
targetId String @map("target_id")
messageId String? @map("message_id")
channelId String? @map("channel_id")
fieldValues String[] @map("field_values")
trackedContent TrackedContent[]
@@unique([number, guildId])
@@map("report")
}
It works when I use authorId: ... + targetId: ... and having another function for upserting the GuildMembers. However, I would like to do this in one function call and am wondering why this error is happening, especially with the error mentioning undefined.