absinthe_phoenix v1.4.0-rc.2 Absinthe.Phoenix.Socket
Absinthe.Phoenix.Socket
is used as a module for setting up a control
channel for handling GraphQL subscriptions.
Example
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_opts(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
Link to this function
put_opts(socket, opts)
put_opts(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_opts(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)
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.