2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
module Resolvers
|
|
|
|
class BaseResolver < GraphQL::Schema::Resolver
|
2019-07-07 11:18:12 +05:30
|
|
|
def self.single
|
|
|
|
@single ||= Class.new(self) do
|
|
|
|
def resolve(**args)
|
|
|
|
super.first
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
def self.resolver_complexity(args, child_complexity:)
|
2019-07-31 22:56:46 +05:30
|
|
|
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
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
|
|
|
end
|