Validation before topics subscription #946
-
now I want to make subscription for post comments, so I take a postId and publish every comment is written on it to the subscribed clients, the problem is I want to do some validation to ensure that the post the user want to subscribe to its comments exists. So I read all of the docs on TypeGraphQL Subscriptions, and wrote my first subscription and it works so well, but the problem I wanna throw an error to the client if the post doesn't exist for the provided postId, 1- I tried in the topics function to find the post if it exists return the topic if not throw an error but the problem is it crashes the whole server and don't send any error to the requested client. 2- then I already have a
so how can I run a validation to make sure that post exists before subscribing, and throw an error to the client if the post doesn't exist. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Use Note that you need to call |
Beta Was this translation helpful? Give feedback.
Use
subscribe
option of@Subscription
decorator to perform custom operations and actions during the subscribe phase.Note that you need to call
pubSub
with filters and topics manually.