class GraphQL::Subscription

Overview

A running subscription, returned by Schema#subscribe. Every event the resolver's channel produces arrives as one response document.

subscription = schema.subscribe(%(subscription { messageAdded { text } }))
subscription.each { |response| socket.send(response) }

The stream ends when the resolver's channel closes. #close ends it from the consumer side and closes the resolver's channel too, so the application learns the subscriber is gone.

Defined in:

graphql/subscription.cr

Instance Method Summary

Instance Method Detail

def close : Nil #

Unsubscribes: closes the resolver's channel and the response stream.


def closed? : Bool #

def each(& : String -> ) : Nil #

Yields every response until the stream ends.


def receive : String #

Next response. Raises Channel::ClosedError once the stream has ended.


def receive? : String | Nil #

Next response, or nil once the stream has ended.


def responses : Channel(String) #

The raw response channel, for use in select.