Class: GraphQL::Streaming::StreamCollector
- Inherits:
-
Object
- Object
- GraphQL::Streaming::StreamCollector
- Defined in:
- lib/graphql/streaming/stream_collector.rb
Overview
Send patches by calling ‘stream.write` Each patch is serialized as JSON and delimited with “nn”
Constant Summary collapse
- DELIMITER =
"\n\n"
Instance Method Summary collapse
-
#initialize(stream) ⇒ StreamCollector
constructor
A new instance of StreamCollector.
-
#patch(path:, value:) ⇒ Object
Implement the collector API for DeferredExecution.
Constructor Details
#initialize(stream) ⇒ StreamCollector
Returns a new instance of StreamCollector.
26 27 28 29 |
# File 'lib/graphql/streaming/stream_collector.rb', line 26 def initialize(stream) @stream = stream @first_patch = true end |
Instance Method Details
#patch(path:, value:) ⇒ Object
Implement the collector API for DeferredExecution
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/graphql/streaming/stream_collector.rb', line 32 def patch(path:, value:) patch_string = JSON.dump({path: path, value: value}) if @first_patch @first_patch = false @stream.write(patch_string) else @stream.write(DELIMITER + patch_string) end end |