@@ -110,6 +110,18 @@ defmodule Console.GraphQl.Deployments.Stack do
110110 field :errors , list_of ( :service_error_attributes ) , description: "Any errors detected when trying to run this stack"
111111 field :cancellation_reason , :string , description: "Why you decided to cancel this run"
112112 field :violations , list_of ( :stack_policy_violation_attributes ) , description: "the violations detected by the policy engine"
113+ field :infracost_resources , list_of ( :stack_infracost_resource_attributes ) , description: "Infracost resource rows to persist for this run"
114+ end
115+
116+ input_object :stack_infracost_resource_attributes do
117+ field :resource_scope , non_null ( :string ) , description: "breakdown | past_breakdown | diff | free"
118+ field :project_name , :string , description: "Infracost project name this resource belongs to"
119+ field :name , non_null ( :string )
120+ field :resource_type , :string
121+ field :hourly_cost , :float
122+ field :monthly_cost , :float
123+ field :monthly_usage_cost , :float
124+ field :raw_resource , :json
113125 end
114126
115127 input_object :run_step_attributes do
@@ -270,6 +282,12 @@ defmodule Console.GraphQl.Deployments.Stack do
270282
271283 field :tags , list_of ( :tag ) , resolve: dataloader ( Deployments ) , description: "key/value tags to filter stacks"
272284
285+ field :infracost_resources , list_of ( :stack_infracost_resource ) ,
286+ description: "Infracost resource rows attached to this stack (newest first)" do
287+ arg :limit , :integer
288+ resolve & Deployments . list_stack_infracost_resources / 3
289+ end
290+
273291 field :read_bindings , list_of ( :policy_binding ) , resolve: dataloader ( Deployments )
274292 field :write_bindings , list_of ( :policy_binding ) , resolve: dataloader ( Deployments )
275293
@@ -429,9 +447,37 @@ defmodule Console.GraphQl.Deployments.Stack do
429447 field :repository , :git_repository , resolve: dataloader ( Deployments ) , description: "the git repository you're sourcing IaC from"
430448 field :violations , list_of ( :stack_policy_violation ) , resolve: dataloader ( Deployments ) , description: "policy violations for this stack"
431449
450+ field :infracost_resources , list_of ( :stack_infracost_resource ) ,
451+ description: "Infracost resource rows attached to this run (newest first)" do
452+ arg :limit , :integer
453+ resolve & Deployments . list_stack_run_infracost_resources / 3
454+ end
455+
456+ timestamps ( )
457+ end
458+
459+ object :stack_infracost_resource do
460+ field :id , non_null ( :id )
461+ field :resource_scope , non_null ( :string ) , description: "breakdown | past_breakdown | diff | free"
462+ field :project_name , :string , description: "Infracost project name this resource belongs to"
463+ field :name , non_null ( :string )
464+ field :resource_type , :string
465+
466+ field :hourly_cost , :float , resolve: fn p , _ , _ -> { :ok , decimal_float ( p . hourly_cost ) } end
467+ field :monthly_cost , :float , resolve: fn p , _ , _ -> { :ok , decimal_float ( p . monthly_cost ) } end
468+ field :monthly_usage_cost , :float , resolve: fn p , _ , _ -> { :ok , decimal_float ( p . monthly_usage_cost ) } end
469+
470+ field :raw_resource , :map
471+
472+ field :stack_run , :stack_run , resolve: dataloader ( Deployments )
473+
432474 timestamps ( )
433475 end
434476
477+ defp decimal_float ( nil ) , do: nil
478+ defp decimal_float ( % Decimal { } = d ) , do: Decimal . to_float ( d )
479+ defp decimal_float ( _ ) , do: nil
480+
435481 object :run_step do
436482 field :id , non_null ( :id )
437483 field :status , non_null ( :step_status )
0 commit comments