Commit 2e2804d5 authored by Emily Ring's avatar Emily Ring Committed by Stan Hu

Added count to terraform and cluster agents

Added count field for GraphQL queries
Updated associated tests and docs
parent 37b8677d
...@@ -7,6 +7,8 @@ module Types ...@@ -7,6 +7,8 @@ module Types
authorize :read_terraform_state authorize :read_terraform_state
connection_type_class(Types::CountableConnectionType)
field :id, GraphQL::ID_TYPE, field :id, GraphQL::ID_TYPE,
null: false, null: false,
description: 'ID of the Terraform state' description: 'ID of the Terraform state'
......
---
title: Add total count to Terraform state GraphQL API
merge_request: 45798
author:
type: changed
...@@ -2307,6 +2307,11 @@ type ClusterAgent { ...@@ -2307,6 +2307,11 @@ type ClusterAgent {
The connection type for ClusterAgent. The connection type for ClusterAgent.
""" """
type ClusterAgentConnection { type ClusterAgentConnection {
"""
Total count of collection
"""
count: Int!
""" """
A list of edges. A list of edges.
""" """
...@@ -2389,6 +2394,11 @@ type ClusterAgentToken { ...@@ -2389,6 +2394,11 @@ type ClusterAgentToken {
The connection type for ClusterAgentToken. The connection type for ClusterAgentToken.
""" """
type ClusterAgentTokenConnection { type ClusterAgentTokenConnection {
"""
Total count of collection
"""
count: Int!
""" """
A list of edges. A list of edges.
""" """
...@@ -18949,6 +18959,11 @@ type TerraformState { ...@@ -18949,6 +18959,11 @@ type TerraformState {
The connection type for TerraformState. The connection type for TerraformState.
""" """
type TerraformStateConnection { type TerraformStateConnection {
"""
Total count of collection
"""
count: Int!
""" """
A list of edges. A list of edges.
""" """
......
...@@ -6183,6 +6183,24 @@ ...@@ -6183,6 +6183,24 @@
"name": "ClusterAgentConnection", "name": "ClusterAgentConnection",
"description": "The connection type for ClusterAgent.", "description": "The connection type for ClusterAgent.",
"fields": [ "fields": [
{
"name": "count",
"description": "Total count of collection",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{ {
"name": "edges", "name": "edges",
"description": "A list of edges.", "description": "A list of edges.",
...@@ -6442,6 +6460,24 @@ ...@@ -6442,6 +6460,24 @@
"name": "ClusterAgentTokenConnection", "name": "ClusterAgentTokenConnection",
"description": "The connection type for ClusterAgentToken.", "description": "The connection type for ClusterAgentToken.",
"fields": [ "fields": [
{
"name": "count",
"description": "Total count of collection",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{ {
"name": "edges", "name": "edges",
"description": "A list of edges.", "description": "A list of edges.",
...@@ -54902,6 +54938,24 @@ ...@@ -54902,6 +54938,24 @@
"name": "TerraformStateConnection", "name": "TerraformStateConnection",
"description": "The connection type for TerraformState.", "description": "The connection type for TerraformState.",
"fields": [ "fields": [
{
"name": "count",
"description": "Total count of collection",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{ {
"name": "edges", "name": "edges",
"description": "A list of edges.", "description": "A list of edges.",
...@@ -7,6 +7,8 @@ module Types ...@@ -7,6 +7,8 @@ module Types
authorize :admin_cluster authorize :admin_cluster
connection_type_class(Types::CountableConnectionType)
field :cluster_agent, field :cluster_agent,
Types::Clusters::AgentType, Types::Clusters::AgentType,
description: 'Cluster agent this token is associated with', description: 'Cluster agent this token is associated with',
......
...@@ -7,6 +7,8 @@ module Types ...@@ -7,6 +7,8 @@ module Types
authorize :admin_cluster authorize :admin_cluster
connection_type_class(Types::CountableConnectionType)
field :created_at, field :created_at,
Types::TimeType, Types::TimeType,
null: true, null: true,
......
---
title: Add total count to cluster agent and agent token GraphQL API
merge_request: 45798
author:
type: changed
...@@ -193,6 +193,7 @@ RSpec.describe GitlabSchema.types['Project'] do ...@@ -193,6 +193,7 @@ RSpec.describe GitlabSchema.types['Project'] do
query { query {
project(fullPath: "#{project.full_path}") { project(fullPath: "#{project.full_path}") {
clusterAgents { clusterAgents {
count
nodes { nodes {
id id
name name
...@@ -227,6 +228,12 @@ RSpec.describe GitlabSchema.types['Project'] do ...@@ -227,6 +228,12 @@ RSpec.describe GitlabSchema.types['Project'] do
expect(agents.first['updatedAt']).to be_present expect(agents.first['updatedAt']).to be_present
expect(agents.first['project']['id']).to eq(project.to_global_id.to_s) expect(agents.first['project']['id']).to eq(project.to_global_id.to_s)
end end
it 'returns count of cluster agents' do
count = subject.dig('data', 'project', 'clusterAgents', 'count')
expect(count).to be(project.cluster_agents.size)
end
end end
describe 'cluster_agent' do describe 'cluster_agent' do
...@@ -240,6 +247,7 @@ RSpec.describe GitlabSchema.types['Project'] do ...@@ -240,6 +247,7 @@ RSpec.describe GitlabSchema.types['Project'] do
id id
tokens { tokens {
count
nodes { nodes {
id id
} }
...@@ -267,5 +275,12 @@ RSpec.describe GitlabSchema.types['Project'] do ...@@ -267,5 +275,12 @@ RSpec.describe GitlabSchema.types['Project'] do
expect(tokens.count).to be(1) expect(tokens.count).to be(1)
expect(tokens.first['id']).to eq(agent_token.to_global_id.to_s) expect(tokens.first['id']).to eq(agent_token.to_global_id.to_s)
end end
it 'returns count of agent tokens' do
agent = subject.dig('data', 'project', 'clusterAgent')
count = agent.dig('tokens', 'count')
expect(cluster_agent.agent_tokens.size).to be(count)
end
end end
end end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'query terraform states' do
include GraphqlHelpers
let_it_be(:project) { create(:project) }
let_it_be(:terraform_state) { create(:terraform_state, :locked, project: project) }
let(:query) do
graphql_query_for(:project, { fullPath: project.full_path },
%{
terraformStates {
count
nodes {
id
name
lockedAt
createdAt
updatedAt
lockedByUser {
id
}
}
}
})
end
let(:current_user) { project.creator }
let(:data) { graphql_data.dig('project', 'terraformStates') }
before do
post_graphql(query, current_user: current_user)
end
it 'returns terraform state data', :aggregate_failures do
state = data.dig('nodes', 0)
expect(state['id']).to eq(terraform_state.to_global_id.to_s)
expect(state['name']).to eq(terraform_state.name)
expect(state['lockedAt']).to eq(terraform_state.locked_at.strftime('%Y-%m-%dT%H:%M:%SZ'))
expect(state['createdAt']).to eq(terraform_state.created_at.strftime('%Y-%m-%dT%H:%M:%SZ'))
expect(state['updatedAt']).to eq(terraform_state.updated_at.strftime('%Y-%m-%dT%H:%M:%SZ'))
expect(state.dig('lockedByUser', 'id')).to eq(terraform_state.locked_by_user.to_global_id.to_s)
end
it 'returns count of terraform states' do
count = data.dig('count')
expect(count).to be(project.terraform_states.size)
end
context 'unauthorized users' do
let(:current_user) { nil }
it { expect(data).to be_nil }
end
end
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