Commit 1285b005 authored by Brett Walker's avatar Brett Walker

Added common fields to the IssueType

and allow passing of child_complexity to the
'resolver_complexity' metho
parent b9798c15
......@@ -10,7 +10,7 @@ module Resolvers
end
end
def self.resolver_complexity(args)
def self.resolver_complexity(args, child_complexity:)
complexity = 1
complexity += 1 if args[:sort]
complexity += 5 if args[:search]
......
......@@ -20,7 +20,7 @@ module ResolvesPipelines
end
class_methods do
def resolver_complexity(args)
def resolver_complexity(args, child_complexity:)
complexity = super
complexity += 2 if args[:sha]
complexity += 2 if args[:ref]
......
......@@ -58,7 +58,7 @@ module Resolvers
IssuesFinder.new(context[:current_user], args).execute
end
def self.resolver_complexity(args)
def self.resolver_complexity(args, child_complexity:)
complexity = super
complexity += 2 if args[:labelName]
......
......@@ -33,7 +33,7 @@ module Types
limit_value = [args[:first], args[:last], page_size].compact.min
# Resolvers may add extra complexity depending on used arguments
complexity = child_complexity + self.resolver&.try(:resolver_complexity, args).to_i
complexity = child_complexity + self.resolver&.try(:resolver_complexity, args, child_complexity: child_complexity).to_i
# Resolvers may add extra complexity depending on number of items being loaded.
multiplier = self.resolver&.try(:complexity_multiplier, args).to_f
......
......@@ -15,6 +15,10 @@ module Types
field :description, GraphQL::STRING_TYPE, null: true
field :state, IssueStateEnum, null: false
field :reference, GraphQL::STRING_TYPE, null: false, method: :to_reference do
argument :full, GraphQL::BOOLEAN_TYPE, required: false, default_value: false
end
field :author, Types::UserType,
null: false,
resolve: -> (obj, _args, _ctx) { Gitlab::Graphql::Loaders::BatchModelLoader.new(User, obj.author_id).find }
......@@ -37,7 +41,9 @@ module Types
field :upvotes, GraphQL::INT_TYPE, null: false
field :downvotes, GraphQL::INT_TYPE, null: false
field :user_notes_count, GraphQL::INT_TYPE, null: false
field :web_path, GraphQL::STRING_TYPE, null: false, method: :issue_path
field :web_url, GraphQL::STRING_TYPE, null: false
field :relative_position, GraphQL::INT_TYPE, null: true
field :closed_at, Types::TimeType, null: true
......
......@@ -4,6 +4,16 @@ class IssuePresenter < Gitlab::View::Presenter::Delegated
presents :issue
def web_url
Gitlab::UrlBuilder.build(issue)
url_builder.url
end
def issue_path
url_builder.issue_path(issue)
end
private
def url_builder
@url_builder ||= Gitlab::UrlBuilder.new(issue)
end
end
---
title: Added reference, web_path, and relative_position fields to GraphQL Issue
merge_request: 28998
author:
type: changed
......@@ -6,7 +6,7 @@ describe Types::BaseField do
context 'when considering complexity' do
let(:resolver) do
Class.new(described_class) do
def self.resolver_complexity(args)
def self.resolver_complexity(args, child_complexity:)
2 if args[:foo]
end
......
......@@ -6,4 +6,10 @@ describe GitlabSchema.types['Issue'] do
it { expect(described_class.graphql_name).to eq('Issue') }
it { expect(described_class).to require_graphql_authorizations(:read_issue) }
it 'has specific fields' do
%i[relative_position web_path web_url reference].each do |field_name|
expect(described_class).to have_graphql_field(field_name)
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe IssuePresenter do
include Gitlab::Routing.url_helpers
let(:user) { create(:user) }
let(:group) { create(:group) }
let(:project) { create(:project, group: group) }
let(:issue) { create(:issue, project: project) }
let(:presenter) { described_class.new(issue, current_user: user) }
before do
group.add_developer(user)
end
describe '#web_url' do
it 'returns correct path' do
expect(presenter.web_url).to eq "http://localhost/#{group.name}/#{project.name}/issues/#{issue.iid}"
end
end
describe '#issue_path' do
it 'returns correct path' do
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