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

[ClientExtensions, TypeScript] Fields of custom type aren't available when using the ClientExtensions preview-feature, unless select'd explicitly. #17388

Closed
Tracked by #19416
ItzSiL3Nce opened this issue Jan 18, 2023 · 2 comments · Fixed by #19517
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 topic: composite-types topic: mongodb
Milestone

Comments

@ItzSiL3Nce
Copy link

Bug description

Only when the clientExtensions preview-feature is enabled (just by enabling it, no need to define custom extensions), fields of a user-defined custom type aren't available after querying the model, unless select'd explicitly.
Note: They are available at runtime, only TypeScript doesn't have them, I'm using the MongoDB as the db provider. Also, might be related to #17349, but not sure.

How to reproduce

Simply create a Prisma model that has one or more fields of an user-defined type. That field won't be available (TypeScript's types only, it is available at runtime) unless it was explicitly selectd. Full example shown below.

Expected behavior

Every field (TypeScript) should be available after executing a query, including the ones of custom types. Just like it is when not using the clientExtensions preview-feature.

Prisma information

schema.prisma

type CustomType {
  data         String
  otherThings  String
  // ...
}

model ExampleUser {
  id        String @id @default(auto()) @map("_id") @db.ObjectId
  username  String
  password  String
  // ...
  otherData CustomType?
}

Using the prisma client

import { PrismaClient } from '@prisma/client'

const client = new PrismaClient()

async function main() {
  await client.$connect()
  
  const userNotWorking = await client.exampleUser.findFirst({ 
    where: {
      username: 'test-user'
    } 
  })

 // @ts-expect-error : Here the `otherData` field is not present inside the `userNotWorking` object.
 const dataNotWorking = userNotWorking.otherData

 // To make it work, the query needs `select` to be added with all the fields wanted.
  const user = await client.exampleUser.findFirst({ 
    where: {
      username: 'test-user'
    },
   select: {
      otherData: true
   }
  })


 // Here the `otherData` field is present inside the `user` object.
 const data = user.otherData
}

main()
  .catch(console.error)
  .finally(() => {
    client.$disconnect()
  })

Environment & setup

  • OS: Ubuntu
  • Database: MongoDB
  • Node.js version: Both 14.20.0 and 18.13.0 (LTS)
  • Preview Features: clientExtensions
  • Typescript: 4.9.4

Prisma Version

prisma                  : 4.9.0
@prisma/client          : 4.9.0
Current platform        : debian-openssl-3.0.x
Query Engine (Node-API) : libquery-engine ceb5c99003b99c9ee2c1d2e618e359c14aef2ea5 (at ../../node_modules/@prisma/engines/libquery_engine-debian-openssl-3.0.x.so.node)
Migration Engine        : migration-engine-cli ceb5c99003b99c9ee2c1d2e618e359c14aef2ea5 (at ../../node_modules/@prisma/engines/migration-engine-debian-openssl-3.0.x)
Introspection Engine    : introspection-core ceb5c99003b99c9ee2c1d2e618e359c14aef2ea5 (at ../../node_modules/@prisma/engines/introspection-engine-debian-openssl-3.0.x)
Format Binary           : prisma-fmt ceb5c99003b99c9ee2c1d2e618e359c14aef2ea5 (at ../../node_modules/@prisma/engines/prisma-fmt-debian-openssl-3.0.x)
Format Wasm             : @prisma/prisma-fmt-wasm 4.9.0-42.ceb5c99003b99c9ee2c1d2e618e359c14aef2ea5
Default Engines Hash    : ceb5c99003b99c9ee2c1d2e618e359c14aef2ea5
Studio                  : 0.479.0
Preview Features        : clientExtensions
@ItzSiL3Nce ItzSiL3Nce added the kind/bug A reported bug. label Jan 18, 2023
@millsp
Copy link
Member

millsp commented Jan 18, 2023

Thanks for the report! I can confirm this as we were conscious that in this first iteration we wouldn't yet support MongoDB's composite types.

@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: mongodb topic: composite-types topic: clientExtensions labels Jan 18, 2023
@pheuter
Copy link

pheuter commented Mar 15, 2023

This issue is currently preventing me from trying out my early access to Prisma Accelerate (since it requires enabling client extensions), looking forward to client extensions supporting composite types 👀

@SevInf SevInf self-assigned this May 30, 2023
SevInf added a commit that referenced this issue May 30, 2023
Only scalars were included into the default selection when extensions
are on.
Fixed by adding a separate section for composites in a payload type and
changing default selection to `scalars & composites`.
After fixing that, another problem with composites got uncovered: when
client extensions are enabled, delegate types for composites are broken.
Since fluent api does not work for composites (and was not inteded too),
generating delegate types was a mistake to begin with. Fixed by removing
delegate types and fluent getters for composites. I will not call it a
breaking change since again, this never worked and our types were just
incorrect.

Fix #17388
SevInf added a commit that referenced this issue May 30, 2023
Only scalars were included into the default selection when extensions
are on.
Fixed by adding a separate section for composites in a payload type and
changing default selection to `scalars & composites`.
After fixing that, another problem with composites got uncovered: when
client extensions are enabled, delegate types for composites are broken.
Since fluent api does not work for composites (and was not inteded too),
generating delegate types was a mistake to begin with. Fixed by removing
delegate types and fluent getters for composites. I will not call it a
breaking change since again, this never worked and our types were just
incorrect.

Fix #17388
@Jolg42 Jolg42 added this to the 4.16.0 milestone May 31, 2023
SevInf added a commit that referenced this issue Jun 1, 2023
Only scalars were included into the default selection when extensions
are on.
Fixed by adding a separate section for composites in a payload type and
changing default selection to `scalars & composites`.
After fixing that, another problem with composites got uncovered: when
client extensions are enabled, delegate types for composites are broken.
Since fluent api does not work for composites (and was not inteded too),
generating delegate types was a mistake to begin with. Fixed by removing
delegate types and fluent getters for composites. I will not call it a
breaking change since again, this never worked and our types were just
incorrect.

Fix #17388
SevInf added a commit that referenced this issue Jun 2, 2023
)

* fix(clientExtensions): Include composites into default selection

Only scalars were included into the default selection when extensions
are on.
Fixed by adding a separate section for composites in a payload type and
changing default selection to `scalars & composites`.
After fixing that, another problem with composites got uncovered: when
client extensions are enabled, delegate types for composites are broken.
Since fluent api does not work for composites (and was not inteded too),
generating delegate types was a mistake to begin with. Fixed by removing
delegate types and fluent getters for composites. I will not call it a
breaking change since again, this never worked and our types were just
incorrect.

Fix #17388

* Snapshots

* Restore original formatting
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 topic: composite-types topic: mongodb
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants