Commit 7000489d authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Add a top-level GraphQL query for an iteration

This makes it easier to query a single iteration by ID regardless of
it being a project or group iteration
parent 0489d9c0
......@@ -4313,6 +4313,11 @@ type DismissVulnerabilityPayload {
vulnerability: Vulnerability
}
"""
Identifier of EE::Iteration
"""
scalar EEIterationID
interface Entry {
"""
Flat path of the entry
......@@ -12096,6 +12101,16 @@ type Query {
"""
instanceSecurityDashboard: InstanceSecurityDashboard
"""
Find an iteration
"""
iteration(
"""
Find an iteration by its ID
"""
id: EEIterationID!
): Iteration
"""
Metadata about GitLab
"""
......
......@@ -12009,6 +12009,16 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "SCALAR",
"name": "EEIterationID",
"description": "Identifier of EE::Iteration",
"fields": null,
"inputFields": null,
"interfaces": null,
"enumValues": null,
"possibleTypes": null
},
{
"kind": "INTERFACE",
"name": "Entry",
......@@ -35598,6 +35608,33 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "iteration",
"description": "Find an iteration",
"args": [
{
"name": "id",
"description": "Find an iteration by its ID",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "EEIterationID",
"ofType": null
}
},
"defaultValue": null
}
],
"type": {
"kind": "OBJECT",
"name": "Iteration",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "metadata",
"description": "Metadata about GitLab",
......@@ -6,6 +6,15 @@ module EE
extend ActiveSupport::Concern
prepended do
field :iteration, ::Types::IterationType,
null: true,
resolve: -> (_obj, args, _ctx) { ::GitlabSchema.find_by_gid(args[:id]) },
description: 'Find an iteration' do
argument :id, ::Types::GlobalIDType[Iteration],
required: true,
description: 'Find an iteration by its ID'
end
field :vulnerabilities,
::Types::VulnerabilityType.connection_type,
null: true,
......
---
title: Add GraphQL query for a single iteration
merge_request: 38692
author:
type: added
......@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe GitlabSchema.types['Query'] do
specify do
expect(described_class).to have_graphql_fields(
:iteration,
:geo_node,
:vulnerabilities,
:instance_security_dashboard,
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Querying an Iteration' do
include GraphqlHelpers
let_it_be(:current_user) { create(:user) }
let_it_be(:group) { create(:group, :private) }
let_it_be(:iteration) { create(:iteration, group: group) }
let(:query) do
graphql_query_for('iteration', { id: iteration.to_global_id.to_s }, 'title')
end
subject { graphql_data['iteration'] }
before do
post_graphql(query, current_user: current_user)
end
context 'when the user has access to the iteration' do
before_all do
group.add_guest(current_user)
end
it_behaves_like 'a working graphql query'
it { is_expected.to include('title' => iteration.name) }
end
context 'when the user does not have access to the iteration' do
it_behaves_like 'a working graphql query'
it { is_expected.to be_nil }
end
context 'when ID argument is missing' do
let(:query) do
graphql_query_for('iteration', {}, 'title')
end
it 'raises an exception' do
expect(graphql_errors).to include(a_hash_including('message' => "Field 'iteration' is missing required arguments: id"))
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