Commit 8d4c9ea1 authored by Felipe Artur's avatar Felipe Artur Committed by Jan Provaznik

Expose 'subscribed' for epics in GraphQL

Exposes subscribed attribute for epics in GraphQL
parent 5fee3ef6
...@@ -211,6 +211,7 @@ The API can be explored interactively using the [GraphiQL IDE](../index.md#graph ...@@ -211,6 +211,7 @@ The API can be explored interactively using the [GraphiQL IDE](../index.md#graph
| `relativePosition` | Int | The relative position of the epic in the Epic tree | | `relativePosition` | Int | The relative position of the epic in the Epic tree |
| `relationPath` | String | | | `relationPath` | String | |
| `reference` | String! | | | `reference` | String! | |
| `subscribed` | Boolean! | Boolean flag for whether the currently logged in user is subscribed to this epic |
### EpicIssue ### EpicIssue
......
...@@ -58,6 +58,12 @@ module Types ...@@ -58,6 +58,12 @@ module Types
argument :full, GraphQL::BOOLEAN_TYPE, required: false, default_value: false # rubocop:disable Graphql/Descriptions argument :full, GraphQL::BOOLEAN_TYPE, required: false, default_value: false # rubocop:disable Graphql/Descriptions
end end
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 epic'
field :issues, # rubocop:disable Graphql/Descriptions field :issues, # rubocop:disable Graphql/Descriptions
Types::EpicIssueType.connection_type, Types::EpicIssueType.connection_type,
null: true, null: true,
......
...@@ -35,13 +35,17 @@ class EpicPresenter < Gitlab::View::Presenter::Delegated ...@@ -35,13 +35,17 @@ class EpicPresenter < Gitlab::View::Presenter::Delegated
end end
end end
def subscribed?
epic.subscribed?(current_user)
end
private private
def initial_data def initial_data
{ {
labels: epic.labels, labels: epic.labels,
participants: participants, participants: participants,
subscribed: epic.subscribed?(current_user) subscribed: subscribed?
} }
end end
......
---
title: Expose subscribed attribute for Epics in GraphQL
merge_request: 18607
author:
type: added
...@@ -10,7 +10,7 @@ describe GitlabSchema.types['Epic'] do ...@@ -10,7 +10,7 @@ describe GitlabSchema.types['Epic'] do
due_date due_date_is_fixed due_date_fixed due_date_from_milestones due_date due_date_is_fixed due_date_fixed due_date_from_milestones
closed_at created_at updated_at children has_children has_issues closed_at created_at updated_at children has_children has_issues
web_path web_url relation_path reference issues web_path web_url relation_path reference issues
user_permissions notes discussions relative_position user_permissions notes discussions relative_position subscribed
] ]
end end
...@@ -21,4 +21,6 @@ describe GitlabSchema.types['Epic'] do ...@@ -21,4 +21,6 @@ describe GitlabSchema.types['Epic'] do
it { expect(described_class).to require_graphql_authorizations(:read_epic) } it { expect(described_class).to require_graphql_authorizations(:read_epic) }
it { expect(described_class).to have_graphql_fields(fields) } it { expect(described_class).to have_graphql_fields(fields) }
it { is_expected.to have_graphql_field(:subscribed, complexity: 5) }
end end
...@@ -7,6 +7,6 @@ describe GitlabSchema.types['DiffPosition'] do ...@@ -7,6 +7,6 @@ describe GitlabSchema.types['DiffPosition'] do
:new_path, :position_type, :old_line, :new_line, :x, :y, :new_path, :position_type, :old_line, :new_line, :x, :y,
:width, :height] :width, :height]
is_expected.to have_graphql_field(*expected_fields) is_expected.to have_graphql_fields(*expected_fields)
end end
end end
...@@ -28,9 +28,15 @@ RSpec::Matchers.define :have_graphql_fields do |*expected| ...@@ -28,9 +28,15 @@ RSpec::Matchers.define :have_graphql_fields do |*expected|
end end
end end
RSpec::Matchers.define :have_graphql_field do |field_name| RSpec::Matchers.define :have_graphql_field do |field_name, args = {}|
match do |kls| match do |kls|
expect(kls.fields.keys).to include(GraphqlHelpers.fieldnamerize(field_name)) field = kls.fields[GraphqlHelpers.fieldnamerize(field_name)]
expect(field).to be_present
args.each do |argument, value|
expect(field.send(argument)).to eq(value)
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