Absinthe.GraphqlWS.Socket behaviour (AbsintehGrahqlWS v0.1.0) View Source
This module is used by a custom websocket, which can then handle connections from a client implementing the GraphQL over WebSocket protocol
Options
schema
- required - The Absinthe schema for the current application (example:MyAppWeb.Schema
)keepalive
- optional - Interval in milliseconds to send:ping
control frames over the websocket. Defaults to30_000
(30 seconds).pipeline
- optional - A{module, function}
tuple defining how to generate an Absinthe pipeline for each incoming message. Defaults to{Absinthe.GraphqlWS.Socket, :absinthe_pipeline}
.
Example
defmodule MyAppWeb.GraphqlSocket do
use Absinthe.GraphqlWS.Socket, schema: MyAppWeb.Schema
def handle_message(_msg, socket) do
{:ok, socket}
end
end
Link to this section Summary
Types
Opcode atoms for messages handled by handle_control/2
. Used by server-side keepalive messages.
Opcode atoms for messages returned by handle_in/2
.
Valid replies from Absinthe.GraphqlWS.Transport.handle_in/2
Valid replies from handle_message/2
A socket that holds information necessary for parsing incoming messages as well as outgoing subscription data.
Functions
Provides a stub implementation that allows the socket to start. Phoenix.Socket.Transport expects a child spec that starts a process, so we do so with a noop Task.
When a client connects to this websocket, this function is called to initialize the socket.
Provides the default absinthe pipeline
Link to this section Types
Specs
control() :: :ping | :pong
Opcode atoms for messages handled by handle_control/2
. Used by server-side keepalive messages.
Specs
opcode() :: :text | :binary | control()
Opcode atoms for messages returned by handle_in/2
.
Specs
reply() :: {:ok, t()} | {:reply, :ok, {opcode(), term()}, t()} | {:reply, :error, {opcode(), term()}, t()} | {:stop, term(), t()}
Valid replies from Absinthe.GraphqlWS.Transport.handle_in/2
Specs
Valid replies from handle_message/2
Specs
t() :: %Absinthe.GraphqlWS.Socket{ absinthe: map(), assigns: map(), connect_info: map(), endpoint: module(), handler: term(), keepalive: integer(), pubsub: term(), subscriptions: map() }
A socket that holds information necessary for parsing incoming messages as well as outgoing subscription data.
Link to this section Functions
Provides a stub implementation that allows the socket to start. Phoenix.Socket.Transport expects a child spec that starts a process, so we do so with a noop Task.
When a client connects to this websocket, this function is called to initialize the socket.
Provides the default absinthe pipeline
Link to this section Callbacks
Specs
Handles messages that are sent to this process through send/2
, which have not been caught
by the default implementation.
Example
def handle_message({:thing, thing}, socket) do
{:ok, assign(socket, :thing, thing)}
end
def handle_message(_msg, socket) do
{:ok, socket}
end