2018-09-11 19:08:34 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-05-23 07:55:14 +00:00
|
|
|
module Resolvers
|
|
|
|
class BaseResolver < GraphQL::Schema::Resolver
|
2019-12-13 09:08:01 +00:00
|
|
|
extend ::Gitlab::Utils::Override
|
|
|
|
|
2019-01-30 19:00:30 +00:00
|
|
|
def self.single
|
|
|
|
@single ||= Class.new(self) do
|
|
|
|
def resolve(**args)
|
|
|
|
super.first
|
|
|
|
end
|
2019-12-23 12:08:18 +00:00
|
|
|
|
|
|
|
def single?
|
|
|
|
true
|
|
|
|
end
|
2019-01-30 19:00:30 +00:00
|
|
|
end
|
|
|
|
end
|
2019-05-06 21:24:19 +00:00
|
|
|
|
2019-11-14 12:06:30 +00:00
|
|
|
def self.last
|
|
|
|
@last ||= Class.new(self) do
|
|
|
|
def resolve(**args)
|
|
|
|
super.last
|
|
|
|
end
|
2019-12-23 12:08:18 +00:00
|
|
|
|
|
|
|
def single?
|
|
|
|
true
|
|
|
|
end
|
2019-11-14 12:06:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-26 09:08:47 +00:00
|
|
|
def self.complexity
|
|
|
|
0
|
|
|
|
end
|
|
|
|
|
2019-05-31 16:46:16 +00:00
|
|
|
def self.resolver_complexity(args, child_complexity:)
|
2019-05-06 21:24:19 +00:00
|
|
|
complexity = 1
|
|
|
|
complexity += 1 if args[:sort]
|
|
|
|
complexity += 5 if args[:search]
|
|
|
|
|
|
|
|
complexity
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.complexity_multiplier(args)
|
|
|
|
# When fetching many items, additional complexity is added to the field
|
|
|
|
# depending on how many items is fetched. For each item we add 1% of the
|
|
|
|
# original complexity - this means that loading 100 items (our default
|
|
|
|
# maxp_age_size limit) doubles the original complexity.
|
|
|
|
#
|
|
|
|
# Complexity is not increased when searching by specific ID(s), because
|
|
|
|
# complexity difference is minimal in this case.
|
|
|
|
[args[:iid], args[:iids]].any? ? 0 : 0.01
|
|
|
|
end
|
2019-12-13 09:08:01 +00:00
|
|
|
|
|
|
|
override :object
|
|
|
|
def object
|
|
|
|
super.tap do |obj|
|
2019-12-23 12:08:18 +00:00
|
|
|
# If the field this resolver is used in is wrapped in a presenter, unwrap its subject
|
2019-12-13 09:08:01 +00:00
|
|
|
break obj.subject if obj.is_a?(Gitlab::View::Presenter::Base)
|
|
|
|
end
|
|
|
|
end
|
2019-12-23 12:08:18 +00:00
|
|
|
|
|
|
|
def single?
|
|
|
|
false
|
|
|
|
end
|
2020-01-23 00:08:53 +00:00
|
|
|
|
|
|
|
def current_user
|
|
|
|
context[:current_user]
|
|
|
|
end
|
2018-05-23 07:55:14 +00:00
|
|
|
end
|
|
|
|
end
|