Commit 403362ba authored by Stan Hu's avatar Stan Hu

Merge branch '267147-graphql-total-count' into 'master'

Total Count for Terraform and Cluster GraphQL API

See merge request gitlab-org/gitlab!45798
parents 71c40552 2e2804d5
......@@ -7,6 +7,8 @@ module Types
authorize :read_terraform_state
connection_type_class(Types::CountableConnectionType)
field :id, GraphQL::ID_TYPE,
null: false,
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 {
The connection type for ClusterAgent.
"""
type ClusterAgentConnection {
"""
Total count of collection
"""
count: Int!
"""
A list of edges.
"""
......@@ -2389,6 +2394,11 @@ type ClusterAgentToken {
The connection type for ClusterAgentToken.
"""
type ClusterAgentTokenConnection {
"""
Total count of collection
"""
count: Int!
"""
A list of edges.
"""
......@@ -18954,6 +18964,11 @@ type TerraformState {
The connection type for TerraformState.
"""
type TerraformStateConnection {
"""
Total count of collection
"""
count: Int!
"""
A list of edges.
"""
......
......@@ -6183,6 +6183,24 @@
"name": "ClusterAgentConnection",
"description": "The connection type for ClusterAgent.",
"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",
"description": "A list of edges.",
......@@ -6442,6 +6460,24 @@
"name": "ClusterAgentTokenConnection",
"description": "The connection type for ClusterAgentToken.",
"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",
"description": "A list of edges.",
......@@ -54911,6 +54947,24 @@
"name": "TerraformStateConnection",
"description": "The connection type for TerraformState.",
"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",
"description": "A list of edges.",
......@@ -7,6 +7,8 @@ module Types
authorize :admin_cluster
connection_type_class(Types::CountableConnectionType)
field :cluster_agent,
Types::Clusters::AgentType,
description: 'Cluster agent this token is associated with',
......
......@@ -7,6 +7,8 @@ module Types
authorize :admin_cluster
connection_type_class(Types::CountableConnectionType)
field :created_at,
Types::TimeType,
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
query {
project(fullPath: "#{project.full_path}") {
clusterAgents {
count
nodes {
id
name
......@@ -227,6 +228,12 @@ RSpec.describe GitlabSchema.types['Project'] do
expect(agents.first['updatedAt']).to be_present
expect(agents.first['project']['id']).to eq(project.to_global_id.to_s)
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
describe 'cluster_agent' do
......@@ -240,6 +247,7 @@ RSpec.describe GitlabSchema.types['Project'] do
id
tokens {
count
nodes {
id
}
......@@ -267,5 +275,12 @@ RSpec.describe GitlabSchema.types['Project'] do
expect(tokens.count).to be(1)
expect(tokens.first['id']).to eq(agent_token.to_global_id.to_s)
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
# 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