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?
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 });
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.