How do I notify the subscribed clients of the new change of the database (Mongodb) from Node.js App ? I know it works when a client commit a mutation, but is there a way to do it on the server?
Asked
Active
Viewed 112 times
1 Answers
0
See the documentation for the Apollo Subscriptions: "To generate events in the example, we notified the pubsub implementation inside of our Mutation resolver with publish. This publish call can occur outside of a resolver if required."
So every time your server code needs to publish updates to the client, it should call the publish() method:
pubsub.publish(POST_ADDED, { postAdded: args });

aminits
- 174
- 4
-
Hi. Thank you ! I want sometime notify the changes from another server .Do I have to create new API or Use the Apollo client on Node.js server – Bright Chip Oct 31 '20 at 11:07
-
If it is another server, then you will need new API - and use publish() there. – aminits Oct 31 '20 at 13:33