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

Link to this function

assign(socket, key, value)

View Source

Implementation copied from Phoenix.Socket, but changed to match on a Absinthe.GraphqlWS.Socket struct.

Link to this function

assign_context(socket, context)

View Source

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
Link to this function

assign_context(socket, key, value)

View Source

Same as assign_context/2 except one key-value pair is assigned.

Retrieves the JSON library module used to encode and decode transport messages

Link to this function

put_options(socket, opts)

View Source

Sets the options for a given GraphQL document execution.

examples

Examples

iex> put_options(socket, context: %{current_user: user})
%Socket{}