Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prisma nexus crud not generating schema correctly #1123

Open
facinick opened this issue Nov 19, 2021 · 0 comments
Open

Prisma nexus crud not generating schema correctly #1123

facinick opened this issue Nov 19, 2021 · 0 comments

Comments

@facinick
Copy link

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant