Hey folks! I’ve a `Event` that has many `Comment` ...
# prisma-whats-new
n
Hey folks! I’ve a
Event
that has many
Comment
types. I’m trying to create a subscription for new comments. How would I do this?
Copy code
subscription {
  Event(filter:{
    mutation_in: [CREATED],
    
  }) {
    node {
      comments {
        id
        message
        createdAt
      }
    }
  }
}
Is as far as I got, I couldn’t figure out the way to set the eventId
Copy code
node:{
      id:"$eventId"
    }
Do the trick? Am I missing something?
n
you can subscribe to `Comment`s being created where the
eventId
is
$eventId
this assumes that you run the mutation like this:
createComment(text: "" eventId: "event-id")
@notrab
n
Hey @nilan
Copy code
subscription {
  Comment(filter:{
    mutation_in: [CREATED],
    eventId:$eventId
  }){
    node {
      id
      message
      createdAt
    }
  }
}
Like this?
n
Copy code
subscription {
  Comment(filter:{
    mutation_in: [CREATED],
    node: {
      eventId:$eventId
    }
  }){
    node {
      id
      message
      createdAt
    }
  }
}
you can use the Playground to get autocompletion for subscriptions, too 🙂
n
Ah, I was close
Ok
n
👍
n
I am getting an error @nilan 😮
Copy code
"message": "Argument 'filter' expected type 'CommentSubscriptionFilter' but got: {mutation_in: [CREATED], node: {eventId: \"cj2j9wmph9d080196fc20wa4c\"}}. Reason: [in field 'node'] Unknown field 'eventId' is not defined in the input type 'CommentSubscriptionFilterNode'. (line 5, column 7):\n      eventId:\"cj2j9wmph9d080196fc20wa4c\"\n      ^ (line 2, column 18):\n  Comment(filter:{\n                 ^\n (line 5, column 7):\n      eventId:\"cj2j9wmph9d080196fc20wa4c\"\n      ^"
eventId
unknown
Comment Type
Copy code
type Comment implements Node {
  createdAt: DateTime!
  event: Event @relation(name: "EventOnComment")
  id: ID! @isUnique
  message: String
  updatedAt: DateTime!
  user: User @relation(name: "CommentOnUser")
}
n
how's the relation field on
Comment
called that connects to the `Event `type?
oh
I'm sorry
n
Event has many Comments
n
Copy code
subscription {
  Comment(filter:{
    mutation_in: [CREATED],
    node: {
      event: {
        id: $eventId
      }
    }
  }){
    node {
      id
      message
      createdAt
    }
  }
}
n
You are a legend.
n
this should work 🙂 note the additional
event
wrapper
n
⭐