-
Notifications
You must be signed in to change notification settings - Fork 121
Open
Description
I am using prisma and nexus with the following prisma schema:
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
}
and I have created nexus models and mutation as such:
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();
},
})
I should be able to run a graphql mutation to create a single post with only userId
, title
and description
. However the types nexus is generating makes it as such that author
field is mandatory in the query.
following is generated by nexus:
type Mutation {
createOnePost(data: PostCreateInput!): Post!
}
input PostCreateInput {
author: UserCreateNestedOneWithoutPostsInput!
createdAt: DateTime
description: String!
id: String
title: String!
updatedAt: DateTime
}
note 1: I have noticed the following type generated by nexus but it's not being used anywhere:
input PostCreateWithoutAuthorInput {
createdAt: DateTime
description: String!
id: String
title: String!
updatedAt: DateTime
}
note 2: I've only added relevant code from my source
Could someone please help me figure out what can I do here?
libraries used:
-
"nexus-plugin-prisma": "^0.35.0"
-
"prisma": "^2.23.0"
-
"@prisma/client": "^2.23.0"
-
"nexus": "^1.0.0"
Metadata
Metadata
Assignees
Labels
No labels