Cauen / prisma-generator-pothos-codegen

The fastest way to create a fully customizable CRUD Graphql API from Prisma Schema.
https://www.npmjs.com/package/prisma-generator-pothos-codegen
100 stars 19 forks source link

Complicated schema leads to invalid inputs.ts #2

Closed elektrica closed 2 years ago

elektrica commented 2 years ago

For some reason, the schema below results in a generated inputs.ts file that does not type check. I tried to simplify it down to the smallest possible case, but there seems to be something about this schema in particular that causes it to fail. If I remove any part of it then it goes back to working correctly.

model A {
  id String @id
  b  B[]
}

model B {
  id  String @id
  a   A      @relation(fields: [aId], references: [id])
  aId String
  int Int
  c   C[]
  d   D[]
  f   F[]
}

model C {
  id  String @id
  b   B      @relation(fields: [bId], references: [id])
  bId String
  int Int
  f   F[]
}

model D {
  id  String @id
  b   B      @relation(fields: [bId], references: [id])
  bId String
  f   F[]
}

model E {
  id String @id
  f  F[]
}

model F {
  id  String @id
  e   E      @relation(fields: [eId], references: [id])
  eId String
  b   B      @relation(fields: [bId], references: [id])
  bId String
  c   C[]
  d   D[]
}
Cauen commented 2 years ago

Hi @elektrica I tested it with a giant project a few days ago and I realized that: inside the inputs file, the typescript starts to suffer from some complexities But when the type is imported for use within resolvers, the type safety works correctly. Was it like that in your case?

I believe there is a problem with recursive type inference with Pothos. And I believe that in this regard, this library can't do much :/

elektrica commented 2 years ago

That's true, the issues seems to be isolated to the inputs file, which is good. Really appreciate you looking at it. You may be right that this is likely just a very strange Pothos problem.