Commit 7c658352 authored by Alexandru Croitor's avatar Alexandru Croitor Committed by Stan Hu

Add more attributes to issues GraphQL endpoint

In order to support realtime sidebars and continue to complete
the GraphQL API, added additional attributes to be returned
for IssueType.

https://gitlab.com/gitlab-org/gitlab/issues/20718
parent af80dec7
# frozen_string_literal: true
module Types
class ExtendedIssueType < IssueType
graphql_name 'ExtendedIssue'
authorize :read_issue
expose_permissions Types::PermissionTypes::Issue
present_using IssuePresenter
field :subscribed, GraphQL::BOOLEAN_TYPE, method: :subscribed?, null: false, complexity: 5,
description: 'Boolean flag for whether the currently logged in user is subscribed to this issue'
end
end
......@@ -49,6 +49,11 @@ module Types
field :web_url, GraphQL::STRING_TYPE, null: false # rubocop:disable Graphql/Descriptions
field :relative_position, GraphQL::INT_TYPE, null: true # rubocop:disable Graphql/Descriptions
field :epic, ::Types::EpicType, null: true, description: 'The epic to which issue belongs'
field :participants, Types::UserType.connection_type, null: true, complexity: 5, description: 'List of participants for the issue'
field :time_estimate, GraphQL::INT_TYPE, null: false, description: 'The time estimate on the issue'
field :total_time_spent, GraphQL::INT_TYPE, null: false, description: 'Total time reported as spent on the issue'
field :closed_at, Types::TimeType, null: true # rubocop:disable Graphql/Descriptions
field :created_at, Types::TimeType, null: false # rubocop:disable Graphql/Descriptions
......
......@@ -92,7 +92,7 @@ module Types
resolver: Resolvers::IssuesResolver
field :issue, # rubocop:disable Graphql/Descriptions
Types::IssueType,
Types::ExtendedIssueType,
null: true,
resolver: Resolvers::IssuesResolver.single
......
......@@ -11,6 +11,10 @@ class IssuePresenter < Gitlab::View::Presenter::Delegated
url_builder.issue_path(issue)
end
def subscribed?
issue.subscribed?(current_user, issue.project)
end
private
def url_builder
......
---
title: Add more attributes to issues GraphQL endpoint
merge_request: 17802
author:
type: changed
require 'spec_helper'
describe GitlabSchema.types['ExtendedIssue'] do
it { expect(described_class).to expose_permissions_using(Types::PermissionTypes::Issue) }
it { expect(described_class.graphql_name).to eq('ExtendedIssue') }
it { expect(described_class).to require_graphql_authorizations(:read_issue) }
it { expect(described_class.interfaces).to include(Types::Notes::NoteableType.to_graphql) }
it 'has specific fields' do
fields = Types::IssueType.fields.keys + [:subscribed]
fields.each do |field_name|
expect(described_class).to have_graphql_field(field_name)
end
end
end
......@@ -10,8 +10,9 @@ describe GitlabSchema.types['Issue'] do
it { expect(described_class.interfaces).to include(Types::Notes::NoteableType.to_graphql) }
it 'has specific fields' do
fields = %i[title_html description_html relative_position web_path web_url
reference]
fields = %i[iid title description state reference author assignees participants labels epic milestone due_date
confidential discussion_locked upvotes downvotes user_notes_count web_path web_url relative_position
time_estimate total_time_spent closed_at created_at updated_at task_completion_status]
fields.each do |field_name|
expect(described_class).to have_graphql_field(field_name)
......
......@@ -25,4 +25,22 @@ describe GitlabSchema.types['Project'] do
is_expected.to have_graphql_fields(*expected_fields)
end
describe 'issue field' do
subject { described_class.fields['issue'] }
it 'returns issue' do
is_expected.to have_graphql_type(Types::ExtendedIssueType)
is_expected.to have_graphql_resolver(Resolvers::IssuesResolver.single)
end
end
describe 'issues field' do
subject { described_class.fields['issues'] }
it 'returns issue' do
is_expected.to have_graphql_type(Types::IssueType.connection_type)
is_expected.to have_graphql_resolver(Resolvers::IssuesResolver)
end
end
end
......@@ -17,13 +17,27 @@ describe IssuePresenter do
describe '#web_url' do
it 'returns correct path' do
expect(presenter.web_url).to eq "http://localhost/#{group.name}/#{project.name}/issues/#{issue.iid}"
expect(presenter.web_url).to eq("http://localhost/#{group.name}/#{project.name}/issues/#{issue.iid}")
end
end
describe '#subscribed?' do
subject { presenter.subscribed? }
it 'returns not subscribed' do
is_expected.to be(false)
end
it 'returns subscribed' do
create(:subscription, user: user, project: project, subscribable: issue, subscribed: true)
is_expected.to be(true)
end
end
describe '#issue_path' do
it 'returns correct path' do
expect(presenter.issue_path).to eq "/#{group.name}/#{project.name}/issues/#{issue.iid}"
expect(presenter.issue_path).to eq("/#{group.name}/#{project.name}/issues/#{issue.iid}")
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