T3 Stack Tutorial - Posts won't retain

Hello! I am new here and new to TS and React. I am attempting to follow along with Theo's amazing T3 stack tutorial but have been running into an issue I was hoping someone would be able to assist with. Upon running the app, I keep getting the error: prisma:query SELECT trilldb.Post.id, trilldb.Post.createdAt, trilldb.Post.content, trilldb.Post.authorId FROM trilldb.Post WHERE 1=1 ORDER BY trilldb.Post.createdAt DESC LIMIT ? OFFSET ? ❌ tRPC failed on posts.getAll: Cannot read properties of undefined (reading 'users') Ultimately what keeps happening is the posts won't retain on the app side but on the Prisma side they are.. Any suggestions? I can provide further context, but does anyone have a quick solution for how they resolved this issue? I've tried searching online/stack overflow but to no avail.
64 Replies
thevalorised
thevalorised14mo ago
We might need to see the implementation of the router that calls posts.getAll and how it is called on the frontend but it can simply be a db mismatch issue. Make sure you have your schema file right, sync the db and generate types with npx prisma db push, and check if data actually exists on db with npx prisma studio
lil_bixbyte
lil_bixbyte14mo ago
Thank you for the suggestion. Unfortunately the issue persists. What's happening is the post data exists on the db but I keep getting errors on the application and it just says "Something went wrong" instead of posting. I can post emojis but there is no record being maintained on the application.
meeepsss
meeepsss14mo ago
could you post your schema and the actual code which is failing?
lil_bixbyte
lil_bixbyte14mo ago
Here is the schema
lil_bixbyte
lil_bixbyte14mo ago
Here is the code if you don't want to download:
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
relationMode = "prisma"
}

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

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

content String @db.VarChar(255)
authorId String

@@index([authorId])
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
relationMode = "prisma"
}

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

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

content String @db.VarChar(255)
authorId String

@@index([authorId])
}
meeepsss
meeepsss14mo ago
could you wrap the code in ``` nvm that's all fine do you know the code which is failing
lil_bixbyte
lil_bixbyte14mo ago
As for what's failing, that is hard for me to determine. The following files have errors, but they all have to do with "Unsafe assignment of an any value" : 1. /src/pages/[slug].tsx 2. /src/pages/post/[id].tsx 3. /server/api/routers/posts.tsx 4. /components/postview.tsx 5. /server/api/helpers/filterUserForClients.ts 6. /server/api/helpers/ssgHelper.ts The error code that is being thrown is mentioned in the body of the original post. There is another error code that actually occurs when I post which I can add as well
meeepsss
meeepsss14mo ago
show me your posts.getAll query? yeah sure you shouldn't have all those TS errors btw. Using TS isn't going to help much if you don't type things :p
lil_bixbyte
lil_bixbyte14mo ago
Here is the error that I just got when posting an emoji:
prisma:query BEGIN
prisma:query INSERT INTO `trilldb`.`Post` (`id`,`createdAt`,`content`,`authorId`) VALUES (?,?,?,?)
prisma:query SELECT `trilldb`.`Post`.`id`, `trilldb`.`Post`.`createdAt`, `trilldb`.`Post`.`content`, `trilldb`.`Post`.`authorId` FROM `trilldb`.`Post` WHERE `trilldb`.`Post`.`id` = ? LIMIT ? OFFSET ?
prisma:query COMMIT
prisma:query SELECT `trilldb`.`Post`.`id`, `trilldb`.`Post`.`createdAt`, `trilldb`.`Post`.`content`, `trilldb`.`Post`.`authorId` FROM `trilldb`.`Post` WHERE 1=1 ORDER BY `trilldb`.`Post`.`createdAt` DESC LIMIT ? OFFSET ?
❌ tRPC failed on posts.getAll: Cannot read properties of undefined (reading 'users')
prisma:query SELECT 1
prisma:query SELECT `trilldb`.`Post`.`id`, `trilldb`.`Post`.`createdAt`, `trilldb`.`Post`.`content`, `trilldb`.`Post`.`authorId` FROM `trilldb`.`Post` WHERE 1=1 ORDER BY `trilldb`.`Post`.`createdAt` DESC LIMIT ? OFFSET ?
❌ tRPC failed on posts.getAll: Cannot read properties of undefined (reading 'users')
prisma:query SELECT `trilldb`.`Post`.`id`, `trilldb`.`Post`.`createdAt`, `trilldb`.`Post`.`content`, `trilldb`.`Post`.`authorId` FROM `trilldb`.`Post` WHERE 1=1 ORDER BY `trilldb`.`Post`.`createdAt` DESC LIMIT ? OFFSET ?
❌ tRPC failed on posts.getAll: Cannot read properties of undefined (reading 'users')
prisma:query SELECT `trilldb`.`Post`.`id`, `trilldb`.`Post`.`createdAt`, `trilldb`.`Post`.`content`, `trilldb`.`Post`.`authorId` FROM `trilldb`.`Post` WHERE 1=1 ORDER BY `trilldb`.`Post`.`createdAt` DESC LIMIT ? OFFSET ?
❌ tRPC failed on posts.getAll: Cannot read properties of undefined (reading 'users')
prisma:query BEGIN
prisma:query INSERT INTO `trilldb`.`Post` (`id`,`createdAt`,`content`,`authorId`) VALUES (?,?,?,?)
prisma:query SELECT `trilldb`.`Post`.`id`, `trilldb`.`Post`.`createdAt`, `trilldb`.`Post`.`content`, `trilldb`.`Post`.`authorId` FROM `trilldb`.`Post` WHERE `trilldb`.`Post`.`id` = ? LIMIT ? OFFSET ?
prisma:query COMMIT
prisma:query SELECT `trilldb`.`Post`.`id`, `trilldb`.`Post`.`createdAt`, `trilldb`.`Post`.`content`, `trilldb`.`Post`.`authorId` FROM `trilldb`.`Post` WHERE 1=1 ORDER BY `trilldb`.`Post`.`createdAt` DESC LIMIT ? OFFSET ?
❌ tRPC failed on posts.getAll: Cannot read properties of undefined (reading 'users')
prisma:query SELECT 1
prisma:query SELECT `trilldb`.`Post`.`id`, `trilldb`.`Post`.`createdAt`, `trilldb`.`Post`.`content`, `trilldb`.`Post`.`authorId` FROM `trilldb`.`Post` WHERE 1=1 ORDER BY `trilldb`.`Post`.`createdAt` DESC LIMIT ? OFFSET ?
❌ tRPC failed on posts.getAll: Cannot read properties of undefined (reading 'users')
prisma:query SELECT `trilldb`.`Post`.`id`, `trilldb`.`Post`.`createdAt`, `trilldb`.`Post`.`content`, `trilldb`.`Post`.`authorId` FROM `trilldb`.`Post` WHERE 1=1 ORDER BY `trilldb`.`Post`.`createdAt` DESC LIMIT ? OFFSET ?
❌ tRPC failed on posts.getAll: Cannot read properties of undefined (reading 'users')
prisma:query SELECT `trilldb`.`Post`.`id`, `trilldb`.`Post`.`createdAt`, `trilldb`.`Post`.`content`, `trilldb`.`Post`.`authorId` FROM `trilldb`.`Post` WHERE 1=1 ORDER BY `trilldb`.`Post`.`createdAt` DESC LIMIT ? OFFSET ?
❌ tRPC failed on posts.getAll: Cannot read properties of undefined (reading 'users')
meeepsss
meeepsss14mo ago
yeah there's no way to tell anything from that. It's just showing prisma's prepared statements are you sure the db is properly populated (check with prisma studio)? Otherwise, you're going to need to send some code ie posts.getAll for a start
lil_bixbyte
lil_bixbyte14mo ago
I'm running prisma studio, and the posts are all being recorded there
lil_bixbyte
lil_bixbyte14mo ago
lil_bixbyte
lil_bixbyte14mo ago
This is what I get on the app though:
lil_bixbyte
lil_bixbyte14mo ago
lil_bixbyte
lil_bixbyte14mo ago
I noticed there were a few things that were depracated that Theo was using in the video and I am super duper new to TS so a lot of this stuff goes way over my head. I figured this would just be a good way to throw myself into the deep end.. 😄 I really appreciate your help, meeps
Want results from more Discord servers?
Add your server