omar-dulaimi / prisma-trpc-generator

Prisma 2+ generator to emit fully implemented tRPC routers
MIT License
675 stars 34 forks source link

Router generation fails on "...OrThrow" queries #42

Closed fleischerdesign closed 1 year ago

fleischerdesign commented 1 year ago

Bug description

Since updating to version 0.6.0, my route generation fails on all "OrThrow" queries. The generated Router has on all of those queries an undefined procedure name and an undefined input:

Bildschirm­foto 2022-11-12 um 13 40 21

How to reproduce

  1. Run Prisma generate
  2. Look at the generated Router files

Expected behavior

The generated Procedure should be either "Mutation" or "Query" and the input should not be "undefined".

Prisma information

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

generator client {
  provider = "prisma-client-js"
}

generator trpc {
  provider       = "prisma-trpc-generator"
  withMiddleware = false
  withShield     = true
  contextPath    = "../../../../context"
  isGenerateSelect   = true
  isGenerateInclude  = true
}

model User {
  id                Int                 @id @default(autoincrement())
  email             String              @unique
  password          String
  name              String
  messages          Message[]
  tokens            Token[]
  ownedChats        Chat[]              @relation("Owner")
  chats             Chat[]
  EmailConfirmation EmailConfirmation[]
}

model Message {
  id        Int      @id @default(autoincrement())
  createdAt DateTime
  createdBy User     @relation(fields: [creatorId], references: [id])
  creatorId Int
  chat      Chat     @relation(fields: [chatId], references: [id])
  chatId    Int
  content   String
}

model Chat {
  id        Int       @id @default(autoincrement())
  title     String
  createdAt DateTime
  creatorId Int
  creator   User      @relation(name: "Owner", fields: [creatorId], references: [id])
  users     User[]
  messages  Message[]
}

model Token {
  id        Int      @id @default(autoincrement())
  createdAt DateTime
  token     String   @unique
  user      User     @relation(fields: [userId], references: [id])
  userId    Int
  lifetime  Int
}

model EmailConfirmation {
  id        Int      @id @default(autoincrement())
  createdAt DateTime
  token     String   @unique
  user      User     @relation(fields: [userId], references: [id])
  userId    Int
  lifetime  Int
}

Environment & setup

OS: MacOS Database: PostgreSQL Node.js Version: 18.11.0

Prisma Version

prisma                  : 4.6.1
@prisma/client          : 4.6.1
Current platform        : darwin-arm64
Query Engine (Node-API) : libquery-engine 694eea289a8462c80264df36757e4fdc129b1b32 (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine        : migration-engine-cli 694eea289a8462c80264df36757e4fdc129b1b32 (at node_modules/@prisma/engines/migration-engine-darwin-arm64)
Introspection Engine    : introspection-core 694eea289a8462c80264df36757e4fdc129b1b32 (at node_modules/@prisma/engines/introspection-engine-darwin-arm64)
Format Binary           : prisma-fmt 694eea289a8462c80264df36757e4fdc129b1b32 (at node_modules/@prisma/engines/prisma-fmt-darwin-arm64)
Format Wasm             : @prisma/prisma-fmt-wasm 4.6.1-3.694eea289a8462c80264df36757e4fdc129b1b32
Default Engines Hash    : 694eea289a8462c80264df36757e4fdc129b1b32
Studio                  : 0.476.0
kristinlindquist commented 1 year ago

I just ran into this too and believe I fixed it with this PR - https://github.com/omar-dulaimi/prisma-trpc-generator/pull/43. @omar-dulaimi would you mind reviewing?

cc @Shahidul1004

omar-dulaimi commented 1 year ago

@kristinlindquist Yes, of course. I'm taking a look at the code

omar-dulaimi commented 1 year ago

Released in https://github.com/omar-dulaimi/prisma-trpc-generator/releases/tag/0.6.1