paljs / prisma-tools

Prisma tools to help you generate CRUD system for GraphQL servers
https://paljs.com
MIT License
683 stars 54 forks source link

Fix generating graphql-module self relation typeDefs #151

Closed alaarihan closed 3 years ago

alaarihan commented 3 years ago

I've found a problem after the last fix, self relation typeDefs don't get generated, this PR fix that

AhmedElywa commented 3 years ago

Did you test it?

alaarihan commented 3 years ago

Yes, I did, without this change the generator will produce this typeDef for this model

model Category {
  id        Int        @id @default(autoincrement())
  name      String
  parentId  Int?
  parent    Category?  @relation("CategoryTree", fields: [parentId], references: [id])
  children  Category[] @relation("CategoryTree")
  createdAt DateTime   @default(now())
  updatedAt DateTime   @updatedAt
}
export default gql`
  type Category {
    id: Int!
    name: String!
    parentId: Int
    parent: Category
    createdAt: DateTime!
    updatedAt: DateTime!
  }
...

After this change the generator will produce this..

export default gql`
  type Category {
    id: Int!
    name: String!
    parentId: Int
    parent: Category
    children(
      where: CategoryWhereInput
      orderBy: CategoryOrderByInput
      cursor: CategoryWhereUniqueInput
      take: Int
      skip: Int
      distinct: CategoryDistinctFieldEnum
    ): [Category!]!
    createdAt: DateTime!
    updatedAt: DateTime!
  }
...