Skip to content

Commit

Permalink
Merge pull request #381 from stephendeyoung/master
Browse files Browse the repository at this point in the history
Update documentation with invoke streamer example
  • Loading branch information
hlship committed Nov 1, 2021
2 parents 015b51b + 7ceb8d4 commit 56637d4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/_examples/invoke-streamer.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(require
'[com.walmartlabs.lacinia.executor :as executor]
[com.walmartlabs.lacinia.parser :as parser]
[com.walmartlabs.lacinia.constants :as constants])

(let [prepared-query (-> schema
(parser/parse-query query)
(parser/prepare-with-query-variables variables))
source-stream-callback (fn [data]
;; Do something with the data
;; e.g. send it to a websocket client
)
cleanup-fn (executor/invoke-streamer
{constants/parsed-query-key prepared-query} source-stream-callback)]
;; Do something with the cleanup-fn e.g. call it when a websocket connection is closed
)
13 changes: 13 additions & 0 deletions docs/subscriptions/streamer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ until ``nil`` is passed to the source stream callback.

In either case, the cleanup callback will then be invoked.

Invoking the streamer
---------------------

The streamer must be invoked with the parsed query and source stream callback in order to setup the
subscription using :api:`executor/invoke-streamer`.

.. literalinclude:: ../_examples/invoke-streamer.edn
:language: clojure

Typically subscriptions are used with websockets so this example could be adapted to receive a message
with a query and variables from a connected websocket client. Then any messages received by the source
stream callback can be pushed to the client.

Timing
------

Expand Down

0 comments on commit 56637d4

Please sign in to comment.