Commit 8fa7c7d0 authored by Markus Koller's avatar Markus Koller

Merge branch '267168-add-pipeline-to-ci-job-type' into 'master'

Add pipeline to CI job GraphQL type

See merge request gitlab-org/gitlab!47347
parents 3af7048f 914bdb7b
......@@ -6,6 +6,9 @@ module Types
class JobType < BaseObject
graphql_name 'CiJob'
field :pipeline, Types::Ci::PipelineType, null: false,
description: 'Pipeline the job belongs to',
resolve: -> (build, _, _) { Gitlab::Graphql::Loaders::BatchModelLoader.new(::Ci::Pipeline, build.pipeline_id).find }
field :name, GraphQL::STRING_TYPE, null: true,
description: 'Name of the job'
field :needs, JobType.connection_type, null: true,
......
---
title: Add pipeline to CI job GraphQL type
merge_request: 47347
author:
type: added
......@@ -2335,6 +2335,11 @@ type CiJob {
last: Int
): CiJobConnection
"""
Pipeline the job belongs to
"""
pipeline: Pipeline!
"""
Schedule for the build
"""
......
......@@ -6276,6 +6276,24 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "pipeline",
"description": "Pipeline the job belongs to",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "Pipeline",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "scheduledAt",
"description": "Schedule for the build",
......@@ -381,6 +381,7 @@ Represents the total number of issues and their weights for a particular day.
| `detailedStatus` | DetailedStatus | Detailed status of the job |
| `name` | String | Name of the job |
| `needs` | CiJobConnection | Builds that must complete before the jobs run |
| `pipeline` | Pipeline! | Pipeline the job belongs to |
| `scheduledAt` | Time | Schedule for the build |
### CiStage
......
......@@ -7,6 +7,7 @@ RSpec.describe Types::Ci::JobType do
it 'exposes the expected fields' do
expected_fields = %i[
pipeline
name
needs
detailedStatus
......
......@@ -34,6 +34,9 @@ RSpec.describe 'Query.project.pipeline.stages.groups.jobs' do
jobs {
nodes {
name
pipeline {
id
}
}
}
}
......@@ -53,7 +56,7 @@ RSpec.describe 'Query.project.pipeline.stages.groups.jobs' do
end
context 'when fetching jobs from the pipeline' do
it 'avoids N+1 queries' do
it 'avoids N+1 queries', :aggregate_failures do
control_count = ActiveRecord::QueryRecorder.new do
post_graphql(query, current_user: user)
end
......@@ -86,8 +89,27 @@ RSpec.describe 'Query.project.pipeline.stages.groups.jobs' do
docker_jobs = docker_group.dig('jobs', 'nodes')
rspec_jobs = rspec_group.dig('jobs', 'nodes')
expect(docker_jobs).to eq([{ 'name' => 'docker 1 2' }, { 'name' => 'docker 2 2' }])
expect(rspec_jobs).to eq([{ 'name' => 'rspec 1 2' }, { 'name' => 'rspec 2 2' }])
expect(docker_jobs).to eq([
{
'name' => 'docker 1 2',
'pipeline' => { 'id' => pipeline.to_global_id.to_s }
},
{
'name' => 'docker 2 2',
'pipeline' => { 'id' => pipeline.to_global_id.to_s }
}
])
expect(rspec_jobs).to eq([
{
'name' => 'rspec 1 2',
'pipeline' => { 'id' => pipeline.to_global_id.to_s }
},
{
'name' => 'rspec 2 2',
'pipeline' => { 'id' => pipeline.to_global_id.to_s }
}
])
end
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