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

[v2.17.0] Missing client TS types Aggregate*Args #5749

Closed
steschwa opened this issue Feb 19, 2021 · 3 comments · Fixed by #20299
Closed

[v2.17.0] Missing client TS types Aggregate*Args #5749

steschwa opened this issue Feb 19, 2021 · 3 comments · Fixed by #20299
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. topic: client types Types in Prisma Client topic: type-clash
Milestone

Comments

@steschwa
Copy link

Since upgrading to v2.17.0 from v2.15.0 for both @prisma/client and prisma i get an TypeScript error stating that the Aggregate*Args types are missing:

VSCode screenshot - missing TS types

After some digging around in index.d.ts I've found the type AggregateUser which in my understanding should replace AggregateUserArgs in aggregateUser<T extends AggregateUserArgs>.

Unfortunately downgrading to v2.15.0 has a similar error.

I've used:

  • prisma migrate dev --preview-feature (added Table Query) after removing the prisma/migrations folder (as suggested here, although i did not switch DB providers)
  • prisma generate
  • prisma db seed --preview-feature

My prisma.schema:

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

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

model User {
    id        Int       @id @default(autoincrement())
    name      String?   @unique
    email     String    @unique
    password  String
    createdAt DateTime  @default(now())
    updatedAt DateTime? @updatedAt
}

enum MediaSource {
    LOCAL
    EXTERNAL
}

model Media {
    id           Int         @id @default(autoincrement())
    path         String
    source       MediaSource @default(LOCAL)
    mime         String
    previewImage String?     @db.Text
    createdAt    DateTime    @default(now())
    updatedAt    DateTime?   @updatedAt
    product      Product?
    market       Market?
}

model Product {
    id         Int        @id @default(autoincrement())
    name       String     @unique
    media      Media?     @relation(fields: [mediaId], references: [id])
    mediaId    Int?
    createdAt  DateTime   @default(now())
    updatedAt  DateTime?  @updatedAt
    expenses   Expense[]
    categories Category[]
}

model Market {
    id        Int       @id @default(autoincrement())
    name      String    @unique
    media     Media?    @relation(fields: [mediaId], references: [id])
    mediaId   Int?
    createdAt DateTime  @default(now())
    updatedAt DateTime? @updatedAt
    expenses  Expense[]
}

model Expense {
    id        Int      @id @default(autoincrement())
    product   Product  @relation(fields: [productId], references: [id])
    productId Int
    market    Market?  @relation(fields: [marketId], references: [id])
    marketId  Int?
    cost      Float
    amount    Int      @default(1)
    date      DateTime @db.Date
    createdAt DateTime @default(now())
}

model Category {
    id        Int       @id @default(autoincrement())
    name      String    @unique
    color     String?
    createdAt DateTime  @default(now())
    updatedAt DateTime? @updatedAt
    products  Product[]
}

model Query {
    id         Int       @id @default(autoincrement())
    color      String?
    collection String
    query      String    @db.Text
    createdAt  DateTime  @default(now())
    updatedAt  DateTime? @updatedAt
}
@steschwa
Copy link
Author

Alright i think i found the problem.

It's seems that there's a problem with database tables named Query. I was receiving the same error as in prisma/prisma-client-js#577 after declaring the missing TS types as dummies (type AggregateUserArgs = {}).

I first thought that it's a problem with my GraphQL query, which it wasn't. I'm not sure how this all relates to not generating the Aggregate* types (the include property for eager loading was also missing), but it seems to be the source of the problem.

I renamed my table name in the schema and everything works fine:

// Previous
// model Query {
model CalculatedQuery {
    id         Int       @id @default(autoincrement())
    color      String?
    collection String
    query      String    @db.Text
    createdAt  DateTime  @default(now())
    updatedAt  DateTime? @updatedAt
}

@wtachau
Copy link

wtachau commented Jun 22, 2023

Same issue— would be nice to have some docs (or at least a more helpful error message) on not naming a table Query

@janpio janpio added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. topic: client types Types in Prisma Client labels Jun 23, 2023
@janpio janpio reopened this Jun 23, 2023
SevInf added a commit that referenced this issue Jul 19, 2023
`DMMFHelper` did not take namespaces into account and merged them all
into single map, based on the name. This is incorrect, since it is
possible to have different type with the same name in different
namespaces. In particular, this broke models named either `Query` or
`Mutation` since they match built in names from `prisma` namespace.

Now we have a separate map for each namespace.

Fix #5749
Fix #9307
Fix #8153
SevInf added a commit that referenced this issue Jul 19, 2023
`DMMFHelper` did not take namespaces into account and merged them all
into single map, based on the name. This is incorrect, since it is
possible to have different type with the same name in different
namespaces. In particular, this broke models named either `Query` or
`Mutation` since they match built in names from `prisma` namespace.

Now we have a separate map for each namespace.

Fix #5749
Fix #9307
Fix #8153
@Jolg42 Jolg42 added this to the 5.1.0 milestone Jul 19, 2023
SevInf added a commit that referenced this issue Jul 20, 2023
`DMMFHelper` did not take namespaces into account and merged them all
into single map, based on the name. This is incorrect, since it is
possible to have different type with the same name in different
namespaces. In particular, this broke models named either `Query` or
`Mutation` since they match built in names from `prisma` namespace.

Now we have a separate map for each namespace.

Fix #5749
Fix #9307
Fix #8153
@SevInf
Copy link
Contributor

SevInf commented Jul 20, 2023

This issue is fixed and will be available in Prisma 5.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. topic: client types Types in Prisma Client topic: type-clash
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants