Search code examples
node.jsreactjsexpresstwilioapollo

How to refresh a React component after a request to backend Node app?


I have an application composed of:

  • React frontend
  • Node JS + Express backend
  • Mongo DB

Backend and frontend communicates mainly through Apollo GraphQL. Recently I began using Twilio for making calls. After a call, Twilio sends a backend request to my node JS app to a specific route, which is then modyfing a document in Mongo. The request is totally independent of the frontend and can come anytime.

How can I update the React component - a form displaying mentioned document, after that backend request (the displayed data should change accoridng to backend version)? I am thinking about websockets and/or Apollo subscriptions, but maybe there is some easier way?


Solution

  • Twilio developer evangelist here.

    You are looking for a way to push data from your server to your front end. Web sockets is probably the best solution for you, and since you are already using Apollo, and Apollo Subscriptions are commonly implemented over web sockets, then that is probably a good solution for you.