zenstackhq / zenstack

Fullstack TypeScript toolkit that enhances Prisma ORM with flexible Authorization layer for RBAC/ABAC/PBAC/ReBAC, offering auto-generated type-safe APIs and frontend hooks.
https://zenstack.dev
MIT License
2.07k stars 88 forks source link

Error while generating from schema with enum and custom prisma output folder #485

Closed bphkns closed 1 year ago

bphkns commented 1 year ago

Description and expected behavior

If the client generator has different output folder then running generate throws error if schema contains enum.

For eg if we have the schema like below

generator client {
  provider = "prisma-client-js"
  output   = "../../../../node_modules/.prisma/abc-client"
  previewFeatures = ["fullTextSearch"]
}

datasource db {
  provider = "postgresql"
  url      = env("DB_URL")
}

enum Role {
  SUPER_ADMIN
  ADMIN
  USER
}

It throws errors while running npx zenstack generate

node_modules/.pnpm/@zenstackhq+runtime@1.0.0-alpha.126_@prisma+client@4.15.0/node_modules/.zenstack/policy.ts:3:10 - error TS2305: Module '"@prisma/client"' has no exported member 'Role'.
3 import { Role } from "@prisma/client";
           ~~~~
node_modules/.pnpm/@zenstackhq+runtime@1.0.0-alpha.126_@prisma+client@4.15.0/node_modules/.zenstack/policy.ts:4:10 - error TS2305: Module '"@prisma/client"' has no exported member 'Status'.
4 import { Status } from "@prisma/client";
           ~~~~~~
✖ Running plugin Access Policy
: Error compiling generated code

Screenshots If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

Additional context If we remove the enum from the schema it complies fine and works as expected

ymc9 commented 1 year ago

Thanks for filing this @bphkns. Yes, there are caveats when configuring prisma with a custom output location. Let me look into more details on how much a fix involves.

ymc9 commented 1 year ago

Fixed by #514