View Source Absinthe.GraphqlWS.Util (AbsintheGrahqlWS v0.3.6)
Helper functions that are imported into a module using Absinthe.GraphqlWS.Socket
.
Link to this section Summary
Functions
Implementation copied from Phoenix.Socket
, but changed to match on a Absinthe.GraphqlWS.Socket
struct.
Adds key-value pairs into Absinthe context. This can be used in the Absinthe.GraphqlWS.Socket.handle_init/2
to assign keys/values to the current Absinthe context.
Same as assign_context/2
except one key-value pair is assigned.
Retrieves the JSON library module used to encode and decode transport messages
Sets the options for a given GraphQL document execution.
Link to this section Functions
@spec assign(Absinthe.GraphqlWS.Socket.t(), map() | keyword()) :: Absinthe.GraphqlWS.Socket.t()
@spec assign(Absinthe.GraphqlWS.Socket.t(), atom(), term()) :: Absinthe.GraphqlWS.Socket.t()
Implementation copied from Phoenix.Socket
, but changed to match on a Absinthe.GraphqlWS.Socket
struct.
Adds key-value pairs into Absinthe context. This can be used in the Absinthe.GraphqlWS.Socket.handle_init/2
to assign keys/values to the current Absinthe context.
examples
Examples
defmodule MySocket do
use Absinthe.GraphqlWS.Socket, schema: MySchema
def handle_init(%{"user_id" => user_id}) do
user = find_user(user_id)
socket = assign_context(socket, current_user: user)
%{:reply, :ok, {:text, Absinthe.GraphqlWS.Message.ConnectionAck.new()}, socket}
end
end
Same as assign_context/2
except one key-value pair is assigned.
Retrieves the JSON library module used to encode and decode transport messages
Sets the options for a given GraphQL document execution.
examples
Examples
iex> put_options(socket, context: %{current_user: user})
%Socket{}