Commit 363d0d38 authored by Alex Kalderimis's avatar Alex Kalderimis

Merge branch 'lm-add-id-to-some-gql-types' into 'master'

Adds ID to group, stage, and detailed status

See merge request gitlab-org/gitlab!64630
parents 96fe611a 326a4a9d
......@@ -7,6 +7,8 @@ module Types
class BuildNeedType < BaseObject
graphql_name 'CiBuildNeed'
field :id, GraphQL::ID_TYPE, null: false,
description: 'ID of the job we need to complete.'
field :name, GraphQL::STRING_TYPE, null: true,
description: 'Name of the job we need to complete.'
end
......
......@@ -6,6 +6,9 @@ module Types
class DetailedStatusType < BaseObject
graphql_name 'DetailedStatus'
field :id, GraphQL::STRING_TYPE, null: false,
description: 'ID for a detailed status.',
extras: [:parent]
field :group, GraphQL::STRING_TYPE, null: true,
description: 'Group of the status.'
field :icon, GraphQL::STRING_TYPE, null: true,
......@@ -29,6 +32,10 @@ module Types
calls_gitaly: true,
description: 'Action information for the status. This includes method, button title, icon, path, and title.'
def id(parent:)
"#{object.id}-#{parent.object.object.id}"
end
def action
if object.has_action?
{
......
......@@ -6,12 +6,14 @@ module Types
class GroupType < BaseObject
graphql_name 'CiGroup'
field :id, GraphQL::STRING_TYPE, null: false,
description: 'ID for a group.'
field :name, GraphQL::STRING_TYPE, null: true,
description: 'Name of the job group.'
description: 'Name of the job group.'
field :size, GraphQL::INT_TYPE, null: true,
description: 'Size of the group.'
description: 'Size of the group.'
field :jobs, Ci::JobType.connection_type, null: true,
description: 'Jobs in group.'
description: 'Jobs in group.'
field :detailed_status, Types::Ci::DetailedStatusType, null: true,
description: 'Detailed status of the group.'
......
......@@ -6,20 +6,16 @@ module Types
graphql_name 'CiStage'
authorize :read_commit_status
field :name,
type: GraphQL::STRING_TYPE,
null: true,
field :id, GraphQL::ID_TYPE, null: false,
description: 'ID of the stage.'
field :name, type: GraphQL::STRING_TYPE, null: true,
description: 'Name of the stage.'
field :groups,
type: Ci::GroupType.connection_type,
null: true,
field :groups, type: Ci::GroupType.connection_type, null: true,
extras: [:lookahead],
description: 'Group of jobs for the stage.'
field :detailed_status, Types::Ci::DetailedStatusType,
null: true,
field :detailed_status, Types::Ci::DetailedStatusType, null: true,
description: 'Detailed status of the stage.'
field :jobs, Ci::JobType.connection_type,
null: true,
field :jobs, Ci::JobType.connection_type, null: true,
description: 'Jobs for the stage.',
method: 'latest_statuses'
field :status, GraphQL::STRING_TYPE,
......
......@@ -5,6 +5,9 @@ module Types
class StatusActionType < BaseObject
graphql_name 'StatusAction'
field :id, GraphQL::STRING_TYPE, null: false,
description: 'ID for a status action.',
extras: [:parent]
field :button_title, GraphQL::STRING_TYPE, null: true,
description: 'Title for the button, for example: Retry this job.'
field :icon, GraphQL::STRING_TYPE, null: true,
......@@ -17,6 +20,10 @@ module Types
field :title, GraphQL::STRING_TYPE, null: true,
description: 'Title for the action, for example: Retry.'
def id(parent:)
"#{parent.parent.object.object.class.name}-#{parent.object.object.id}"
end
def action_method
object[:method]
end
......
......@@ -10,6 +10,7 @@ module Ci
class Group
include StaticModel
include Gitlab::Utils::StrongMemoize
include GlobalID::Identification
attr_reader :project, :stage, :name, :jobs
......@@ -22,6 +23,10 @@ module Ci
@jobs = jobs
end
def id
"#{stage.id}-#{name}"
end
def ==(other)
other.present? && other.is_a?(self.class) &&
project == other.project &&
......
......@@ -7658,6 +7658,7 @@ Represents the total number of issues and their weights for a particular day.
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="cibuildneedid"></a>`id` | [`ID!`](#id) | ID of the job we need to complete. |
| <a id="cibuildneedname"></a>`name` | [`String`](#string) | Name of the job we need to complete. |
### `CiConfig`
......@@ -7733,6 +7734,7 @@ Represents the total number of issues and their weights for a particular day.
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="cigroupdetailedstatus"></a>`detailedStatus` | [`DetailedStatus`](#detailedstatus) | Detailed status of the group. |
| <a id="cigroupid"></a>`id` | [`String!`](#string) | ID for a group. |
| <a id="cigroupjobs"></a>`jobs` | [`CiJobConnection`](#cijobconnection) | Jobs in group. (see [Connections](#connections)) |
| <a id="cigroupname"></a>`name` | [`String`](#string) | Name of the job group. |
| <a id="cigroupsize"></a>`size` | [`Int`](#int) | Size of the group. |
......@@ -7827,6 +7829,7 @@ Represents the total number of issues and their weights for a particular day.
| ---- | ---- | ----------- |
| <a id="cistagedetailedstatus"></a>`detailedStatus` | [`DetailedStatus`](#detailedstatus) | Detailed status of the stage. |
| <a id="cistagegroups"></a>`groups` | [`CiGroupConnection`](#cigroupconnection) | Group of jobs for the stage. (see [Connections](#connections)) |
| <a id="cistageid"></a>`id` | [`ID!`](#id) | ID of the stage. |
| <a id="cistagejobs"></a>`jobs` | [`CiJobConnection`](#cijobconnection) | Jobs for the stage. (see [Connections](#connections)) |
| <a id="cistagename"></a>`name` | [`String`](#string) | Name of the stage. |
| <a id="cistagestatus"></a>`status` | [`String`](#string) | Status of the pipeline stage. |
......@@ -8491,6 +8494,7 @@ four standard [pagination arguments](#connection-pagination-arguments):
| <a id="detailedstatusgroup"></a>`group` | [`String`](#string) | Group of the status. |
| <a id="detailedstatushasdetails"></a>`hasDetails` | [`Boolean`](#boolean) | Indicates if the status has further details. |
| <a id="detailedstatusicon"></a>`icon` | [`String`](#string) | Icon of the status. |
| <a id="detailedstatusid"></a>`id` | [`String!`](#string) | ID for a detailed status. |
| <a id="detailedstatuslabel"></a>`label` | [`String`](#string) | Label of the status. |
| <a id="detailedstatustext"></a>`text` | [`String`](#string) | Text of the status. |
| <a id="detailedstatustooltip"></a>`tooltip` | [`String`](#string) | Tooltip associated with the status. |
......@@ -13102,6 +13106,7 @@ Represents the Geo sync and verification state of a snippet repository.
| ---- | ---- | ----------- |
| <a id="statusactionbuttontitle"></a>`buttonTitle` | [`String`](#string) | Title for the button, for example: Retry this job. |
| <a id="statusactionicon"></a>`icon` | [`String`](#string) | Icon used in the action button. |
| <a id="statusactionid"></a>`id` | [`String!`](#string) | ID for a status action. |
| <a id="statusactionmethod"></a>`method` | [`String`](#string) | Method for the action, for example: :post. |
| <a id="statusactionpath"></a>`path` | [`String`](#string) | Path for the action. |
| <a id="statusactiontitle"></a>`title` | [`String`](#string) | Title for the action, for example: Retry. |
......
......@@ -18,6 +18,10 @@ module Gitlab
@user = user
end
def id
"#{group}-#{subject.id}"
end
def icon
raise NotImplementedError
end
......
......@@ -8,14 +8,26 @@ RSpec.describe Types::Ci::DetailedStatusType do
specify { expect(described_class.graphql_name).to eq('DetailedStatus') }
it 'has all fields' do
expect(described_class).to have_graphql_fields(:group, :icon, :favicon,
expect(described_class).to have_graphql_fields(:id, :group, :icon, :favicon,
:details_path, :has_details,
:label, :text, :tooltip, :action)
end
let_it_be(:stage) { create(:ci_stage_entity, status: :skipped) }
describe 'id field' do
it 'correctly renders the field' do
parent_object = double(:parent_object, object: stage)
parent = double(:parent, object: parent_object)
status = stage.detailed_status(stage.pipeline.user)
expected_id = "#{status.id}-#{stage.id}"
expect(resolve_field('id', status, extras: { parent: parent })).to eq(expected_id)
end
end
describe 'action field' do
it 'correctly renders the field' do
stage = create(:ci_stage_entity, status: :skipped)
status = stage.detailed_status(stage.pipeline.user)
expected_status = {
......
......@@ -7,6 +7,7 @@ RSpec.describe Types::Ci::GroupType do
it 'exposes the expected fields' do
expected_fields = %i[
id
name
size
jobs
......
......@@ -7,6 +7,7 @@ RSpec.describe Types::Ci::StageType do
it 'exposes the expected fields' do
expected_fields = %i[
id
name
groups
detailedStatus
......
......@@ -3,10 +3,13 @@
require 'spec_helper'
RSpec.describe Types::Ci::StatusActionType do
include GraphqlHelpers
specify { expect(described_class.graphql_name).to eq('StatusAction') }
it 'exposes the expected fields' do
expected_fields = %i[
id
buttonTitle
icon
path
......@@ -16,4 +19,21 @@ RSpec.describe Types::Ci::StatusActionType do
expect(described_class).to have_graphql_fields(*expected_fields)
end
describe 'id field' do
it 'correctly renders the field' do
stage = build(:ci_stage_entity, status: :skipped)
status = stage.detailed_status(stage.pipeline.user)
grandparent_object = double(:grandparent_object, object: stage)
parent_object = double(:parent_object, object: status)
grandparent = double(:parent, object: grandparent_object)
parent = double(:parent, object: parent_object, parent: grandparent)
expected_id = "#{stage.class.name}-#{status.id}"
expect(resolve_field('id', status, extras: { parent: parent })).to eq(expected_id)
end
end
end
......@@ -38,9 +38,15 @@ RSpec.describe 'Query.project.pipeline' do
name
groups {
nodes {
detailedStatus {
id
}
name
jobs {
nodes {
detailedStatus {
id
}
name
needs {
nodes { #{all_graphql_fields_for('CiBuildNeed')} }
......
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