@@ -6,46 +6,53 @@ defmodule Absinthe.Phase.Subscription.Result do
66
77 alias Absinthe.Blueprint
88 alias Absinthe.Blueprint.Continuation
9+ alias Absinthe.Phase
910
1011 @ spec run ( any , Keyword . t ( ) ) :: { :ok , Blueprint . t ( ) }
1112 def run ( blueprint , options ) do
12- topic = Keyword . get ( options , :topic )
13+ topic = Keyword . fetch! ( options , :topic )
1314 prime = Keyword . get ( options , :prime )
1415 result = % { "subscribed" => topic }
16+
1517 case prime do
1618 nil ->
1719 { :ok , put_in ( blueprint . result , result ) }
1820
19- prime_fun when is_function ( prime_fun , 0 ) ->
20- { :ok , prime_results } = prime_fun . ( )
21-
22- result =
23- if prime_results != [ ] do
24- continuations =
25- Enum . map ( prime_results , fn cr ->
26- % Continuation {
27- phase_input: blueprint ,
28- pipeline: [
29- { Absinthe.Phase.Subscription.Prime , [ prime_result: cr ] } ,
30- { Absinthe.Phase.Document.Execution.Resolution , options } ,
31- Absinthe.Phase.Document.Result
32- ]
33- }
34- end )
35-
36- Map . put ( result , :continuation , continuations )
37- else
38- result
39- end
40-
41- { :ok , put_in ( blueprint . result , result ) }
21+ prime_fun when is_function ( prime_fun , 1 ) ->
22+ do_prime ( prime_fun , result , blueprint , options )
4223
4324 val ->
4425 raise """
45- Invalid prime function. Must be a function of arity 0 .
26+ Invalid prime function. Must be a function of arity 1 .
4627
4728 #{ inspect ( val ) }
4829 """
4930 end
5031 end
32+
33+ def do_prime ( prime_fun , base_result , blueprint , options ) do
34+ { :ok , prime_results } = prime_fun . ( blueprint . execution )
35+
36+ result =
37+ if prime_results != [ ] do
38+ continuations =
39+ Enum . map ( prime_results , fn cr ->
40+ % Continuation {
41+ phase_input: blueprint ,
42+ pipeline: [
43+ { Phase.Subscription.Prime , [ prime_result: cr ] } ,
44+ { Phase.Document.Execution.Resolution , options } ,
45+ Phase.Subscription.GetOrdinal ,
46+ Phase.Document.Result
47+ ]
48+ }
49+ end )
50+
51+ Map . put ( base_result , :continuation , continuations )
52+ else
53+ base_result
54+ end
55+
56+ { :ok , put_in ( blueprint . result , result ) }
57+ end
5158end
0 commit comments