@@ -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
0 commit comments