@@ -6,46 +6,53 @@ defmodule Absinthe.Phase.Subscription.Result do
6
6
7
7
alias Absinthe.Blueprint
8
8
alias Absinthe.Blueprint.Continuation
9
+ alias Absinthe.Phase
9
10
10
11
@ spec run ( any , Keyword . t ( ) ) :: { :ok , Blueprint . t ( ) }
11
12
def run ( blueprint , options ) do
12
- topic = Keyword . get ( options , :topic )
13
+ topic = Keyword . fetch! ( options , :topic )
13
14
prime = Keyword . get ( options , :prime )
14
15
result = % { "subscribed" => topic }
16
+
15
17
case prime do
16
18
nil ->
17
19
{ :ok , put_in ( blueprint . result , result ) }
18
20
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 )
42
23
43
24
val ->
44
25
raise """
45
- Invalid prime function. Must be a function of arity 0 .
26
+ Invalid prime function. Must be a function of arity 1 .
46
27
47
28
#{ inspect ( val ) }
48
29
"""
49
30
end
50
31
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
51
58
end
0 commit comments