MichalLytek / typegraphql-prisma

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

typescript compile throws errors for prisma version over 5.13.0 #450

Closed andreicon closed 2 months ago

andreicon commented 4 months ago

Describe the Bug When compiling project dist with typescript compile, it will throw errors similar to errors

To Reproduce Install latest dependencies and generate client and typescript-graphql schema. Run tsc.

Expected Behavior tsc compiles successfully

Environment (please complete the following information):

Additional Context using @prisma/generator-helper and @prisma/internals versions 5.13.0 works

jessekrubin commented 4 months ago

Encountering this as well. createManyAndReturn is new to prisma (https://github.com/prisma/prisma/releases/tag/5.14.0)

Also the new omit could be causing problems (but I do not know).

@andreicon I looked at your PR. locking the generator version(s) seems icky. The problem is that createMany is 1) relatively new to sqlite and 2) now returns the updated data

felippi commented 4 months ago

Just add override on your package.json until the corretion of typegraphql


"overrides": {
    "typegraphql-prisma": {
      "@prisma/generator-helper": "<=5.13.0",
      "@prisma/internals": "<=5.13.0"
    }
  }

edit: Use npm list @prisma and npm list @prisma/internals to show all dependencies of @prisma, ensure that none of them use @prisma greater than 5.13 Obviously, after that, execute npm install

andreicon commented 4 months ago

i'm not sure why @felippi is being downvoted, i did exactly that

felippi commented 4 months ago

i'm not sure why @felippi is being downvoted, i did exactly that

Use npm list @prisma and npm list @prisma/internals to show all dependencies of @prisma, ensure that none of them use @prisma greater than 5.13 Obviously, after that, execute npm install*

jessekrubin commented 4 months ago

@andreicon bc it feels dirty and is not an actual fix as well as it is a fix that must be undone.

felippi commented 4 months ago

@andreicon bc it feels dirty and is not an actual fix as well as it is a fix that must be undone.

I only suggested an alternative that worked for me until the definitive alternative comes, now if these people can afford to have their applications not working until a definitive solution comes, then don't use that and leave your application not working until one appears a clean solution

jessekrubin commented 4 months ago

@felippi a thumbs down is not a personal attack (AFAIK). I support what you're saying!

All the best! Regards, Jesse

eduardolundgren commented 4 months ago

Hello @MichalLytek,

Do you have any updates on this issue?

Thanks.

savager commented 3 months ago

For any Yarn users out there. I chose 5.4.2 because that was the version I previously ran, but obviously any version before 5.14

"resolutions": {
        "typegraphql-prisma/@prisma/generator-helper": "5.4.2",
        "typegraphql-prisma/@prisma/internals": "5.4.2",
        "typegraphql-prisma/@prisma/engines": "5.4.2"
    }
DanLeCornu commented 3 months ago

For any pnpm-ers out there, the syntax is a little different than npm (as provided in @felippi's answer):

in root package.json

  "pnpm": {
    "overrides": {
      "typegraphql-prisma>@prisma/generator-helper": "<=5.13.0",
      "typegraphql-prisma>@prisma/internals": "<=5.13.0"
    }
  },

from the pnpm docs

stevefan1999-personal commented 2 months ago

Given this schema:

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

generator typegraphql {
  provider               = "typegraphql-prisma"
  output                 = "../prisma/generated/type-graphql"
  emitRedundantTypesInfo = true
}

datasource db {
  provider = "sqlite"
  url      = env("DATABASE_URL")
}

model User {
  id       Int     @id @default(autoincrement())
  email    String  @unique
  name     String?
  posts    Post[]
  password String?
}

model Post {
  id        Int     @id @default(autoincrement())
  title     String
  content   String?
  published Boolean @default(false)
  author    User    @relation(fields: [authorId], references: [id])
  authorId  Int
}

The problem is here: https://github.com/MichalLytek/typegraphql-prisma/blob/be2477654a654f70d87922fd47a2f53ba1b9828f/src/generator/type-class.ts#L48-L54

This does not take in account when the target output type is part of the Model.

  {
    name: 'author',
    args: [],
    isNullable: false,
    outputType: {
      type: 'User',
      namespace: 'model',
      location: 'outputObjectTypes',
      isList: false
    },
    isRequired: true,
    fieldTSType: 'User',
    typeGraphQLType: 'User',
    argsTypeName: undefined
  }

Here is what it usually expects:

  {
    name: '_max',
    args: [],
    isNullable: true,
    outputType: {
      type: 'PostMaxAggregate',
      namespace: 'prisma',
      location: 'outputObjectTypes',
      isList: false
    },
    isRequired: false,
    fieldTSType: 'PostMaxAggregate | null',
    typeGraphQLType: 'PostMaxAggregate',
    argsTypeName: undefined
  }

Edit 2: Bingo! https://github.com/MichalLytek/typegraphql-prisma/blob/be2477654a654f70d87922fd47a2f53ba1b9828f/src/generator/dmmf/types.ts#L50

We forgot to handle for the model case!

MichalLytek commented 2 months ago

It should be fixed in v0.28.0 as the code was adjusted to work with Prisma 5.18 🔒

eduardolundgren commented 2 months ago

It should be fixed in v0.28.0 as the code was adjusted to work with Prisma 5.18 🔒

@MichalLytek Thank you!