Class: GraphQL::Streaming::ActionCableCollector
- Inherits:
-
Object
- Object
- GraphQL::Streaming::ActionCableCollector
- Defined in:
- lib/graphql/streaming/action_cable_collector.rb
Overview
Accept patches from GraphQL and send them to clients via ‘channel_name`.
Patches are also issued with ‘query_id`. This way, clients on the same channel can tell whether a patch is for their query or someone else’s.
When a query is finished (no more patches will be sent), the collector can notify clients with #close
Instance Method Summary collapse
-
#close ⇒ void
Broadcast a message to terminate listeners on this query.
-
#initialize(channel, query_id) ⇒ ActionCableCollector
constructor
A new instance of ActionCableCollector.
-
#patch(path:, value:) ⇒ void
Implements the “collector” API for DeferredExecution.
Constructor Details
#initialize(channel, query_id) ⇒ ActionCableCollector
Returns a new instance of ActionCableCollector.
41 42 43 44 45 |
# File 'lib/graphql/streaming/action_cable_collector.rb', line 41 def initialize(channel, query_id) @query_id = query_id @channel = channel @closed = false end |
Instance Method Details
#close ⇒ void
This method returns an undefined value.
Broadcast a message to terminate listeners on this query
64 65 66 67 68 69 70 |
# File 'lib/graphql/streaming/action_cable_collector.rb', line 64 def close @channel.send_graphql_payload({ query_id: @query_id, close: true, }) @closed = true end |
#patch(path:, value:) ⇒ void
This method returns an undefined value.
Implements the “collector” API for DeferredExecution. Sends ‘{…, query_id: @query_id}` over `@broadcaster`.
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/graphql/streaming/action_cable_collector.rb', line 50 def patch(path:, value:) if !@closed @channel.send_graphql_payload({ query_id: @query_id, patch: { path: path, value: value, }, }) end end |