AssertionError: Cannot find model by name...
Hello. I am going to use nested documents in MongoDB. Prisma implements this with ebedded types and therefore changed "model" to "type" in the prisma schema. Result during "prisma generate":
✔ Generated Prisma Client (3.13.0 | library) to ./node_modules/@prisma/client in 436ms
AssertionError [ERR_ASSERTION]: Cannot find model by name AvaliblePrintArea
at AwaitEventEmitter.modelOutputType (/home/satyadev/PROJECTS/printi-price/node_modules/prisma-nestjs-graphql/index.js:1049:25)
at AwaitEventEmitter.<anonymous> (/home/satyadev/PROJECTS/printi-price/node_modules/await-event-emitter/lib/index.js:115:39)
at Generator.next (<anonymous>)
at /home/satyadev/PROJECTS/printi-price/node_modules/await-event-emitter/lib/index.js:12:71
at new Promise (<anonymous>)
at __awaiter (/home/satyadev/PROJECTS/printi-price/node_modules/await-event-emitter/lib/index.js:8:12)
at AwaitEventEmitter.emit (/home/satyadev/PROJECTS/printi-price/node_modules/await-event-emitter/lib/index.js:108:16)
at generate (/home/satyadev/PROJECTS/printi-price/node_modules/prisma-nestjs-graphql/index.js:2050:24)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Object.onGenerate (/home/satyadev/PROJECTS/printi-price/node_modules/prisma-nestjs-graphql/index.js:2095:5)
Part of the schema.prisma
model Variant {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String
avaliblePrintAreas AvaliblePrintArea[]
type AvaliblePrintArea {
position String
height Int
width Int
}
Environment "@prisma/client": "^3.13.0", "prisma": "^3.13.0", "prisma-nestjs-graphql": "^15.2.2", "@nestjs/common": "^8.0.0", "@nestjs/core": "^8.0.0", "@nestjs/graphql": "^10.0.8",
Where is defined AvaliblePrintArea? Inside model?
It's not valid syntax (prisma v3.14)
model Variant {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String
avaliblePrintAreas AvaliblePrintArea[]
}
type AvaliblePrintArea {
position String
height Int
width Int
}
With schema above I do not have such errors
AvaliblePrintArea is defined inside the Variant model.
I don't have an invalid syntax error.
Have you tried with MongoDB Connector?
When I disable "generator nestgraphql", prisma generate works correctly. I can query and add nested documents in MongoDB.
Yes I tried with mongodb as provider option.
Could you specify other options from your schema?
And link to prisma documentation about nested embedded types.
- Options from prisma schema
generator client {
provider = "prisma-client-js"
previewFeatures = ["fullTextIndex", "extendedIndexes"]
}
generator nestgraphql {
provider = "node node_modules/prisma-nestjs-graphql"
output = "../libs/prisma/src/lib/@generated/prisma-nestjs-graphql"
useInputType_WhereInput_ALL = "WhereInput"
fields_Validator_from = "class-validator"
fields_Validator_input = true
}
datasource db {
provider = "mongodb"
url = env("MONGODB_URI")
}
I do not see where type defined inside model.
https://www.prisma.io/docs/concepts/components/prisma-client/composite-types#example-schema this example is working for me, with one exception, I replaced price Decimal to price Int
Because of error
Error: Schema parsing
error: Error validating field `price` in model `Product`: Field `price` in model `Product` can't be of type Decimal. The current connector does not support the Decimal type.
--> schema.prisma:47
Can you please tell me what other data I can provide to help you reproduce the problem?
Repository with steps to reproduce is ideal option. But full schema or part of it which reproduce the error is also ok.