prisma-nestjs-graphql icon indicating copy to clipboard operation
prisma-nestjs-graphql copied to clipboard

AssertionError: Cannot find model by name...

Open Signaturo opened this issue 3 years ago • 7 comments

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",

Signaturo avatar May 19 '22 19:05 Signaturo

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

unlight avatar May 19 '22 22:05 unlight

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.

Signaturo avatar May 20 '22 13:05 Signaturo

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.

unlight avatar May 20 '22 13:05 unlight

  1. Prisma documentation about nested composite types
  1. 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")
}

Signaturo avatar May 20 '22 21:05 Signaturo

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

unlight avatar May 25 '22 08:05 unlight

Can you please tell me what other data I can provide to help you reproduce the problem?

Signaturo avatar Jun 04 '22 20:06 Signaturo

Repository with steps to reproduce is ideal option. But full schema or part of it which reproduce the error is also ok.

unlight avatar Jun 05 '22 18:06 unlight