Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING!: Change default Error payload parameter and add ability to close #25

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/absinthe/graphql_ws/socket.ex
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ defmodule Absinthe.GraphqlWS.Socket do
"""
@type init() ::
{:ok, map(), socket()}
| {:error, {String.t(), map()}, socket()}
| {:error, map(), socket()}
| {:close, {number(), String.t()}, socket()}
| {:stop, term(), socket()}

@doc """
Expand Down
10 changes: 8 additions & 2 deletions lib/absinthe/graphql_ws/transport.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule Absinthe.GraphqlWS.Transport do
their codebase, but is documented to help understand the intentions of the code.
"""

alias Absinthe.GraphqlWS.{Message, Socket, Util}
alias Absinthe.GraphqlWS.{Message, Socket, Util, Uuid}
alias Phoenix.Socket.Broadcast
require Logger

Expand Down Expand Up @@ -126,8 +126,14 @@ defmodule Absinthe.GraphqlWS.Transport do
{:ok, payload, socket} ->
{:reply, :ok, {:text, Message.ConnectionAck.new(payload)}, %{socket | initialized?: true}}

{:error, {id, payload}, socket} ->
{:reply, :ok, {:text, Message.Error.new(id, payload)}, socket}

{:error, payload, socket} ->
{:reply, :ok, {:text, Message.Error.new(payload)}, socket}
{:reply, :ok, {:text, Message.Error.new(Uuid.generate(), payload)}, socket}

{:close, {status, message}, socket} ->
close(status, message, socket)
end
else
{:reply, :ok, {:text, Message.ConnectionAck.new()}, %{socket | initialized?: true}}
Expand Down