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

Prisma Accelerate not working with trpc #23104

Closed
afif1400 opened this issue Feb 13, 2024 · 2 comments
Closed

Prisma Accelerate not working with trpc #23104

afif1400 opened this issue Feb 13, 2024 · 2 comments
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. domain/pdp Issue in the "PDP" domain: Prisma Data Platform kind/bug A reported bug. topic: @prisma/extension-accelerate

Comments

@afif1400
Copy link

afif1400 commented Feb 13, 2024

Bug description

Cannot fetch data from service:
fetch failed
    at eval (./src/trpc/server.ts:62:98)
Cause: PrismaClientKnownRequestError: 
Invalid prisma.student.findMany() invocation:


Cannot fetch data from service:
fetch failed
    at ai.handleRequestError (/Users/mohammed.afif/Developer/apps/fl/eduvault/node_modules/.pnpm/@prisma+client@5.9.1_prisma@5.9.1/node_modules/@prisma/client/runtime/library.js:126:6775)
    ... 8 lines matching cause stack trace ...
    at async resolve (webpack-internal:///(rsc)/./node_modules/.pnpm/@trpc+server@10.45.1/node_modules/@trpc/server/dist/index.mjs:494:24) {
  code: 'INTERNAL_SERVER_ERROR',
  name: 'TRPCError',
  [cause]: PrismaClientKnownRequestError: 
  Invalid prisma.student.findMany() invocation:

How to reproduce

using t3 stack with planetscale database and prisma accelerate

Expected behavior

Works without prisma accelerate

Prisma information

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

datasource db {
    provider     = "mysql"
    url          = env("DATABASE_URL")
    directUrl    = env("DIRECT_DATABASE_URL")
    relationMode = "prisma"
}

model Post {
    id        String   @id @default(cuid())
    name      String
    createdAt DateTime @default(now())
    updatedAt DateTime @updatedAt

    createdBy   User   @relation(fields: [createdById], references: [id])
    createdById String

    @@index([name])
    @@index([createdById])
}

// Necessary for Next auth
model Account {
    id                String  @id @default(cuid())
    userId            String
    type              String
    provider          String
    providerAccountId String
    refresh_token     String? @db.Text
    access_token      String? @db.Text
    expires_at        Int?
    token_type        String?
    scope             String?
    id_token          String? @db.Text
    session_state     String?
    user              User    @relation(fields: [userId], references: [id], onDelete: Cascade)

    @@unique([provider, providerAccountId])
    @@index([userId])
}

model Session {
    id           String   @id @default(cuid())
    sessionToken String   @unique
    userId       String
    expires      DateTime
    user         User     @relation(fields: [userId], references: [id], onDelete: Cascade)

    @@index([userId])
}

model User {
    id            String    @id @default(cuid())
    name          String?
    email         String?   @unique
    password      String?
    emailVerified DateTime?
    role          Role      @default(USER)
    image         String?
    referral      Referral?
    points        Reward?
    accounts      Account[]
    sessions      Session[]
    posts         Post[]
    students      Student[]
    // achievements  Achievement[]
}

model Referral {
    id        String   @default(cuid())
    code      String   @unique
    count     Int      @default(0)
    createdAt DateTime @default(now())
    updatedAt DateTime @updatedAt

    user   User   @relation(fields: [userId], references: [id])
    userId String @unique

    @@index([code])
    @@index([userId])
}

model Reward {
    id        String   @default(cuid())
    points    Int      @default(0)
    createdAt DateTime @default(now())
    updatedAt DateTime @updatedAt

    user   User   @relation(fields: [userId], references: [id])
    userId String @unique

    @@index([userId])
}

model VerificationToken {
    identifier String
    token      String   @unique
    expires    DateTime

    @@unique([identifier, token])
}

// add a Role enum to your schema
enum Role {
    USER
    ADMIN
}

model Student {
    id         String        @id @default(cuid())
    name       String
    achivments Achievement[]
    createdAt  DateTime      @default(now())
    updatedAt  DateTime      @updatedAt

    createdBy   User   @relation(fields: [createdById], references: [id])
    createdById String

    @@index([name])
    @@index([createdById])
}

model Achievement {
    id          String   @id @default(cuid())
    name        String
    description String
    files       File[]
    grade       String   @default("1")
    createdAt   DateTime @default(now())
    updatedAt   DateTime @updatedAt

    student   Student @relation(fields: [studentId], references: [id], onDelete: Cascade)
    studentId String

    @@index([name])
    @@index([studentId])
}

model File {
    id        String   @id @default(cuid())
    name      String
    type      String
    url       String
    key       String
    size      Int
    extension String
    height    Int?
    width     Int?
    createdAt DateTime @default(now())
    updatedAt DateTime @updatedAt

    achievement   Achievement @relation(fields: [achievementId], references: [id], onDelete: Cascade)
    achievementId String

    @@index([name])
    @@index([achievementId])
}
import { PrismaClient } from "@prisma/client";
import { withAccelerate } from "@prisma/extension-accelerate";

import { env } from "@/env";

const prismaClientSingleton = () => {
  return new PrismaClient().$extends(withAccelerate());
};

type PrismaClientSingleton = ReturnType<typeof prismaClientSingleton>;

const globalForPrisma = globalThis as unknown as {
  prisma: PrismaClientSingleton | undefined;
};

export const db =
  globalForPrisma.prisma ??
  new PrismaClient({
    log:
      env.NODE_ENV === "development" ? ["query", "error", "warn"] : ["error"],
  }).$extends(withAccelerate());

if (env.NODE_ENV !== "production") globalForPrisma.prisma = db;

Environment & setup

  • OS: macOS
  • Database: PlanetScale
  • Node.js version: 20

Prisma Version

prisma                  : 5.9.1
@prisma/client          : 5.9.1
Computed binaryTarget   : darwin-arm64
Operating System        : darwin
Architecture            : arm64
Node.js                 : v20.9.0
Query Engine (Node-API) : libquery-engine 23fdc5965b1e05fc54e5f26ed3de66776b93de64 (at node_modules/.pnpm/@prisma+engines@5.9.1/node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Schema Engine           : schema-engine-cli 23fdc5965b1e05fc54e5f26ed3de66776b93de64 (at node_modules/.pnpm/@prisma+engines@5.9.1/node_modules/@prisma/engines/schema-engine-darwin-arm64)
Schema Wasm             : @prisma/prisma-schema-wasm 5.9.0-32.23fdc5965b1e05fc54e5f26ed3de66776b93de64
Default Engines Hash    : 23fdc5965b1e05fc54e5f26ed3de66776b93de64
Studio                  : 0.497.0
@afif1400 afif1400 added the kind/bug A reported bug. label Feb 13, 2024
@jkomyno
Copy link
Contributor

jkomyno commented Feb 13, 2024

Hi @afif1400, the error you provided refers to trpc, but the code snippet pasted above doesn't show any usage of trpc.
Can you please provide a minimal, self-contained reproduction repository, so we can reproduce and analyse this issue, and understand the next steps to fix it? Thanks!

@jkomyno jkomyno added bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. topic: @prisma/extension-accelerate labels Feb 13, 2024
@janpio janpio added the domain/pdp Issue in the "PDP" domain: Prisma Data Platform label Feb 14, 2024
@nurul3101
Copy link
Member

@afif1400 I'll close the GitHub Issue here as this repository is for the open source Prisma ORM and not for the commercial products like Prisma Accelerate. Let's continue the conversation on the Discord post that you have initiated:
https://discord.com/channels/937751382725886062/1206900837260070974

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. domain/pdp Issue in the "PDP" domain: Prisma Data Platform kind/bug A reported bug. topic: @prisma/extension-accelerate
Projects
None yet
Development

No branches or pull requests

4 participants