typegraphql-prisma icon indicating copy to clipboard operation
typegraphql-prisma copied to clipboard

typescript compile throws errors for prisma version over 5.13.0

Open andreicon opened this issue 1 year ago • 10 comments

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):

  • OS: Ubuntu 24.04
  • Node v20.12.2
  • typegraphql-prisma 0.27.2
  • Prisma 5.14.0
  • TypeScript 5.4.5

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

andreicon avatar May 15 '24 10:05 andreicon

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

jessekrubin avatar May 15 '24 15:05 jessekrubin

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

felippi avatar May 29 '24 04:05 felippi

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

andreicon avatar Jun 03 '24 11:06 andreicon

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

felippi avatar Jun 03 '24 20:06 felippi

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

jessekrubin avatar Jun 03 '24 21:06 jessekrubin

@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

felippi avatar Jun 03 '24 22:06 felippi

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

All the best! Regards, Jesse

jessekrubin avatar Jun 03 '24 22:06 jessekrubin

Hello @MichalLytek,

Do you have any updates on this issue?

Thanks.

eduardolundgren avatar Jun 07 '24 20:06 eduardolundgren

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"
	}

savager avatar Jun 12 '24 18:06 savager

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

DanLeCornu avatar Jun 19 '24 12:06 DanLeCornu

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!

stevefan1999-personal avatar Jul 30 '24 16:07 stevefan1999-personal

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

MichalLytek avatar Aug 07 '24 14:08 MichalLytek

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

@MichalLytek Thank you!

eduardolundgren avatar Aug 07 '24 15:08 eduardolundgren