问题描述
当 createComment
突变被执行时,一个名为 Invalid 'prisma.comment.create()' invocation:
的错误
我现在不知道这有什么问题。?
我使用 OSX 和 postgresql
schema.prisma
model User {
userId Int @id @default(autoincrement())
fullName String
username String @unique
avatar String?
email String @unique
password String
phoneNumber String @unique
location String?
searchHistoryOnOff Boolean @default(true)
notificationOnOff Boolean @default(true)
notifications Notification[]
searchHistories SearchHistory[]
products Product[]
comments Comment[]
createdAt DateTime @default(Now())
updatedAt DateTime @updatedAt
}
model Product {
id Int @id @default(autoincrement())
authorId Int
title String
price Int
picture String[]
content String?
hits Int @default(0)
author User @relation(fields: [authorId],references: [userId])
hashtags Hashtag[]
comments Comment[]
createdAt DateTime @default(Now())
updated
}
model Comment {
id Int @id @default(autoincrement())
authorId Int
productId Int
comment String
author User @relation(fields: [authorId],references: [userId])
product Product @relation(fields: [productId],references: [id])
createdAt DateTime @default(Now())
updatedAt DateTime @updatedAt
}
typeDefs
import { gql } from 'apollo-server-express';
export default gql`
type Mutation {
createComment(productId: Int!,commment: String!): MutationResponse!
}
`;
解析器
import { Comment } from '@prisma/client';
import { protectedResolver } from '../../users/user.utils';
import { Identity,Resolvers } from './../../types.d';
const resolvers: Resolvers = {
Mutation: {
createComment: protectedResolver(
async (_,{ productId,comment },{ loggedInUser,client }) => {
const { userId } = loggedInUser;
const product: Identity = await client.product.findUnique({
where: { id: productId },select: { id: true },});
if (!product) {
return {
ok: false,error: '게시글이 존재하지 않음',};
}
const newComment: Comment = await client.comment.create({
data: {
comment,author: {
connect: { userId },},product: {
connect: { id: productId },});
return { ok: true };
}
),};
export default resolvers;
请帮帮我??
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)