Absinthe.Phoenix.Socket (absinthe_phoenix v2.0.2) View Source

Absinthe.Phoenix.Socket is used as a module for setting up a control channel for handling GraphQL subscriptions.

Examples

defmodule MyApp.Web.UserSocket do
  use Phoenix.Socket
  use Absinthe.Phoenix.Socket,
    schema: MyApp.Web.Schema

  transport :websocket, Phoenix.Transports.WebSocket

  def connect(params, socket) do
    socket = Absinthe.Phoenix.Socket.put_options(socket, [
      context: %{current_user: find_current_user(params)}
    ])
    {:ok, socket}
  end

  def id(_socket), do: nil
end

Phoenix 1.2

If you're on Phoenix 1.2 see put_schema/2.

Link to this section Summary

Functions

Configure Absinthe options for a socket.

Configure the schema for a socket.

Link to this section Functions

Link to this function

put_options(socket, opts)

View Source

Specs

Configure Absinthe options for a socket.

Examples

def connect(params, socket) do
  current_user = current_user(params)
  socket = Absinthe.Phoenix.Socket.put_options(socket, context: %{
    current_user: current_user
  })
  {:ok, socket}
end

defp current_user(%{"user_id" => id}) do
  MyApp.Repo.get(User, id)
end
Link to this function

put_schema(socket, schema)

View Source

Specs

Configure the schema for a socket.

Only use this if you are not yet on Phoenix 1.3. If you're on Phoenix 1.3, read the moduledocs.