Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throws "TypeError: Cannot read property 'args' of undefined" error when @ignore is present #218

Closed
Borales opened this issue Dec 6, 2021 · 4 comments
Labels
bug Something isn't working

Comments

@Borales
Copy link

Borales commented Dec 6, 2021

Sample schema:

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

generator typegraphql {
  provider = "typegraphql-prisma"
}

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

model File {
  id      String @id @default(cuid())
  ownerId String @map("owner_id")

  owner User @relation("file_owner", fields: [ownerId], references: [id]) @ignore

  @@map("files")
}

model User {
  id String @id @default(cuid())

  uploadedFiles File[] @relation("file_owner")

  @@map("users")
}

When @ignore decorator is present (File model, owner relation) - typegraphql-prisma throws the following error:

✔ Generated Prisma Client (3.6.0 | library) to ./../node_modules/@prisma/client in 90ms

TypeError: Cannot read property 'args' of undefined
    at [..]/node_modules/typegraphql-prisma/lib/generator/dmmf/transform.js:347:50
    at Array.map (<anonymous>)
    at [..]/node_modules/typegraphql-prisma/lib/generator/dmmf/transform.js:345:14
    at Array.map (<anonymous>)
    at new DmmfDocument ([..]/node_modules/typegraphql-prisma/lib/generator/dmmf/dmmf-document.js:32:14)
    at generateCode ([..]/node_modules/typegraphql-prisma/lib/generator/generate-code.js:49:26)
    at Object.generate [as onGenerate] ([..]/node_modules/typegraphql-prisma/lib/cli/prisma-generator.js:45:39)
    at async LineStream.<anonymous> ([..]/node_modules/@prisma/generator-helper/dist/generatorHandler.js:36:24)

Environment:

  • OS: MacOS 12.0.1
  • Node 14.18
  • typegraphql-prisma version 0.18.1
  • Prisma version 3.6.0
  • TypeScript version 4.3.5

Additional Context

https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#ignore

@MichalLytek
Copy link
Owner

MichalLytek commented Dec 8, 2021

I think that you use @ignore in a wrong way.
The purpose of that feature is to exclude invalid relations to invalid models.
If you put @ignore also on the other side of the relation, it works correctly.

@MichalLytek MichalLytek added the question Further information is requested label Dec 8, 2021
@MichalLytek
Copy link
Owner

Fixed via 2fbe4a4 🔒

@MichalLytek MichalLytek added bug Something isn't working and removed question Further information is requested labels Dec 8, 2021
@Borales
Copy link
Author

Borales commented Dec 8, 2021

@MichalLytek apologies, I probably posted not the best sample.

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

generator typegraphql {
  provider = "typegraphql-prisma"
}

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

model File {
  id      String @id @default(cuid())
  ownerId String @map("owner_id")

  owner  User  @relation("file_owner", fields: [ownerId], references: [id])
  posts   Post[] @relation("post_thumbnail") @ignore

  @@map("files")
}

model User {
  id String @id @default(cuid())

  uploadedFiles File[] @relation("file_owner")

  @@map("users")
}

model Post {
  id String @id @default(cuid())
  thumbnailId String

  thumbnail      File           @relation("post_thumbnail", fields: [thumbnailId], references: [id], onDelete: SetNull)
}

I want to be able to access Post.thumbnail, but I don't care about File.posts (and I don't want it to be generated by Prisma).

Anyway, seems like you fixed this on dev. Is there an ETA for this to be released?

@MichalLytek
Copy link
Owner

Today will be a new release, as always 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants