TRPC Prisma using connect properly
Hi guys just created a new app with createt3, I think some things changed since the last time I used prisma and trpc, so I have following basic schema setup:
And I am trying to create a router to run a mutation to create a movie with an answer like this:
But I get this warning
at
model Movie {
id String @id @default(cuid())
text String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
answer Answer? @relation(fields: [answerId], references: [id])
answerId String?
}
model Answer {
id String @id @default(cuid())
text String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Movie Movie[]
}
model Movie {
id String @id @default(cuid())
text String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
answer Answer? @relation(fields: [answerId], references: [id])
answerId String?
}
model Answer {
id String @id @default(cuid())
text String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Movie Movie[]
}
export const movieRouter = router({
getAll: publicProcedure.query(({ ctx }) => {
return ctx.prisma.movie.findMany();
}),
create: publicProcedure.input(z.object({
text: z.string(),
answer: z.string(),
})).mutation(({ ctx, input }) => {
const answer = ctx.prisma.answer.create({
data: {
text: input.text,
}
});
return ctx.prisma.movie.create({
data: {
text: input.text,
answer: {
connect: {
id: answer.id,
}
},
// Connect the new Movie to the existing Answer using the 'movies' relation field
movies: {
connect: {
id: answer.id,
}
}
}
});
}),
});
export const movieRouter = router({
getAll: publicProcedure.query(({ ctx }) => {
return ctx.prisma.movie.findMany();
}),
create: publicProcedure.input(z.object({
text: z.string(),
answer: z.string(),
})).mutation(({ ctx, input }) => {
const answer = ctx.prisma.answer.create({
data: {
text: input.text,
}
});
return ctx.prisma.movie.create({
data: {
text: input.text,
answer: {
connect: {
id: answer.id,
}
},
// Connect the new Movie to the existing Answer using the 'movies' relation field
movies: {
connect: {
id: answer.id,
}
}
}
});
}),
});
Property 'id' does not exist on type 'Prisma__AnswerClient<Answer, never>'.ts(2339)
Property 'id' does not exist on type 'Prisma__AnswerClient<Answer, never>'.ts(2339)
id: answer.id,
And this warning
Type '{ text: string; answer: { connect: { id: any; }; }; movies: { connect: { id: any; }; }; }' is not assignable to type '(Without<MovieCreateInput, MovieUncheckedCreateInput> & MovieUncheckedCreateInput) | (Without<...> & MovieCreateInput)'.
Type '{ text: string; answer: { connect: { id: any; }; }; movies: { connect: { id: any; }; }; }' is not assignable to type '(Without<MovieCreateInput, MovieUncheckedCreateInput> & MovieUncheckedCreateInput) | (Without<...> & MovieCreateInput)'.
0 Replies