Absinthe.GraphqlWS.Socket.handle_init
You're seeing just the callback
handle_init
, go back to Absinthe.GraphqlWS.Socket module for more information.
Specs
Handle the connection_init
message sent by the socket implementation. This will receive
the payload
from the message, defaulting to an empty map if received from the client.
This can be used for custom authentication/authorization, using
Absinthe.GraphqlWS.Util.assign_context/2
to modify the Absinthe context.
Example
defmodule MySocket do
use Absinthe.GraphqlWS.Socket, schema: MySchema
def handle_init(%{"user_id" => user_id}) do
case find_user(user_id) do
nil ->
{:error, %{}, socket}
user ->
socket = assign_context(socket, current_user: user)
{:ok, %{name: user.name}, socket}
end
end
end