Commit 914bdb7b authored by Tiger's avatar Tiger
parent 023b7230
...@@ -6,6 +6,9 @@ module Types ...@@ -6,6 +6,9 @@ module Types
class JobType < BaseObject class JobType < BaseObject
graphql_name 'CiJob' 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, field :name, GraphQL::STRING_TYPE, null: true,
description: 'Name of the job' description: 'Name of the job'
field :needs, JobType.connection_type, null: true, field :needs, JobType.connection_type, null: true,
......
---
title: Add pipeline to CI job GraphQL type
merge_request: 47347
author:
type: added
...@@ -2325,6 +2325,11 @@ type CiJob { ...@@ -2325,6 +2325,11 @@ type CiJob {
last: Int last: Int
): CiJobConnection ): CiJobConnection
"""
Pipeline the job belongs to
"""
pipeline: Pipeline!
""" """
Schedule for the build Schedule for the build
""" """
......
...@@ -6240,6 +6240,24 @@ ...@@ -6240,6 +6240,24 @@
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "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", "name": "scheduledAt",
"description": "Schedule for the build", "description": "Schedule for the build",
...@@ -379,6 +379,7 @@ Represents the total number of issues and their weights for a particular day. ...@@ -379,6 +379,7 @@ Represents the total number of issues and their weights for a particular day.
| `detailedStatus` | DetailedStatus | Detailed status of the job | | `detailedStatus` | DetailedStatus | Detailed status of the job |
| `name` | String | Name of the job | | `name` | String | Name of the job |
| `needs` | CiJobConnection | Builds that must complete before the jobs run | | `needs` | CiJobConnection | Builds that must complete before the jobs run |
| `pipeline` | Pipeline! | Pipeline the job belongs to |
| `scheduledAt` | Time | Schedule for the build | | `scheduledAt` | Time | Schedule for the build |
### CiStage ### CiStage
......
...@@ -7,6 +7,7 @@ RSpec.describe Types::Ci::JobType do ...@@ -7,6 +7,7 @@ RSpec.describe Types::Ci::JobType do
it 'exposes the expected fields' do it 'exposes the expected fields' do
expected_fields = %i[ expected_fields = %i[
pipeline
name name
needs needs
detailedStatus detailedStatus
......
...@@ -34,6 +34,9 @@ RSpec.describe 'Query.project.pipeline.stages.groups.jobs' do ...@@ -34,6 +34,9 @@ RSpec.describe 'Query.project.pipeline.stages.groups.jobs' do
jobs { jobs {
nodes { nodes {
name name
pipeline {
id
}
} }
} }
} }
...@@ -53,7 +56,7 @@ RSpec.describe 'Query.project.pipeline.stages.groups.jobs' do ...@@ -53,7 +56,7 @@ RSpec.describe 'Query.project.pipeline.stages.groups.jobs' do
end end
context 'when fetching jobs from the pipeline' do 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 control_count = ActiveRecord::QueryRecorder.new do
post_graphql(query, current_user: user) post_graphql(query, current_user: user)
end end
...@@ -86,8 +89,27 @@ RSpec.describe 'Query.project.pipeline.stages.groups.jobs' do ...@@ -86,8 +89,27 @@ RSpec.describe 'Query.project.pipeline.stages.groups.jobs' do
docker_jobs = docker_group.dig('jobs', 'nodes') docker_jobs = docker_group.dig('jobs', 'nodes')
rspec_jobs = rspec_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(docker_jobs).to eq([
expect(rspec_jobs).to eq([{ 'name' => 'rspec 1 2' }, { 'name' => 'rspec 2 2' }]) {
'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 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