An interesting feature of GraphQL (to me) is the real-time subscriptions against a dataset. It's relatively pain free to add (assuming you've managed to get everything else configured!).

The problem I recently faced was authentication over subscriptions, and how to ensure the user connected via a web socket was authenticated or not. When I eventually solved it, there were a number of specific code changes that I figured would be useful to catalogue and record here.

Tech stack

In my particular case I'm using the following tech stack though this post should be useful if you're not using all the same parts:

The changes are split across the backend GraphQL server and the client code (which in the case of Next.js is frontend and backend in the form of SSR).

  • [SSR]: server side rendering

Drafts may be incomplete or entirely abandoned, so please forgive me. If you find an issue with a draft, or would like to see me write about something specifically, please try raising an issue.