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

Typescript issue on nested queries with clientExtensions feature #17563

Closed
malekjaroslav opened this issue Jan 26, 2023 · 3 comments · Fixed by #17356
Closed

Typescript issue on nested queries with clientExtensions feature #17563

malekjaroslav opened this issue Jan 26, 2023 · 3 comments · Fixed by #17356
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/typescript Issue for tech TypeScript. topic: client types Types in Prisma Client topic: clientExtensions
Milestone

Comments

@malekjaroslav
Copy link

malekjaroslav commented Jan 26, 2023

Bug description

When clientExtensions feature is added to Prisma some nested queries start throwing Typescript errors . For example this nested query below throws an error saying "tenant" is not available on "version" but it should be. The query works just fine without the extension and weirdly enough it works fine even when take and orderBy are omitted from the query.

How to reproduce

  // When "take" and "orderBy" is included, typescript shows an error
  const contract = await prisma.rentContract.findUniqueOrThrow({
    where: {
      id: "",
    },
    include: {
      tenant: true,
      versions: {
        take: 1,
        orderBy: {
          createdAt: "desc",
        },
        include: {
          tenant: true,
        },
      },
    },
  });
  // Error on tenant
  contract.versions[0]?.tenant.name;

  // When "take" and "orderBy" is excluded, typescript shows correct suggestions
  const contract2 = await prisma.rentContract.findUniqueOrThrow({
    where: {
      id: "",
    },
    include: {
      tenant: true,
      versions: {
        /* take: 1,
        orderBy: {
          createdAt: "desc",
        },*/
        include: {
          tenant: true,
        },
      },
    },
  });
   // No error
  contract2.versions[0]?.tenant.name;

Expected behavior

It should not throw an error

Prisma information

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["clientExtensions"]
}

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


model Tenant {
  id          String         @id @default(cuid())
  name        String
  contracts   RentContract[]

  createdAt DateTime  @default(now())
  deletedAt DateTime?
}



model RentContract {
  id               String              @id @default(cuid())
  tenant           Tenant              @relation(fields: [tenantId], references: [id])
  tenantId         String
  versionOf        RentContract?       @relation("Versions", fields: [versionOfId], references: [id])
  versionOfId      String?
  versions         RentContract[]      @relation("Versions")

  updatedAt DateTime  @updatedAt
  createdAt DateTime  @default(now())
  deletedAt DateTime?
}

Environment & setup

  • OS: macOS
  • Node.js version: v16.18.0

Prisma Version

4.9.0
@malekjaroslav malekjaroslav added the kind/bug A reported bug. label Jan 26, 2023
@malekjaroslav malekjaroslav changed the title Typescript issue in nested queries with clientExtensions feature Typescript issue om nested queries with clientExtensions feature Jan 26, 2023
@malekjaroslav malekjaroslav changed the title Typescript issue om nested queries with clientExtensions feature Typescript issue on nested queries with clientExtensions feature Jan 26, 2023
@millsp millsp added bug/2-confirmed Bug has been reproduced and confirmed. topic: client types Types in Prisma Client tech/typescript Issue for tech TypeScript. team/client Issue for team Client. topic: clientExtensions labels Jan 27, 2023
@millsp
Copy link
Member

millsp commented Jan 27, 2023

Thanks for the report. I can immediately confirm this as it was also reported here #17349.

@millsp millsp added this to the 4.10.0 milestone Jan 30, 2023
@millsp millsp self-assigned this Jan 30, 2023
@jove4015
Copy link

jove4015 commented Feb 6, 2023

@millsp - This bug is marked resolved, however, client extensions still are not usable (see #17767). Is there any progress on making this feature functionally available?

@millsp
Copy link
Member

millsp commented Feb 6, 2023

Hey @jove4015, the fix will be release tomorrow. If you want, you can install @prisma/client@dev to try it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/typescript Issue for tech TypeScript. topic: client types Types in Prisma Client topic: clientExtensions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants