Make web real-time with GraphQL subscriptions

Make web real-time with GraphQL subscriptions

Written by arvind pal | Published a year ago

A lot of times we like to provide our users with some real-time features. Consider this simple scenario:

You are making an Instagram web clone.

People start following each other and when one publishes a photo, all people following that user will be notified and will see the photo in their browsers if they have it open. There won’t be any need for a hard reload of the page.

How should we implement that?


SubscriptionType = GraphQL::ObjectType.define do
  name 'Subscription'
  field :feedItemAdded, PhotoType,
        'A photo is added' do
    subscription_scope :current_user_uuid
  end
end


Subscriptions in GraphQL

Subscriptions allow GraphQL clients to observe specific events and receive updates from the server when those events occur. This supports live updates, such as WebSocket pushes. Subscriptions introduce several new concepts:


  • Subscription Type
  • Triggers
  • Implementation


RELATED BLOGS