Commit 164e9136 authored by Tiger's avatar Tiger

Add CI job to Terraform state version GraphQL type

https://gitlab.com/gitlab-org/gitlab/-/merge_requests/47339
parent 023b7230
......@@ -17,6 +17,12 @@ module Types
description: 'The user that created this version',
resolve: -> (version, _, _) { Gitlab::Graphql::Loaders::BatchModelLoader.new(User, version.created_by_user_id).find }
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 }
field :created_at, Types::TimeType,
null: false,
description: 'Timestamp the version was created'
......
---
title: Add CI job to Terraform state version GraphQL type
merge_request: 47339
author:
type: added
......@@ -20541,6 +20541,11 @@ type TerraformStateVersion {
"""
id: ID!
"""
The job that created this version
"""
job: CiJob
"""
Timestamp the version was updated
"""
......
......@@ -59663,6 +59663,20 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "job",
"description": "The job that created this version",
"args": [
],
"type": {
"kind": "OBJECT",
"name": "CiJob",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "updatedAt",
"description": "Timestamp the version was updated",
......@@ -3019,6 +3019,7 @@ Autogenerated return type of TerraformStateUnlock.
| `createdAt` | Time! | Timestamp the version was created |
| `createdByUser` | User | The user that created this version |
| `id` | ID! | ID of the Terraform state version |
| `job` | CiJob | The job that created this version |
| `updatedAt` | Time! | Timestamp the version was updated |
### TerraformStateVersionRegistry
......
......@@ -4,6 +4,7 @@ FactoryBot.define do
factory :terraform_state_version, class: 'Terraform::StateVersion' do
terraform_state factory: :terraform_state
created_by_user factory: :user
build { association(:ci_build, project: terraform_state.project) }
sequence(:version)
file { fixture_file_upload('spec/fixtures/terraform/terraform.tfstate', 'application/json') }
......
......@@ -7,12 +7,13 @@ RSpec.describe GitlabSchema.types['TerraformStateVersion'] do
it { expect(described_class).to require_graphql_authorizations(:read_terraform_state) }
describe 'fields' do
let(:fields) { %i[id created_by_user created_at updated_at] }
let(:fields) { %i[id created_by_user job created_at updated_at] }
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['createdByUser'].type).not_to be_non_null }
it { expect(described_class.fields['job'].type).not_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 }
end
......
......@@ -29,6 +29,10 @@ RSpec.describe 'query terraform states' do
createdByUser {
id
}
job {
name
}
}
lockedByUser {
......@@ -61,6 +65,7 @@ RSpec.describe 'query terraform states' do
expect(version['createdAt']).to eq(latest_version.created_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('job', 'name')).to eq(latest_version.build.name)
end
it 'returns count of terraform states' do
......
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