Skip to content

Commit fdd08ea

Browse files
committed
Formatting
1 parent 051cc53 commit fdd08ea

File tree

4 files changed

+52
-33
lines changed

4 files changed

+52
-33
lines changed

lib/absinthe/phoenix/channel.ex

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ defmodule Absinthe.Phoenix.Channel do
3737
socket =
3838
socket
3939
|> assign(:absinthe, absinthe_config)
40+
4041
{:ok, socket}
4142
end
4243

@@ -90,9 +91,10 @@ defmodule Absinthe.Phoenix.Channel do
9091
end
9192

9293
def handle_info(
93-
%Phoenix.Socket.Broadcast{payload: %{result: %{ordinal: ordinal}}} = msg,
94-
socket
95-
) when not is_nil(ordinal) do
94+
%Phoenix.Socket.Broadcast{payload: %{result: %{ordinal: ordinal}}} = msg,
95+
socket
96+
)
97+
when not is_nil(ordinal) do
9698
absinthe_assigns = Map.get(socket.assigns, :absinthe, %{})
9799
last_ordinal = absinthe_assigns[:subscription_ordinals][msg.topic]
98100

@@ -101,6 +103,7 @@ defmodule Absinthe.Phoenix.Channel do
101103
send_msg(msg, socket)
102104
socket = update_ordinal(socket, msg.topic, ordinal)
103105
{:noreply, socket}
106+
104107
true ->
105108
{:noreply, socket}
106109
end
@@ -118,12 +121,17 @@ defmodule Absinthe.Phoenix.Channel do
118121

119122
defp update_ordinal(socket, topic, ordinal) do
120123
absinthe_assigns = Map.get(socket, :absinthe, %{})
124+
121125
ordinals =
122126
absinthe_assigns
123127
|> Map.get(:subscription_ordinals, %{})
124128
|> Map.put(topic, ordinal)
125129

126-
Phoenix.Socket.assign(socket, :absinthe, Map.put(absinthe_assigns, :subscription_ordinals, ordinals))
130+
Phoenix.Socket.assign(
131+
socket,
132+
:absinthe,
133+
Map.put(absinthe_assigns, :subscription_ordinals, ordinals)
134+
)
127135
end
128136

129137
defp run_doc(socket, query, config, opts) do
@@ -154,6 +162,7 @@ defmodule Absinthe.Phoenix.Channel do
154162

155163
{:more, %{data: _} = reply, continuation, context} ->
156164
id = new_query_id()
165+
157166
socket =
158167
socket
159168
|> Absinthe.Phoenix.Socket.put_options(context: context)
@@ -172,17 +181,19 @@ defmodule Absinthe.Phoenix.Channel do
172181
case Absinthe.Pipeline.run(document, apply(module, fun, [schema, options])) do
173182
{:ok, %{result: %{continuation: continuation} = result, execution: res}, _phases} ->
174183
{:more, Map.delete(result, :continuation), continuation, res.context}
184+
175185
{:ok, %{result: result, execution: res}, _phases} ->
176186
{:ok, result, res.context}
187+
177188
{:error, msg, _phases} ->
178189
{:error, msg}
179190
end
180191
end
181192

182193
defp pubsub_subscribe(
183-
topic,
184-
%{transport_pid: transport_pid, serializer: serializer, pubsub_server: pubsub_server}
185-
) do
194+
topic,
195+
%{transport_pid: transport_pid, serializer: serializer, pubsub_server: pubsub_server}
196+
) do
186197
:ok =
187198
Phoenix.PubSub.subscribe(
188199
pubsub_server,
@@ -192,7 +203,6 @@ defmodule Absinthe.Phoenix.Channel do
192203
)
193204
end
194205

195-
196206
defp extract_variables(payload) do
197207
case Map.get(payload, "variables", %{}) do
198208
nil -> %{}
@@ -214,14 +224,17 @@ defmodule Absinthe.Phoenix.Channel do
214224
|> Map.delete(:continuation)
215225
|> add_query_id(id)
216226

217-
push socket, "doc", result
227+
push(socket, "doc", result)
218228
handle_continuation(socket, next_continuation, id)
229+
219230
{:ok, %{result: result}, _phases} ->
220-
push socket, "doc", add_query_id(result, id)
231+
push(socket, "doc", add_query_id(result, id))
232+
221233
{:ok, %{errors: errors}, _phases} ->
222-
push socket, "doc", add_query_id(%{errors: errors}, id)
234+
push(socket, "doc", add_query_id(%{errors: errors}, id))
235+
223236
{:error, msg, _phases} ->
224-
push socket, "doc", add_query_id(msg, id)
237+
push(socket, "doc", add_query_id(msg, id))
225238
end
226239
end
227240

@@ -241,12 +254,13 @@ defmodule Absinthe.Phoenix.Channel do
241254
end
242255

243256
defp push_subscription_item(data, topic, socket) do
244-
msg = %Phoenix.Socket.Broadcast{
245-
topic: topic,
246-
event: "subscription:data",
247-
payload: %{result: %{data: data}, subscriptionId: topic}
248-
}
249-
|> socket.serializer.fastlane!()
257+
msg =
258+
%Phoenix.Socket.Broadcast{
259+
topic: topic,
260+
event: "subscription:data",
261+
payload: %{result: %{data: data}, subscriptionId: topic}
262+
}
263+
|> socket.serializer.fastlane!()
250264

251265
send(socket.transport_pid, msg)
252266
end

mix.exs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ defmodule Absinthe.Phoenix.Mixfile do
5252
defp deps do
5353
[
5454
{:absinthe_plug, "~> 1.5"},
55-
#{:absinthe, "~> 1.5"},
56-
{:absinthe, github: "circles-learning-labs/absinthe", branch: "subscription-prime", override: true},
55+
# {:absinthe, "~> 1.5"},
56+
{:absinthe,
57+
github: "circles-learning-labs/absinthe", branch: "subscription-prime", override: true},
5758
{:decimal, "~> 1.0 or ~> 2.0"},
5859
{:phoenix, "~> 1.5"},
5960
{:phoenix_pubsub, "~> 2.0"},

test/absinthe/phoenix_test.exs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,28 +131,30 @@ defmodule Absinthe.PhoenixTest do
131131
end
132132

133133
test "subcription with prime", %{socket: socket} do
134-
ref = push socket, "doc", %{
135-
"query" => "subscription { prime }"
136-
}
137-
assert_reply ref, :ok, %{subscriptionId: subscription_ref}
134+
ref =
135+
push(socket, "doc", %{
136+
"query" => "subscription { prime }"
137+
})
138+
139+
assert_reply(ref, :ok, %{subscriptionId: subscription_ref})
138140

139-
assert_push "subscription:data", push
141+
assert_push("subscription:data", push)
140142
expected = %{result: %{data: %{"prime" => "prime1"}}, subscriptionId: subscription_ref}
141143
assert expected == push
142144

143-
assert_push "subscription:data", push
145+
assert_push("subscription:data", push)
144146
expected = %{result: %{data: %{"prime" => "prime2"}}, subscriptionId: subscription_ref}
145147
assert expected == push
146148
end
147149

148150
test "subscription with ordinal", %{socket: socket} do
149-
ref = push socket, "doc", %{"query" => "subscription { ordinal }"}
151+
ref = push(socket, "doc", %{"query" => "subscription { ordinal }"})
150152

151-
assert_reply ref, :ok, %{subscriptionId: subscription_ref}
153+
assert_reply(ref, :ok, %{subscriptionId: subscription_ref})
152154

153155
Absinthe.Subscription.publish(TestEndpoint, 1, ordinal: "ordinal_topic")
154156

155-
assert_push "subscription:data", push
157+
assert_push("subscription:data", push)
156158
expected = %{result: %{data: %{"ordinal" => 1}, ordinal: 1}, subscriptionId: subscription_ref}
157159
assert expected == push
158160

@@ -161,7 +163,7 @@ defmodule Absinthe.PhoenixTest do
161163

162164
Absinthe.Subscription.publish(TestEndpoint, 2, ordinal: "ordinal_topic")
163165

164-
assert_push "subscription:data", push
166+
assert_push("subscription:data", push)
165167
expected = %{result: %{data: %{"ordinal" => 2}, ordinal: 2}, subscriptionId: subscription_ref}
166168
assert expected == push
167169
end

test/support/schema.ex

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,11 @@ defmodule Schema do
100100

101101
field :prime, :string do
102102
config fn _, _ ->
103-
{:ok, topic: "prime_topic", prime: fn _ ->
104-
{:ok, ["prime1", "prime2"]}
105-
end}
103+
{:ok,
104+
topic: "prime_topic",
105+
prime: fn _ ->
106+
{:ok, ["prime1", "prime2"]}
107+
end}
106108
end
107109
end
108110

0 commit comments

Comments
 (0)