Mutation type issue
I'm trying to mutate something like this with tRPC and Prisma
list.id
is just a string but list.cards
has a type of Card[]
which I'm importing from a file Prisma auto-generated from my schema
Then on my backend
I tried putting something like z.array(z.object({}))
but obviously that doesn't work and it shows this error20 Replies
@Outis I can pinch in with what I'd do, but you either define the types manually, or you can use something like https://github.com/omar-dulaimi/prisma-zod-generator and then generate the zod schema based on the card
GitHub
GitHub - omar-dulaimi/prisma-zod-generator: Prisma 2+ generator to ...
Prisma 2+ generator to emit Zod schemas from your Prisma schema - GitHub - omar-dulaimi/prisma-zod-generator: Prisma 2+ generator to emit Zod schemas from your Prisma schema
But if the card is a simple type then just manually create it
This is really useful but my problem has evolved even further lol
My front end receives an array of objects and I just want to overwrite/update my previous array of objects inside my
cards
property
I've tried plenty of solutions, posted on the slack prisma help channel but nothing yet and I'm really contemplating if the switch to trcp/prisma is worth itWhat exactly is the issue that prevents you from updating the previous array?
I just don't understand the prisma update syntax for it
This is where I get to and I truly have tried so much stuff
You need to update all the cards?
Or you just need to update a single entity with the cards?
I simply want to update the order of the cards
So what I'm doing is reorder my cards in my front end and send it to my backend
Like this?
You would think it works like that but doesn't
Are you getting any errors or?
Yeah well it says that the type is invalid
Your
cards
you got from the frontend seems to be incorrect
Can you print typeof cards[0]?
This is the type
It's exactly the same, I don't it's a type issue
I think it has to do with how updating records works in Prisma when you also have relations
Yeah I'd say this is not related to
tRPC
but rather prisma, their error message is horrible so I cant decrypt much more from it
IS there any more info in the error?
Some more that was missing but I don't think it's of any use
I also tried something like this
But set only takes exactly one arguement, the id
Hopefully someone with more knowledge will be able to help out, I can only think that the type contained in the array
cards
is not appropriate but I dont understand their error message...Well I hope so too, appreciate the help
This is what I came up with
It works but it has to update each index individually
So every card is its own entity?
Its a bit different from the code you listed above
But if it works great, update me if someone on the prisma side replies
Yes it is, this is my schema
Are the cards in the column embedded or via a reference? Not sure how Prisma works or what driver youre using
Basically you can use a transaction and bulk insert all the cards and then update the column with the newly inserted cards
But I cant give you the exact implementation as I am not familiar with the technology unfortunately