paljs / prisma-tools

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

sdlInput generation looks incorrect #197

Open pakatagoh opened 3 years ago

pakatagoh commented 3 years ago

@AhmedElywa

I have the following schema

model LeaveOfAbsence {
  createdAt     DateTime @default(now())
  updatedAt     DateTime @updatedAt
  id            String   @id @default(cuid())
  startDateTime DateTime
  endDateTime   DateTime
  reason        String?
  cleaner       Cleaner  @relation(fields: [cleanerId], references: [id])
  cleanerId     String
}

model Cleaner {
  createdAt         DateTime         @default(now())
  updatedAt         DateTime         @updatedAt
  id                String           @id @default(cuid())
  leaveOfAbsence    LeaveOfAbsence[]
  agency            Agency           @relation(fields: [agencyId], references: [id])
  agencyId          String
}

model Agency {
  createdAt           DateTime      @default(now())
  updatedAt           DateTime      @updatedAt
  id                  String        @id @default(cuid())
  name                String        @unique
  cleaners            Cleaner[]
}

With prisma, I'm able to create a LeaveOfAbsence with nested creations of Cleaner and Agency

image

However, the sdlInput types generated do not take into account nested creations. Below is the sdl generated with the help of generateGraphQlSDLFile from @paljs/plugins

createOneLeaveOfAbsence(data: LeaveOfAbsenceCreateInput!): LeaveOfAbsence!

input LeaveOfAbsenceCreateInput {
  createdAt: DateTime
  updatedAt: DateTime
  id: String
  startDateTime: DateTime!
  endDateTime: DateTime!
  reason: String
  cleaner: CleanerCreateNestedOneWithoutLeaveOfAbsenceInput!
}

input CleanerCreateNestedOneWithoutLeaveOfAbsenceInput {
  create: CleanerUncheckedCreateWithoutLeaveOfAbsenceInput
  connectOrCreate: CleanerCreateOrConnectWithoutLeaveOfAbsenceInput
  connect: CleanerWhereUniqueInput
}

input CleanerUncheckedCreateWithoutLeaveOfAbsenceInput {
  createdAt: DateTime
  updatedAt: DateTime
  id: String
  # other types here 
  agencyId: String!
  # more types here 
}

As a result, apollo hooks generated by codegen do not follow the same types as prisma

image

I am not able to perform nested/transactional creations. Was pretty sure this wasn't an issue in the past. Maybe it's an issue with prisma's latest updates that are causing this issue

Hope the explanation is clear enough and hope to get some feedback asap!

My setup: "@paljs/plugins": "2.13.0", "@paljs/cli": "2.13.1", "@prisma/client": "2.20.1", "prisma": "^2.20.1",

AhmedElywa commented 3 years ago

Maybe it's an update from Prisma DMMF in the last version. I will check that and back to you

pakatagoh commented 3 years ago

@AhmedElywa any updates on this?

AhmedElywa commented 3 years ago

Not yet was working on a big change in Prisma admin and ClI to support multiple Prisma schema in the sand project

pakatagoh commented 3 years ago

okay noted! but just wondering if you have any indication on when you think you might finish working on this fix?