Subscription Type

Subscription is the entry point for all subscriptions in a GraphQL system. Each field corresponds to an event which may be subscribed to:

type Subscription {
  # Triggered whenever a post is added
  postWasPublished: Post
  # Triggered whenever a comment is added;
  # to watch a certain post, provide a `postId`
  commentWasPublished(postId: ID): Comment

This type is the root for subscription operations, for example:

subscription {
  postWasPublished {
    # This data will be delivered whenever `postWasPublished`
    # is triggered by the server:
    author {

To add subscriptions to your system, define an ObjectType named Subscription:

# app/graphql/types/subscription_type.rb
Types::SubscriptionType = GraphQL::ObjectType.define do
  name "Subscription"
  field :postWasPublished, !Types::PostType, "A post was published to the blog"
  # ...

Then, add it as the subscription root with subscription(...):

# app/graphql/my_schema.rb
MySchema = GraphQL::Schema.define do
  # ...
  # Add Subscription to

See Implementing Subscriptions for more about actually delivering updates.