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
Link to this section Functions
Specs
put_options(Phoenix.Socket.t(), Absinthe.run_opts()) :: Phoenix.Socket.t()
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
Specs
put_schema(Phoenix.Socket.t(), Absinthe.Schema.t()) :: Phoenix.Socket.t()
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.