MichalLytek / typegraphql-prisma

Prisma generator to emit TypeGraphQL types and CRUD resolvers from your Prisma schema
https://prisma.typegraphql.com
MIT License
891 stars 113 forks source link

Slow prisma generate #395

Closed baptistemanson closed 1 year ago

baptistemanson commented 1 year ago

Describe the Bug With one model, I get ✔ Generated Prisma Client (4.15.0 | library) to .\node_modules\@prisma\client in 53ms ✔ Generated TypeGraphQL integration to .\node_modules\@generated\type-graphql in 69.38s

When testing with a larger schema (19 models) it takes 90-100s.

To Reproduce

generator client {
  provider = "prisma-client-js"
}

generator typegraphql {
  provider = "typegraphql-prisma"
}

datasource db {
  provider = "postgresql"
  url      = env("POSTGRES_MODEL_STRING")
}

model App {
  id String @id @default(uuid())
}

Expected Behavior We would expect to be just a few seconds.

Environment (please complete the following information):

We were also able to reproduce this issue with a macOS M1 environment.

{
  "extends": "ts-node/node16/tsconfig.json",
  "compilerOptions": {
    "target": "es2018",
    "lib": [
      "es2018",
      "esnext.asynciterable"
    ],
    "module": "commonjs",
    "outDir": "./dist",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true
  }
}

Have a great day! Tell me how I can help beyond funding (because broke for now)

baptistemanson commented 1 year ago

Some progress; a custom folder outside out of the node_modules brings the performance to some acceptable performance. ✔ Generated TypeGraphQL integration to .\src\server\middlewares\graphql in 574ms for the large model ✔ Generated TypeGraphQL integration to .\src\server\middlewares\graphql in 6.15s

MichalLytek commented 1 year ago

On my machine with such schema: https://github.com/MichalLytek/typegraphql-prisma/blob/main/experiments/postgres/prisma/schema.prisma

✔ Generated Prisma Client (4.15.0 | library) to ./prisma/generated/client in 83ms

✔ Generated TypeGraphQL integration to ./prisma/generated/type-graphql in 2.43s
MichalLytek commented 1 year ago

https://github.com/MichalLytek/typegraphql-prisma/blob/main/experiments/postgres/prisma/schema.prisma

As stated in the docs, emitting to node_modules does transpilation of the generated TS code on the fly, that's why it's so slow.

baptistemanson commented 1 year ago

Im glad we got a chance to find the solution and document it for future users. As I use tsx now, I forgot transpilation with ts-node was so slow! Thanks for trying to run it too Michal, I appreciate.

I will close the bug.