omar-dulaimi / prisma-zod-generator

Prisma 2+ generator to emit Zod schemas from your Prisma schema
MIT License
535 stars 45 forks source link

Bad prisma-client import #9

Closed altarrok closed 2 years ago

altarrok commented 2 years ago

Bug description

Generated object schemas have a bad prisma-client import when client output is "../src/generated/prisma-client" and zod output is "../src/generated/zod" in Windows:

import type { Prisma } from '......prisma-client';

How to reproduce

  1. add output = "../src/generated/prisma-client" to client generator config in schema.prisma
  2. add output = "../src/generated/zod" to zod generator config in schema.prisma
  3. Run yarn prisma generate
  4. Go to src\generated\zod\schemas\objects\XCreateInput.schema.ts
  5. See import type { Prisma } from '......prisma-client';

Expected behavior

import type { Prisma } from '../../../prisma-client';

Prisma information

generator client { provider = "prisma-client-js" output = "../src/generated/prisma-client" binaryTargets = ["native", "rhel-openssl-1.0.x"] }

generator zod { provider = "prisma-zod-generator" output = "../src/generated/zod" }

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

model X { id String @id @default(auto()) @map("_id") @db.ObjectId }

Environment & setup

Prisma Version

prisma                  : 4.1.0
@prisma/client          : 4.1.0
Current platform        : windows
Query Engine (Node-API) : libquery-engine 8d8414deb360336e4698a65aa45a1fbaf1ce13d8 (at node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine        : migration-engine-cli 8d8414deb360336e4698a65aa45a1fbaf1ce13d8 (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine    : introspection-core 8d8414deb360336e4698a65aa45a1fbaf1ce13d8 (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary           : prisma-fmt 8d8414deb360336e4698a65aa45a1fbaf1ce13d8 (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash    : 8d8414deb360336e4698a65aa45a1fbaf1ce13d8
Studio                  : 0.467.
omar-dulaimi commented 2 years ago

Hey @altarrok

Sadly, I do not have a Windows machine to try it out. On my Linux machine though, your config worked fine and generated this import:

import type { Prisma } from '../../../prisma-client';

So, is it possible that you attempt fixing this? I'm more than happy to accept your changes and guide you along the way.

Also, don't forget to star this project if you find it helpful :)

altarrok commented 2 years ago

@omar-dulaimi Yeah sure, I already implemented a fix, I don't have the perms tho, how can I create a PR? thx

omar-dulaimi commented 2 years ago

@altarrok 1- Fork 2- Clone 3- Create a local branch for the fix 4- Push to your fork 5- From your Github repo, create PR

altarrok commented 2 years ago

@omar-dulaimi thanks for the steps, created the PR: #10

omar-dulaimi commented 2 years ago

@altarrok Thanks for your contribution. Any others you have are welcomed, just make sure to start an issue first so we can discuss it :)

Released in: https://github.com/omar-dulaimi/prisma-zod-generator/releases/tag/0.4.1