1. Setting up GraphQL Subscriptions in Drupal
Hey, GraphQL Galaxy. In this Lightning Talk, I want to take you through what it took to set up GraphQL subscriptions for an existing Drupal-based product. I'm Alexander Farweg or Kingdutch on places like Twitter and GitHub, and I'm the Lead Frontend Engineer and GraphQL Initiative Lead at OpenSocial.
OpenSocial is a community engagement platform that helps organizations connect with their communities online and grow them in the process. OpenSocial is built on top of the Drupal content management framework. To allow quicker communication between members on our platforms, we wanted to use GraphQL to add a real-time chat as a new feature to our existing products. The goal was for the chat to integrate with our existing member and group structure. To build our chats, we chose Rescript and React. And of course, GraphQL to let our server and client communicate. On the client side, we chose the excellent Urql GraphQL client.
2. Choosing ReactPHP for Subscription Service
Since OpenSocial's back-end developers are most familiar with PHP, we decided to use it for our subscription service. ReactPHP was chosen over AMP for its syntax and the introduction of Fibers in PHP 8.1. This allowed us to create a long-running PHP process and perform tasks asynchronously.
Or I would risk having to maintain it all by myself. With this in mind, since OpenSocial's back-end developers are most familiar with PHP, we decided to use this for our subscription service too. This does mean that we need some new tools. We now need something that can create a long-running PHP process, and perform tasks asynchronously. There are a few libraries out there already that can help us with this. ReactPHP and AMP are both capable libraries that let you write asynchronous code. The biggest difference is what syntax they use for their promises. Fun fact, the PHP extension for an event loop that both ReactPHP and AMP use actually predates Node.js. More recently, ReactPHP and AMP have bundled their forces to build Revolt, which will make use of Fibers, a feature that has been introduced in PHP 8.1. At OpenSocial, we settled on ReactPHP after trying both it and AMP.