Quramy / prisma-fabbrica

Prisma generator to define model factory
MIT License
244 stars 13 forks source link

prisma-fabbrica supports Multi-file Prisma Schema? #395

Open tomlla opened 3 hours ago

tomlla commented 3 hours ago

Describe the bug In my unit test, sometimes npx prisma generate fails (fleaky test)

[NOTE] I'm using Multi-file prisma schema feature. I'd like to get more information about the supported status of the Multi-file Prisma Schema in the README.md.

Prisma Documentation https://www.prisma.io/docs/orm/prisma-schema/overview/location#multi-file-prisma-schema

To Reproduce

npx prisma generate --no-hints
Environment variables loaded from .env
Prisma schema loaded from prisma/schema
Error: 
✔ Generated Prisma Client (v5.20.0) to ./node_modules/@prisma/client in 973ms

ENOENT: no such file or directory, open '/app/prisma/src/__generated__/fabbrica/index.js'

Expected behavior

$ npx prisma generate --no-hints
Environment variables loaded from .env
Prisma schema loaded from prisma/schema

✔ Generated Prisma Client (v5.19.0) to ./node_modules/@prisma/client in 276ms

✔ Generated fabbrica to ./prisma/src/__generated__/fabbrica in 4.10s

NOTE: Generally, prisma-fabbrica generate the code into src/__generated__/fabbrica

But in my project prisma-fabbrica ouptuts to prisma/src/__generated__/fabbrica

This in itself is not a problem. I believe this behavior occurs due to the Multi-file schema setup. Does prisma-fabbrica use a relative path of schema.prisma? I manually run mv prisma/src/__generated__ src/__generated__ each time.

Anyway, the main issue is that prisma-fabbrica's code generation is failing during npx prisma generate.

Environment (please complete the following information):

Your Schema

I have prisma/schema/schema.prisma and mutiple schema files (about 50 files)

generator client {
  provider        = "prisma-client-js"
  binaryTargets   = ["native", "debian-openssl-3.0.x"]
  previewFeatures = ["prismaSchemaFolder"]
}

generator fabbrica {
  provider = "prisma-fabbrica"
}

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

Your tsconfig.json

Paste TypeScript configuration if you have problem about TypeScript compilation.

```json { "compilerOptions": { "module": "commonjs", "esModuleInterop": true, "declaration": true, "removeComments": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "allowSyntheticDefaultImports": true, "target": "es2020", "sourceMap": true, "outDir": "./dist", "baseUrl": ".", "paths": { "@/*": ["src/*"] }, "incremental": true, "strict": true, "lib": [ "ES2021.String", "es2020" ], "skipLibCheck": true, "strictNullChecks": true, "noImplicitAny": true, "strictBindCallApply": true, "forceConsistentCasingInFileNames": true, "noFallthroughCasesInSwitch": true, "plugins": [ { "name": "eslint-plugin-import-access" } ], "types": ["vitest/globals", "vitest-environment-vprisma"] }, "include": ["src/**/*.ts", "src/**/*.js", "vitest.config.ts"] } ```
tomlla commented 3 hours ago

If the Multi-file Prisma Schema is not supported, I'll close this issue.