Commit 29d69b33 authored by Marius Bobin's avatar Marius Bobin

Merge branch 'fix-build-need-id-job-type' into 'master'

Make previousStageJobsOrNeeds return union

See merge request gitlab-org/gitlab!76444
parents fd3262af ca6c6a70
......@@ -8,7 +8,7 @@ module Types
graphql_name 'CiBuildNeed'
field :id, GraphQL::Types::ID, null: false,
description: 'ID of the job we need to complete.'
description: 'ID of the BuildNeed.'
field :name, GraphQL::Types::String, null: true,
description: 'Name of the job we need to complete.'
end
......
# frozen_string_literal: true
module Types
module Ci
class JobNeedUnion < GraphQL::Schema::Union
TypeNotSupportedError = Class.new(StandardError)
possible_types Types::Ci::JobType, Types::Ci::BuildNeedType
def self.resolve_type(object, context)
if object.is_a?(::Ci::BuildNeed)
Types::Ci::BuildNeedType
elsif object.is_a?(CommitStatus)
Types::Ci::JobType
else
raise TypeNotSupportedError
end
end
end
end
end
......@@ -50,8 +50,8 @@ module Types
null: true,
description: 'How long the job was enqueued before starting.'
field :previous_stage_jobs_or_needs, Types::Ci::JobType.connection_type, null: true,
description: 'Jobs that must complete before the job runs. Returns needed jobs if the job uses the `needs` keyword, and returns previous stage jobs otherwise.'
field :previous_stage_jobs_or_needs, Types::Ci::JobNeedUnion.connection_type, null: true,
description: 'Jobs that must complete before the job runs. Returns `BuildNeed`, which is the needed jobs if the job uses the `needs` keyword, or the previous stage jobs otherwise.'
field :detailed_status, Types::Ci::DetailedStatusType, null: true,
description: 'Detailed status of the job.'
field :artifacts, Types::Ci::JobArtifactType.connection_type, null: true,
......
......@@ -6513,6 +6513,29 @@ The edge type for [`JiraProject`](#jiraproject).
| <a id="jiraprojectedgecursor"></a>`cursor` | [`String!`](#string) | A cursor for use in pagination. |
| <a id="jiraprojectedgenode"></a>`node` | [`JiraProject`](#jiraproject) | The item at the end of the edge. |
#### `JobNeedUnionConnection`
The connection type for [`JobNeedUnion`](#jobneedunion).
##### Fields
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="jobneedunionconnectionedges"></a>`edges` | [`[JobNeedUnionEdge]`](#jobneedunionedge) | A list of edges. |
| <a id="jobneedunionconnectionnodes"></a>`nodes` | [`[JobNeedUnion]`](#jobneedunion) | A list of nodes. |
| <a id="jobneedunionconnectionpageinfo"></a>`pageInfo` | [`PageInfo!`](#pageinfo) | Information to aid in pagination. |
#### `JobNeedUnionEdge`
The edge type for [`JobNeedUnion`](#jobneedunion).
##### Fields
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="jobneedunionedgecursor"></a>`cursor` | [`String!`](#string) | A cursor for use in pagination. |
| <a id="jobneedunionedgenode"></a>`node` | [`JobNeedUnion`](#jobneedunion) | The item at the end of the edge. |
#### `LabelConnection`
The connection type for [`Label`](#label).
......@@ -8619,7 +8642,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="cibuildneedid"></a>`id` | [`ID!`](#id) | ID of the BuildNeed. |
| <a id="cibuildneedname"></a>`name` | [`String`](#string) | Name of the job we need to complete. |
### `CiConfig`
......@@ -8723,7 +8746,7 @@ Represents the total number of issues and their weights for a particular day.
| <a id="cijobneeds"></a>`needs` | [`CiBuildNeedConnection`](#cibuildneedconnection) | References to builds that must complete before the jobs run. (see [Connections](#connections)) |
| <a id="cijobpipeline"></a>`pipeline` | [`Pipeline`](#pipeline) | Pipeline the job belongs to. |
| <a id="cijobplayable"></a>`playable` | [`Boolean!`](#boolean) | Indicates the job can be played. |
| <a id="cijobpreviousstagejobsorneeds"></a>`previousStageJobsOrNeeds` | [`CiJobConnection`](#cijobconnection) | Jobs that must complete before the job runs. Returns needed jobs if the job uses the `needs` keyword, and returns previous stage jobs otherwise. (see [Connections](#connections)) |
| <a id="cijobpreviousstagejobsorneeds"></a>`previousStageJobsOrNeeds` | [`JobNeedUnionConnection`](#jobneedunionconnection) | Jobs that must complete before the job runs. Returns `BuildNeed`, which is the needed jobs if the job uses the `needs` keyword, or the previous stage jobs otherwise. (see [Connections](#connections)) |
| <a id="cijobqueuedat"></a>`queuedAt` | [`Time`](#time) | When the job was enqueued and marked as pending. |
| <a id="cijobqueuedduration"></a>`queuedDuration` | [`Duration`](#duration) | How long the job was enqueued before starting. |
| <a id="cijobrefname"></a>`refName` | [`String`](#string) | Ref name of the job. |
......@@ -17949,6 +17972,13 @@ One of:
- [`Issue`](#issue)
- [`MergeRequest`](#mergerequest)
#### `JobNeedUnion`
One of:
- [`CiBuildNeed`](#cibuildneed)
- [`CiJob`](#cijob)
#### `NoteableType`
Represents an object that supports notes.
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Types::Ci::JobNeedUnion do
describe '.resolve_type' do
context 'when resolving a build need' do
it 'resolves to a BuildNeedType' do
resolved_type = described_class.resolve_type(build(:ci_build_need), {})
expect(resolved_type).to be(Types::Ci::BuildNeedType)
end
end
context 'when resolving a build' do
it 'resolves to a JobType' do
resolved_type = described_class.resolve_type(build(:ci_build), {})
expect(resolved_type).to be(Types::Ci::JobType)
end
end
context 'when resolving an unrelated object' do
it 'raises a TypeNotSupportedError for string object' do
expect do
described_class.resolve_type(+'unrelated object', {})
end.to raise_error(Types::Ci::JobNeedUnion::TypeNotSupportedError)
end
it 'raises a TypeNotSupportedError for nil object' do
expect do
described_class.resolve_type(nil, {})
end.to raise_error(Types::Ci::JobNeedUnion::TypeNotSupportedError)
end
it 'raises a TypeNotSupportedError for other CI object' do
expect do
described_class.resolve_type(build(:ci_pipeline), {})
end.to raise_error(Types::Ci::JobNeedUnion::TypeNotSupportedError)
end
end
end
end
......@@ -50,8 +50,13 @@ RSpec.describe 'Query.project.pipeline' do
}
previousStageJobsOrNeeds {
nodes {
name
}
... on CiBuildNeed {
#{all_graphql_fields_for('CiBuildNeed')}
}
... on CiJob {
#{all_graphql_fields_for('CiJob')}
}
}
}
detailedStatus {
id
......@@ -99,7 +104,7 @@ RSpec.describe 'Query.project.pipeline' do
'name' => 'docker 1 2',
'needs' => { 'nodes' => [] },
'previousStageJobsOrNeeds' => { 'nodes' => [
{ 'name' => 'my test job' }
a_hash_including( 'name' => 'my test job' )
] }
),
a_hash_including(
......@@ -111,14 +116,15 @@ RSpec.describe 'Query.project.pipeline' do
'name' => 'rspec 1 2',
'needs' => { 'nodes' => [] },
'previousStageJobsOrNeeds' => { 'nodes' => [
{ 'name' => 'docker 1 2' }, { 'name' => 'docker 2 2' }
a_hash_including('name' => 'docker 1 2'),
a_hash_including('name' => 'docker 2 2')
] }
),
a_hash_including(
'name' => 'rspec 2 2',
'needs' => { 'nodes' => [a_hash_including('name' => 'my test job')] },
'previousStageJobsOrNeeds' => { 'nodes' => [
{ 'name' => 'my test job' }
a_hash_including('name' => 'my test job' )
] }
)
)
......
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