SubscriptionsTransportWS.SocketTest.push_doc
You're seeing just the function
push_doc
, go back to SubscriptionsTransportWS.SocketTest module for more information.
Specs
push_doc( socket :: SubscriptionsTransportWS.Socket.t(), document :: String.t(), opts :: [{:variables, map()}] ) :: {:ok, SubscriptionsTransportWS.Socket.t()} | {:ok, result :: map(), SubscriptionsTransportWS.Socket.t()}
Helper function to push a GraphQL document to a socket.
The only option that is used is opts[:variables]
- all other options are
ignored.
When you push a query/mutation it will return with {:ok, result, socket}
. For
subscriptions it will return an {:ok, socket}
tuple.
Example of synchronous response
# Push query over socket and receive response
push_doc(socket, "query {
posts {
id
body
}
}", variables: %{limit: 10})
{:ok, %{"data" => %{"posts" => [%{"body" => "body1", "id" => "aa"}]}}, _socket}
Example of asynchronous response
# Subscribe to subscription
push_doc(socket, "subscription {
postAdded{
id
body
title
}
}", variables: %{})
# The submitPost mutation triggers the postAdded subscription publication
push_doc(socket, "mutation submitPost($title: String, $body: String){
submitPost(title: $title, body: $body){
id
body
title
}
}", variables: %{title: "test title", body: "test body"})
assert_receive_subscription(%{
"data" => %{
"postAdded" => %{"body" => "test body", "id" => "1", "title" => "test title"}
}
})