diff options
Diffstat (limited to 'app/graphql/types/terraform')
-rw-r--r-- | app/graphql/types/terraform/state_type.rb | 8 | ||||
-rw-r--r-- | app/graphql/types/terraform/state_version_type.rb | 35 |
2 files changed, 34 insertions, 9 deletions
diff --git a/app/graphql/types/terraform/state_type.rb b/app/graphql/types/terraform/state_type.rb index 05b6d130f19..d97e673bf31 100644 --- a/app/graphql/types/terraform/state_type.rb +++ b/app/graphql/types/terraform/state_type.rb @@ -19,9 +19,7 @@ module Types field :locked_by_user, Types::UserType, null: true, - authorize: :read_user, - description: 'The user currently holding a lock on the Terraform state', - resolve: -> (state, _, _) { Gitlab::Graphql::Loaders::BatchModelLoader.new(User, state.locked_by_user_id).find } + description: 'The user currently holding a lock on the Terraform state' field :locked_at, Types::TimeType, null: true, @@ -39,6 +37,10 @@ module Types field :updated_at, Types::TimeType, null: false, description: 'Timestamp the Terraform state was updated' + + def locked_by_user + Gitlab::Graphql::Loaders::BatchModelLoader.new(User, object.locked_by_user_id).find + end end end end diff --git a/app/graphql/types/terraform/state_version_type.rb b/app/graphql/types/terraform/state_version_type.rb index b1fbe42ecaf..a3af5c876ca 100644 --- a/app/graphql/types/terraform/state_version_type.rb +++ b/app/graphql/types/terraform/state_version_type.rb @@ -3,6 +3,8 @@ module Types module Terraform class StateVersionType < BaseObject + include ::API::Helpers::RelatedResourcesHelpers + graphql_name 'TerraformStateVersion' authorize :read_terraform_state @@ -13,15 +15,20 @@ module Types field :created_by_user, Types::UserType, null: true, - authorize: :read_user, - description: 'The user that created this version', - resolve: -> (version, _, _) { Gitlab::Graphql::Loaders::BatchModelLoader.new(User, version.created_by_user_id).find } + description: 'The user that created this version' + + field :download_path, GraphQL::STRING_TYPE, + null: true, + description: "URL for downloading the version's JSON file" field :job, Types::Ci::JobType, null: true, - authorize: :read_build, - description: 'The job that created this version', - resolve: -> (version, _, _) { Gitlab::Graphql::Loaders::BatchModelLoader.new(::Ci::Build, version.ci_build_id).find } + description: 'The job that created this version' + + field :serial, GraphQL::INT_TYPE, + null: true, + description: 'Serial number of the version', + method: :version field :created_at, Types::TimeType, null: false, @@ -30,6 +37,22 @@ module Types field :updated_at, Types::TimeType, null: false, description: 'Timestamp the version was updated' + + def created_by_user + Gitlab::Graphql::Loaders::BatchModelLoader.new(User, object.created_by_user_id).find + end + + def download_path + expose_path api_v4_projects_terraform_state_versions_path( + id: object.project_id, + name: object.terraform_state.name, + serial: object.version + ) + end + + def job + Gitlab::Graphql::Loaders::BatchModelLoader.new(::Ci::Build, object.ci_build_id).find + end end end end |