Hey, seems like my subscription not receiving noti...
# prisma-whats-new
c
Hey, seems like my subscription not receiving notifications for UPDATED mutation type. It does receive CREATED and DELETED mutations though. I am checking in playground. @nilan i will be waiting for your response on monday 😉
n
@checkmatez hey! 🙂 This seems like a bug on our end, I created this issue: https://github.com/graphcool/api-bugs/issues/66 Please add if you have more information 🙂
c
Hi! Glad you are back here after conference 🙂 Does SSS stands for server side subscriptions? I actually meant regular subscriptions. So, this is my schema: http://prntscr.com/fb36ue Basically i want to build 2 player multiplayer tic-tac-toe game. So when first pIayer press "Search for an opponent" i send CREATE lobby node payload, and i want to subscribe to event UPDATE on that node. So, when second player presses "Search..." i can find that node with just 1 player and update it, to trigger a subscription to the first player. Im not sure if thats the right approach so feel free to suggest another one 🙂 Anyway, when im testing subscription in playground using this subscription: http://prntscr.com/fb39nu i dont receive UPDATE notifications. I can create new lobby node in "data" panel in console and see this event in subscription. But when i try to update field "Player2" on that node through "data" panel or using mutation in playground, i dont receive notification. I hope i explained it well 🙂
ping @nilan
n
ahhh I see! Yes, SSS stands for server-side subscription, sorry for the mix up 😄
currently, subscriptions are not triggered on relation updates - you can add the player2 and afterwards update a dummy field on the node
would that work for you?
c
Dummy field means some scalar value? Can i do it in one mutation?
n
how are you adding the player2?
yes, some scalar field 🙂
c
Copy code
mutation joinExistingLobby($lobbyId: ID!, $playerId: ID!) {
    updateLobby(id: $lobbyId, player2Id: $playerId) {
      id
      updatedAt
      player1 {
        id
        email
      }
      player2 {
        id
        email
      }
    }
  }
n
Copy code
mutation joinExistingLobby($lobbyId: ID!, $playerId: ID!) {
   updateLobby(id: $lobbyId, player2Id: $playerId, dummy: "dummy") {
     id
     updatedAt
     player1 {
       id
       email
     }
     player2 {
       id
       email
     }
   }
 }
for example 🙂
c
Gotcha 🙂 I try this, thanks!
Can i bother you with one more question?
n
that was already one question! 😛
going to lunch, will have a look later
c
Okay, i ask anyway 🙂
n
of course 🙂
c
So, in my game i imagine that when player makes a move i send Mutation to the server. But in order to prevent "hacks" i need to validate that player is allowed to make that move (square is empty for example). So, i guess i should make that validation with Function on trigger Pipeline - PreWrite. In that function i have to first make a query to get what squares are currently empty and then check if passed move is allowed. Does that make sense? 🙂
Also, do i have to pass whole set of moves in mutation from client, when i really only need the current move that is being made?
n
ok a question for clarification - all your player moves are distinct steps, correct?
so there are not two players for the same game that can make a move at the same time?
ping @checkmatez - man Slack threads are weird 😅
c
@nilan Yeah, moves are distinct, you can't move at the same. I was away, at the interview for my first job as web dev 😅
n
Ohhh nice! Hope it all went well
So because your moves are distinct, it's a great use case for what you suggest
it would be a bit more complicated if many players can do actions in parallel
c
@nilan thx a lot 🙂 I'll try to set up validation with Functions. What about the need to send an array of all moves, when i really need only one last move 🙂 ? I mean in schema my moves are just field with array of integers, and to do UPDATE mutation i have to send an entire array. Is it correct?
n
oh, yes that's correct! sorry, did not see your reply 😕
what about if you make a
Move
type? Then instead of checking
update
you check
createMove
and see if it is valid