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

Self relation graphql module generation problem #149

Closed alaarihan closed 3 years ago

alaarihan commented 3 years ago

Hi,

While I'm creating a self relations in a module, pal g made a wrong import from the module to its self, this confusion happened because the module has relations to its self:

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
}

The generated code was like this:

import { GraphQLModule } from '@graphql-modules/core'
import typeDefs from './typeDefs'
import resolvers from './resolvers'
import { addSelect } from '../common/addSelect'
import { CommonModule } from '../common/common.module'
import { CategoryModule } from '../Category/Category.module'

export const CategoryModule = new GraphQLModule({
  name: 'Category',
  typeDefs,
  resolvers,
  imports: [CommonModule, CategoryModule],
  resolversComposition: {
    Query: [addSelect],
    Mutation: [addSelect],
  },
})

as you see the module name is CategoryModule and it contain an import to CategoryModule in the same time

AhmedElywa commented 3 years ago

Thanks for the report will work on it

AhmedElywa commented 3 years ago

If you have time and want to try solving it you can take a look here https://github.com/paljs/prisma-tools/blob/7f3541095a50c2447051dbcca9ed7b43d7715fbc/packages/generator/src/graphql-modules/index.ts#L50

alaarihan commented 3 years ago

Yeah sure, I just want to know how can I test the changes that I will make?

AhmedElywa commented 3 years ago

You can make any folder in https://github.com/paljs/prisma-tools/tree/master/packages/generator/__tests__ path and take nexus-prisma as an example.

to run the generator just do node index.js command inside your folder