Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Zod schema import path #76

Open
andenacitelli opened this issue Mar 21, 2023 · 4 comments
Open

Incorrect Zod schema import path #76

andenacitelli opened this issue Mar 21, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@andenacitelli
Copy link

andenacitelli commented Mar 21, 2023

Bug description

My generated schemas have subfolders for enums and objects, but the generated routers seem to expect the schemas to be in that root folder instead of in the subfolders.

Generated Router:

import { t, publicProcedure } from "./helpers/createRouter";
import { LocationCreateManySchema } from "../schemas/createManyLocation.schema";
import { LocationCreateOneSchema } from "../schemas/createOneLocation.schema";
import { LocationDeleteManySchema } from "../schemas/deleteManyLocation.schema";
import { LocationDeleteOneSchema } from "../schemas/deleteOneLocation.schema";
import { LocationFindFirstSchema } from "../schemas/findFirstLocation.schema";
import { LocationFindManySchema } from "../schemas/findManyLocation.schema";
import { LocationFindUniqueSchema } from "../schemas/findUniqueLocation.schema";
import { LocationUpdateManySchema } from "../schemas/updateManyLocation.schema";
import { LocationUpdateOneSchema } from "../schemas/updateOneLocation.schema";
import { LocationUpsertSchema } from "../schemas/upsertOneLocation.schema";

export const locationsRouter = t.router({
  createManyLocation: publicProcedure
    .input(LocationCreateManySchema).mutation
// Rest of file...

File Structure:
image

How to reproduce

npm i prisma-trpc-generator

Add generator to Prisma schema:

generator trpc {
  provider             = "prisma-trpc-generator"
  withZod              = true
  withMiddleware       = false
  withShield           = false
  contextPath          = "@endwise/server/trpc"
  trpcOptionsPath      = "@endwise/server/trpc"
}

npx prisma generate

Expected behavior

Import paths are correct. For example, import { LocationCreateManySchema } from "../schemas/createManyLocation.schema"; should instead be import { LocationCreateManySchema } from "../schemas/objects/createManyLocation.schema";

Prisma information

Schema:

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator zod {
  provider         = "zod-prisma-types"
  createModelTypes = false
}

generator trpc {
  provider             = "prisma-trpc-generator"
  withZod              = true
  withMiddleware       = false
  withShield           = false
  contextPath          = "@endwise/server/trpc"
  trpcOptionsPath      = "@endwise/server/trpc"
}

generator client {
  provider = "prisma-client-js"
  output   = "./generated/prisma"
}

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

model CacheEntry {
  key   String @id @map("_id")
  value String
}

model User {
  // App-Agnostic
  id         String  @id @default(auto()) @map("_id") @db.ObjectId
  email      String  @unique
  customerId String?

  // App-Specific
  tasks         Task[]
  epics         Epic[]
  projects      Project[]
  schedules     Schedule[]
  locations     Location[]
  taskTemplates TaskTemplate[]
}

model Task {
  id          String            @id @default(auto()) @map("_id") @db.ObjectId
  title       String
  description String? // Rich-Text
  recurrence  RecurrenceOptions @default(NONE) // TODO: Needs fleshed out a bit; aim for Google Calendar level of customizability
  locations   Location[]
  // TODO: Location blacklist
  size        TaskSize          @default(MEDIUM) // Defaults to Medium, but will likely be set by GPT or the user.
  start       DateTime?
  end         DateTime?
  createdAt   DateTime          @default(now())
  updatedAt   DateTime          @updatedAt

  // TODO: Parent Task

  // TODO: 1:N Dependencies

  // Linkage
  User           User          @relation(fields: [userEmail], references: [email])
  userEmail      String        @unique
  Epic           Epic?         @relation(fields: [epicId], references: [id])
  epicId         String?       @db.ObjectId
  Project        Project?      @relation(fields: [projectId], references: [id])
  projectId      String?       @db.ObjectId
  TaskTemplate   TaskTemplate? @relation(fields: [taskTemplateId], references: [id])
  taskTemplateId String?       @db.ObjectId
}

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

  // Linkage
  User      User?    @relation(fields: [userEmail], references: [id])
  userEmail String?  @db.ObjectId
  tasks     Task[]
  Project   Project? @relation(fields: [projectId], references: [id])
  projectId String?  @db.ObjectId
}

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

  // Linkage
  User      User?   @relation(fields: [userEmail], references: [id])
  userEmail String? @db.ObjectId
  epics     Epic[]
  tasks     Task[]
}

model Location {
  id          String @id @default(auto()) @map("_id") @db.ObjectId
  nickname    String
  latitude    Float
  longitude   Float
  radiusMiles Int // Radius in which user is considered to be at this location

  // Linkage
  User      User?   @relation(fields: [userEmail], references: [id])
  userEmail String? @db.ObjectId
  Task      Task?   @relation(fields: [taskId], references: [id])
  taskId    String? @db.ObjectId
}

model TaskTemplate {
  id    String @id @default(auto()) @map("_id") @db.ObjectId
  tasks Task[]

  // Linkage
  User      User?   @relation(fields: [userEmail], references: [email])
  userEmail String? @unique
}

model Schedule {
  id        String     @id @default(auto()) @map("_id") @db.ObjectId
  timeslots Timeslot[]

  // Linkage
  User      User?   @relation(fields: [userEmail], references: [email])
  userEmail String? @unique
}

model Timeslot {
  id           String @id @default(auto()) @map("_id") @db.ObjectId
  startSeconds Int // # of Seconds Into Week
  endSeconds   Int // # of Seconds Into Week

  // Linkage
  Schedule   Schedule @relation(fields: [scheduleId], references: [id])
  scheduleId String   @db.ObjectId
}

/// JIRA-esque Task Statuses
enum TaskSize {
  SMALL
  MEDIUM
  LARGE
  EXTRA_LARGE
}

enum DayOfTheWeek {
  MONDAY
  TUESDAY
  WEDNESDAY
  THURSDAY
  FRIDAY
  SATURDAY
  SUNDAY
}

enum RecurrenceOptions {
  NONE
  DAILY
  WEEKLY
  MONTHLY
}

Environment & setup

  • OS: Windows
  • Database: MongoDB (shouldn't matter)
  • Node.js Version: v18.14.2

Prisma Version

Environment variables loaded from .env
prisma                  : 4.11.0
@prisma/client          : 4.11.0
Current platform        : windows
Query Engine (Node-API) : libquery-engine 8fde8fef4033376662cad983758335009d522acb (at ..\..\node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine        : migration-engine-cli 8fde8fef4033376662cad983758335009d522acb (at ..\..\node_modules\@prisma\engines\migration-engine-windows.exe)
Format Wasm             : @prisma/prisma-fmt-wasm 4.11.0-57.8fde8fef4033376662cad983758335009d522acb
Default Engines Hash    : 8fde8fef4033376662cad983758335009d522acb
Studio                  : 0.483.0
@omar-dulaimi omar-dulaimi added the bug Something isn't working label May 6, 2023
@omar-dulaimi
Copy link
Owner

I think the issue is a little bit different than the description. Am I right with the following being the actual problem?

// wrong
import { LocationAggregateRawObjectSchema } from "../schemas/aggregateRawLocation.schema";

// correct
import { LocationAggregateRawObjectSchema } from "../schemas/objects/LocationAggregateRaw.schema";


// same problem for `LocationFindRawObjectSchema`

@andenacitelli
Copy link
Author

I think the issue is a little bit different than the description. Am I right with the following being the actual problem?


// wrong

import { LocationAggregateRawObjectSchema } from "../schemas/aggregateRawLocation.schema";



// correct

import { LocationAggregateRawObjectSchema } from "../schemas/objects/LocationAggregateRaw.schema";





// same problem for `LocationFindRawObjectSchema`

Yes, that's correct. Paths generated expect the schemas to be directly inside the schemas folder rather than schemas/objects.

@tamutus
Copy link

tamutus commented Oct 6, 2023

image

The problem I'm facing is that, because zod-prisma doesn't work for Prisma 5, and prisma-zod-generator doesn't work for Prisma 5, I am using zod-prisma-types which does work for Prisma 5 and that generates files to the directory structure as follows:

image

@flawnson
Copy link

flawnson commented Feb 5, 2024

I'm having the same problem; my schemas directory is empty (aside from an enums directory which is also empty) yet all the generated routers are pointing to .schema files within the schemas directory. Could this be related to issue #84 with Prisma 5?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants