I'm wondering how to do a self relation in a prope...
# prisma-whats-new
a
I'm wondering how to do a self relation in a proper way using prisma. For example making followers/following system. It can be something like that
Copy code
type User {
  id: ID! @unique
  followers: [User!]!
  following: [User!]!
}
But I believe that is not efficient or how prisma will deal with something like that? thanks in advance
a
You are on the right track! šŸ™‚ I would add relation names though:
Copy code
followers: [User!]! @relation(name: "UserFollowers")
  follows: [User!]! @relation(name: "UserFollows")
and you have to update to
prisma@beta
. There was a problem with self-relations: https://github.com/graphcool/prisma/issues/1609
Also, this issue provides an example how the actual
follow
and
unfollow
mutation can look like.
a
Thanks @andre I'll take a look
a
Sure thing šŸ™‚ You're welcome.
a
I tried what you did in the comments but it still doesn't work. what I did .. - add relation names -
npm i -g prisma@beta
and
prisma local upgrade
-
prisma deploy
Now updateUser follower working but updateUser following not working
prisma version
->
prisma/1.3.0-beta.1 (darwin-x64) node-v8.4.0
prisma vluster list
->
Copy code
name        version     endpoint
──────────  ──────────  ─────────────────────────────
local       1.3-beta-9  <http://localhost:4466/cluster>
prisma-eu1  1.2.3       <https://eu1.prisma.sh/cluster>
prisma-us1  1.2.3       <https://us1.prisma.sh/cluster>
and I'm using local cluster
a
Do you get an error message?
a
Yes, Internal server error with request id
It works fine now Here's what I did. - I went to mysql docker containers and checked the tables and for some reasons I don't know the table that represents the relation UserFollowing wasn't exist - Tried to deploy again and that didn't help. - Tried to remove the cluster and init again and didn't help too. - Tried to kill the containers and remove them and deploy again and that didn't help - Finally I changed the service name in
prisma.yml
and that creates everything from scratch and it worked Anyway, thank you very much @andre for following up with me
šŸ‘ 1
fast parrot 1