这个问题可能是由于 Prisma 的数据模型中出现了一对多的关系,导致在使用 Apollo GraphQL 创建一个 mutation 时出现错误。
以下是解决方法的步骤:
model User {
id Int @id @default(autoincrement())
name String
posts Post[]
}
model Post {
id Int @id @default(autoincrement())
title String
content String
author User @relation(fields: [authorId], references: [id])
authorId Int
}
model User {
id Int @id @default(autoincrement())
name String
post Post[]
}
model Post {
id Int @id @default(autoincrement())
title String
content String?
author User? @relation(fields: [authorId], references: [id])
authorId Int?
}
type Mutation {
addUser(data: UserCreateInput!): User
addPost(data: PostCreateInput!): Post
}
input PostCreateInput {
title String!
content String
authorId Int!
}
type User {
id Int
name String
post [Post!]!
}
type Post {
id Int
title String
content String
author User
}
const ADD_POST = gql`
mutation AddPost