Commit 20895f86 authored by Emily Ring's avatar Emily Ring Committed by Bob Van Landuyt

Added additional fields to GraphQl terraform state

Added serial and downloadPath to graphql state_version_type
Updated related docs and tests
parent 74fed087
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
module Types module Types
module Terraform module Terraform
class StateVersionType < BaseObject class StateVersionType < BaseObject
include ::API::Helpers::RelatedResourcesHelpers
graphql_name 'TerraformStateVersion' graphql_name 'TerraformStateVersion'
authorize :read_terraform_state authorize :read_terraform_state
...@@ -16,11 +18,20 @@ module Types ...@@ -16,11 +18,20 @@ module Types
authorize: :read_user, authorize: :read_user,
description: 'The user that created this version' 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, field :job, Types::Ci::JobType,
null: true, null: true,
authorize: :read_build, authorize: :read_build,
description: 'The job that created this version' 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, field :created_at, Types::TimeType,
null: false, null: false,
description: 'Timestamp the version was created' description: 'Timestamp the version was created'
...@@ -33,6 +44,14 @@ module Types ...@@ -33,6 +44,14 @@ module Types
Gitlab::Graphql::Loaders::BatchModelLoader.new(User, object.created_by_user_id).find Gitlab::Graphql::Loaders::BatchModelLoader.new(User, object.created_by_user_id).find
end 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 def job
Gitlab::Graphql::Loaders::BatchModelLoader.new(::Ci::Build, object.ci_build_id).find Gitlab::Graphql::Loaders::BatchModelLoader.new(::Ci::Build, object.ci_build_id).find
end end
......
---
title: Add additional fields to GraphQl terraform state version
merge_request: 48411
author:
type: changed
...@@ -21619,6 +21619,11 @@ type TerraformStateVersion { ...@@ -21619,6 +21619,11 @@ type TerraformStateVersion {
""" """
createdByUser: User createdByUser: User
"""
URL for downloading the version's JSON file
"""
downloadPath: String
""" """
ID of the Terraform state version ID of the Terraform state version
""" """
...@@ -21629,6 +21634,11 @@ type TerraformStateVersion { ...@@ -21629,6 +21634,11 @@ type TerraformStateVersion {
""" """
job: CiJob job: CiJob
"""
Serial number of the version
"""
serial: Int
""" """
Timestamp the version was updated Timestamp the version was updated
""" """
......
...@@ -63004,6 +63004,20 @@ ...@@ -63004,6 +63004,20 @@
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "deprecationReason": null
}, },
{
"name": "downloadPath",
"description": "URL for downloading the version's JSON file",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{ {
"name": "id", "name": "id",
"description": "ID of the Terraform state version", "description": "ID of the Terraform state version",
...@@ -63036,6 +63050,20 @@ ...@@ -63036,6 +63050,20 @@
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "deprecationReason": null
}, },
{
"name": "serial",
"description": "Serial number of the version",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{ {
"name": "updatedAt", "name": "updatedAt",
"description": "Timestamp the version was updated", "description": "Timestamp the version was updated",
...@@ -3217,8 +3217,10 @@ Autogenerated return type of TerraformStateUnlock. ...@@ -3217,8 +3217,10 @@ Autogenerated return type of TerraformStateUnlock.
| ----- | ---- | ----------- | | ----- | ---- | ----------- |
| `createdAt` | Time! | Timestamp the version was created | | `createdAt` | Time! | Timestamp the version was created |
| `createdByUser` | User | The user that created this version | | `createdByUser` | User | The user that created this version |
| `downloadPath` | String | URL for downloading the version's JSON file |
| `id` | ID! | ID of the Terraform state version | | `id` | ID! | ID of the Terraform state version |
| `job` | CiJob | The job that created this version | | `job` | CiJob | The job that created this version |
| `serial` | Int | Serial number of the version |
| `updatedAt` | Time! | Timestamp the version was updated | | `updatedAt` | Time! | Timestamp the version was updated |
### TerraformStateVersionRegistry ### TerraformStateVersionRegistry
......
...@@ -7,13 +7,15 @@ RSpec.describe GitlabSchema.types['TerraformStateVersion'] do ...@@ -7,13 +7,15 @@ RSpec.describe GitlabSchema.types['TerraformStateVersion'] do
it { expect(described_class).to require_graphql_authorizations(:read_terraform_state) } it { expect(described_class).to require_graphql_authorizations(:read_terraform_state) }
describe 'fields' do describe 'fields' do
let(:fields) { %i[id created_by_user job created_at updated_at] } let(:fields) { %i[id created_by_user job download_path serial created_at updated_at] }
it { expect(described_class).to have_graphql_fields(fields) } it { expect(described_class).to have_graphql_fields(fields) }
it { expect(described_class.fields['id'].type).to be_non_null } it { expect(described_class.fields['id'].type).to be_non_null }
it { expect(described_class.fields['createdByUser'].type).not_to be_non_null } it { expect(described_class.fields['createdByUser'].type).not_to be_non_null }
it { expect(described_class.fields['job'].type).not_to be_non_null } it { expect(described_class.fields['job'].type).not_to be_non_null }
it { expect(described_class.fields['downloadPath'].type).not_to be_non_null }
it { expect(described_class.fields['serial'].type).not_to be_non_null }
it { expect(described_class.fields['createdAt'].type).to be_non_null } it { expect(described_class.fields['createdAt'].type).to be_non_null }
it { expect(described_class.fields['updatedAt'].type).to be_non_null } it { expect(described_class.fields['updatedAt'].type).to be_non_null }
end end
......
...@@ -4,6 +4,7 @@ require 'spec_helper' ...@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec.describe 'query terraform states' do RSpec.describe 'query terraform states' do
include GraphqlHelpers include GraphqlHelpers
include ::API::Helpers::RelatedResourcesHelpers
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
let_it_be(:terraform_state) { create(:terraform_state, :with_version, :locked, project: project) } let_it_be(:terraform_state) { create(:terraform_state, :with_version, :locked, project: project) }
...@@ -23,6 +24,8 @@ RSpec.describe 'query terraform states' do ...@@ -23,6 +24,8 @@ RSpec.describe 'query terraform states' do
latestVersion { latestVersion {
id id
downloadPath
serial
createdAt createdAt
updatedAt updatedAt
...@@ -62,6 +65,16 @@ RSpec.describe 'query terraform states' do ...@@ -62,6 +65,16 @@ RSpec.describe 'query terraform states' do
expect(state.dig('lockedByUser', 'id')).to eq(terraform_state.locked_by_user.to_global_id.to_s) expect(state.dig('lockedByUser', 'id')).to eq(terraform_state.locked_by_user.to_global_id.to_s)
expect(version['id']).to eq(latest_version.to_global_id.to_s) expect(version['id']).to eq(latest_version.to_global_id.to_s)
expect(version['serial']).to eq(latest_version.version)
expect(version['downloadPath']).to eq(
expose_path(
api_v4_projects_terraform_state_versions_path(
id: project.id,
name: terraform_state.name,
serial: latest_version.version
)
)
)
expect(version['createdAt']).to eq(latest_version.created_at.iso8601) expect(version['createdAt']).to eq(latest_version.created_at.iso8601)
expect(version['updatedAt']).to eq(latest_version.updated_at.iso8601) expect(version['updatedAt']).to eq(latest_version.updated_at.iso8601)
expect(version.dig('createdByUser', 'id')).to eq(latest_version.created_by_user.to_global_id.to_s) expect(version.dig('createdByUser', 'id')).to eq(latest_version.created_by_user.to_global_id.to_s)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment