VSCode Autocomplete Not Functioning When Extending Prisma Schema
akshilshah opened this issue · 2 comments
Bug description
While extending Prisma, the autocomplete feature in Visual Studio Code (VSCode) is not functioning correctly.
How to reproduce
- Save the below code in the file
import { PrismaClient } from '@prisma/client'
// export const db = new PrismaClient()
export const db = new PrismaClient().$extends({
result: {
organizationEmail: {
emailAddress: {
needs: { email: true, domain: { select: { domain: true } } },
compute(email) {
return `${email.email}@${email.domain.domain}`
}
}
}
}
})
const main = async () => {
await db.
}
main()
- Run the prisma generate
- Write a code snippet with await db. and press Ctrl (or Command on Mac) + Space to trigger autocomplete
- Observe that the autocomplete feature is not working as expected.
Expected behavior
The autocomplete feature should suggest relevant fields, models, and other Prisma schema elements, facilitating easier and more accurate schema extensions. It should display the autocomplete suggestions as shown in the below screenshot.
Prisma information
// Add your schema.prisma
model Organization {
id Int @id @default(autoincrement()) /// Organization Id
name String /// Organization name
sitename String @unique ///represents a unique identifier for a organization site
subdomain String? ///represents a subdomain in a domain hierarchy
domain String? ///it represents the main identifier of a location
customPortalDomain String? @map("custom_portal_domain") ///it refers to the workplace of the customer
customCustomerDomain String? @map("custom_customer_domain") ///it refers to the end customer of the customer
@@map("organizations")
}
Environment & setup
- OS: macOS
- Database: PostgreSQL
- Node.js version: v20.10.0
- Vscode Prisma Extension Version: 5.13.1
Prisma Version
prisma : 5.13.0
@prisma/client : 5.13.0
Computed binaryTarget : darwin-arm64
Operating System : darwin
Architecture : arm64
Node.js : v20.10.0
Query Engine (Node-API) : libquery-engine b9a39a7ee606c28e3455d0fd60e78c3ba82b1a2b (at node_modules/prisma/node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Schema Engine : schema-engine-cli b9a39a7ee606c28e3455d0fd60e78c3ba82b1a2b (at node_modules/prisma/node_modules/@prisma/engines/schema-engine-darwin-arm64)
Schema Wasm : @prisma/prisma-schema-wasm 5.13.0-23.b9a39a7ee606c28e3455d0fd60e78c3ba82b1a2b
Default Engines Hash : b9a39a7ee606c28e3455d0fd60e78c3ba82b1a2b
Studio : 0.500.0
Your extension is not valid. I suppose you project is JS one, otherwise, TS typecheck would've told you that.
Relations are not supported in result extension, so domain
can not be specified in needs
.
See #20091 for feature request for relation support in result extensions.
Hi @SevInf
If I copy paste the below code which is from the https://www.prisma.io/docs/orm/prisma-client/client-extensions/query, vscode autocomplete still doesn't show up the suggestions.
Could you please help me with this?
const prisma = new PrismaClient().$extends({
query: {
user: {
async findMany({ model, operation, args, query }) {
// take incoming `where` and set `age`
args.where = { ...args.where, age: { gt: 18 } }
return query(args)
},
},
},
})
await prisma.user.findMany() // returns users whose age is greater than 18