【发布时间】:2021-12-29 14:14:12
【问题描述】:
我正在使用具有以下 prisma 架构的 prisma 和 nexus:
model User {
id String @id @default(uuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
username String @unique
posts Post[]
}
model Post {
id String @id @default(uuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
title String
description String
author User @relation(fields: [userId], references: [id])
userId String
}
我已经创建了这样的关系模型和突变:
export const Post = objectType({
name: 'Post',
definition(t) {
t.model.id();
t.model.title();
t.model.description();
t.model.userId();
t.model.author();
t.model.updatedAt();
t.model.createdAt();
},
});
export const PostMutations = extendType({
type: 'Mutation',
definition(t) {
t.crud.createOnePost();
},
})
我应该能够运行 graphql 突变来创建一个只有 userId、title 和 description 的帖子。但是,nexus 生成的类型使得 author 字段在查询中是必需的。
以下是由nexus生成的:
type Mutation {
createOnePost(data: PostCreateInput!): Post!
}
input PostCreateInput {
author: UserCreateNestedOneWithoutPostsInput!
createdAt: DateTime
description: String!
id: String
title: String!
updatedAt: DateTime
}
注意 1:我注意到 nexus 生成了以下类型,但它没有在任何地方使用:
input PostCreateWithoutAuthorInput {
createdAt: DateTime
description: String!
id: String
title: String!
updatedAt: DateTime
}
注意 2:我只添加了来自我的来源的相关代码
有人可以帮我弄清楚我可以在这里做什么吗?
使用的库:
-
"nexus-plugin-prisma": "^0.35.0"
-
“棱镜”:“^2.23.0”
-
"@prisma/client": "^2.23.0"
-
“关系”:“^1.0.0”
【问题讨论】:
标签: nexus prisma prisma-graphql prisma2 nexus-prisma