Commit cd748e15 authored by Alexandru Croitor's avatar Alexandru Croitor

Extend attributes returned by graphql query for MRs

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

https://gitlab.com/gitlab-org/gitlab/issues/20829
parent 31a2c541
......@@ -55,12 +55,27 @@ module Types
field :web_url, GraphQL::STRING_TYPE, null: true # rubocop:disable Graphql/Descriptions
field :upvotes, GraphQL::INT_TYPE, null: false # rubocop:disable Graphql/Descriptions
field :downvotes, GraphQL::INT_TYPE, null: false # rubocop:disable Graphql/Descriptions
field :subscribed, GraphQL::BOOLEAN_TYPE, method: :subscribed?, null: false # rubocop:disable Graphql/Descriptions
field :head_pipeline, Types::Ci::PipelineType, null: true, method: :actual_head_pipeline # rubocop:disable Graphql/Descriptions
field :pipelines, Types::Ci::PipelineType.connection_type, # rubocop:disable Graphql/Descriptions
resolver: Resolvers::MergeRequestPipelinesResolver
field :milestone, Types::MilestoneType, description: 'The milestone this merge request is linked to',
null: true,
resolve: -> (obj, _args, _ctx) { Gitlab::Graphql::Loaders::BatchModelLoader.new(Milestone, obj.milestone_id).find }
field :assignees, Types::UserType.connection_type, null: true, complexity: 5, description: 'The list of assignees for the merge request'
field :participants, Types::UserType.connection_type, null: true, complexity: 5, description: 'The list of participants on the merge request'
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 MR'
field :labels, Types::LabelType.connection_type, null: true, complexity: 5, description: 'The list of labels on the merge request'
field :discussion_locked, GraphQL::BOOLEAN_TYPE, description: 'Boolean flag determining if comments on the merge request are locked to members only',
null: false,
resolve: -> (obj, _args, _ctx) { !!obj.discussion_locked }
field :time_estimate, GraphQL::INT_TYPE, null: false, description: 'The time estimate for the merge request'
field :total_time_spent, GraphQL::INT_TYPE, null: false, description: 'Total time reported as spent on the merge request'
field :reference, GraphQL::STRING_TYPE, null: false, method: :to_reference, description: 'Internal merge request reference. Returned in shortened format by default' do
argument :full, GraphQL::BOOLEAN_TYPE, required: false, default_value: false, description: 'Boolean option specifying whether the reference should be returned in full'
end
field :task_completion_status, Types::TaskCompletionStatus, null: false # rubocop:disable Graphql/Descriptions
end
end
---
title: Extend graphql query endpoint for merge requests to return more attributes to support sidebar implementation
merge_request: 17813
author:
type: other
......@@ -435,8 +435,13 @@ The API can be explored interactively using the [GraphiQL IDE](../index.md#graph
| `webUrl` | String | |
| `upvotes` | Int! | |
| `downvotes` | Int! | |
| `subscribed` | Boolean! | |
| `headPipeline` | Pipeline | |
| `milestone` | Milestone | The milestone this merge request is linked to |
| `subscribed` | Boolean! | Boolean flag for whether the currently logged in user is subscribed to this MR |
| `discussionLocked` | Boolean! | Boolean flag determining if comments on the merge request are locked to members only |
| `timeEstimate` | Int! | The time estimate for the merge request |
| `totalTimeSpent` | Int! | Total time reported as spent on the merge request |
| `reference` | String! | Internal merge request reference. Returned in shortened format by default |
| `taskCompletionStatus` | TaskCompletionStatus! | |
### MergeRequestPermissions
......
......@@ -20,7 +20,9 @@ describe GitlabSchema.types['MergeRequest'] do
merge_error allow_collaboration should_be_rebased rebase_commit_sha
rebase_in_progress merge_commit_message default_merge_commit_message
merge_ongoing source_branch_exists mergeable_discussions_state web_url
upvotes downvotes subscribed head_pipeline pipelines task_completion_status
upvotes downvotes head_pipeline pipelines task_completion_status
milestone assignees participants subscribed labels discussion_locked time_estimate
total_time_spent reference
]
is_expected.to have_graphql_fields(*expected_fields)
......
......@@ -45,4 +45,22 @@ describe GitlabSchema.types['Project'] do
is_expected.to have_graphql_resolver(Resolvers::IssuesResolver)
end
end
describe 'merge_requests field' do
subject { described_class.fields['mergeRequest'] }
it 'returns merge requests' do
is_expected.to have_graphql_type(Types::MergeRequestType)
is_expected.to have_graphql_resolver(Resolvers::MergeRequestsResolver.single)
end
end
describe 'merge_request field' do
subject { described_class.fields['mergeRequests'] }
it 'returns merge request' do
is_expected.to have_graphql_type(Types::MergeRequestType.connection_type)
is_expected.to have_graphql_resolver(Resolvers::MergeRequestsResolver)
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