11defmodule Console.GraphQl.Resolvers.Plural do
22 use Nebulex.Caching
33 alias Console.Plural . { Repositories , ExternalToken }
4- alias Console.Plural . { Connection , PageInfo }
4+ alias Console.Plural . { Connection , PageInfo , Stack }
55 alias Console.Services.Plural
66 alias Kube.Client
77
@@ -28,13 +28,22 @@ defmodule Console.GraphQl.Resolvers.Plural do
2828
2929 def get_recipe ( % { id: id } , _ ) do
3030 with { :ok , recipe } <- Repositories . get_recipe ( id ) do
31- sections = Enum . map ( recipe . recipeSections , fn section ->
32- Map . put ( section , :recipe_items , section . recipeItems )
33- end )
34- { :ok , Map . put ( recipe , :recipe_sections , sections ) }
31+ { :ok , format_recipe ( recipe ) }
3532 end
3633 end
3734
35+ defp format_section ( section ) , do: Map . put ( section , :recipe_items , section . recipeItems )
36+
37+ defp format_recipe ( recipe ) do
38+ sections = Enum . map ( recipe . recipeSections , & format_section / 1 )
39+ Map . put ( recipe , :recipe_sections , sections )
40+ end
41+
42+ def get_stack ( % { name: name } , _ ) do
43+ with { :ok , % Stack { bundles: recipes , sections: sections } = stack } <- Repositories . get_stack ( name ) ,
44+ do: { :ok , % { stack | bundles: Enum . map ( recipes , & format_recipe / 1 ) , sections: Enum . map ( sections , & format_section / 1 ) } }
45+ end
46+
3847 def list_applications ( _ , _ ) do
3948 with { :ok , % { items: items } } <- Client . list_applications ( ) ,
4049 do: { :ok , items }
@@ -53,6 +62,10 @@ defmodule Console.GraphQl.Resolvers.Plural do
5362 Plural . install_recipe ( id , context , ! ! args [ :oidc ] , user )
5463 end
5564
65+ def install_stack ( % { name: name , context: context } = args , % { context: % { current_user: user } } ) do
66+ Plural . install_stack ( name , context , ! ! args [ :oidc ] , user )
67+ end
68+
5669 def update_smtp ( % { smtp: smtp } , _ ) , do: Plural . update_smtp ( smtp )
5770
5871 def resolve_configuration ( % { metadata: % { name: name } } , first , second ) ,
0 commit comments