Class: Resolvers::BaseResolver

Inherits:
GraphQL::Schema::Resolver
  • Object
show all
Extended by:
Gitlab::Utils::Override
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/graphql/resolvers/base_resolver.rb

Direct Known Subclasses

Admin::Analytics::InstanceStatistics::MeasurementsResolver, AlertManagement::AlertResolver, AlertManagement::AlertStatusCountsResolver, BoardListIssuesResolver, BoardListsResolver, BoardsResolver, BranchCommitResolver, Ci::PipelineStagesResolver, CommitPipelinesResolver, DesignManagement::DesignAtVersionResolver, DesignManagement::DesignResolver, DesignManagement::DesignsResolver, DesignManagement::Version::DesignAtVersionResolver, DesignManagement::Version::DesignsAtVersionResolver, DesignManagement::VersionInCollectionResolver, DesignManagement::VersionResolver, DesignManagement::VersionsResolver, EchoResolver, EnvironmentsResolver, ErrorTracking::SentryDetailedErrorResolver, ErrorTracking::SentryErrorCollectionResolver, ErrorTracking::SentryErrorStackTraceResolver, ErrorTracking::SentryErrorsResolver, GroupResolver, IssueStatusCountsResolver, IssuesResolver, LastCommitResolver, MergeRequestPipelinesResolver, MergeRequestsResolver, MetadataResolver, Metrics::DashboardResolver, Metrics::Dashboards::AnnotationResolver, MilestonesResolver, NamespaceProjectsResolver, NamespaceResolver, PackagesResolver, ProjectMembersResolver, ProjectPipelineResolver, ProjectPipelinesResolver, ProjectResolver, Projects::GrafanaIntegrationResolver, Projects::JiraImportsResolver, Projects::JiraProjectsResolver, Projects::ServicesResolver, Projects::SnippetsResolver, ProjectsResolver, ReleaseResolver, ReleasesResolver, SnippetsResolver, TodoResolver, TreeResolver, UserResolver, UserStarredProjectsResolver, Users::SnippetsResolver, UsersResolver

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Utils::Override

extended, extensions, included, method_added, override, prepended, queue_verification, verify!

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Class Method Details

.complexityObject


37
38
39
# File 'app/graphql/resolvers/base_resolver.rb', line 37

def self.complexity
  0
end

.complexity_multiplier(args) ⇒ Object


49
50
51
52
53
54
55
56
57
58
# File 'app/graphql/resolvers/base_resolver.rb', line 49

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

.lastObject


29
30
31
32
33
34
35
# File 'app/graphql/resolvers/base_resolver.rb', line 29

def self.last
  @last ||= Class.new(self.single) do
    def select_result(results)
      results&.last
    end
  end
end

.resolver_complexity(args, child_complexity:) ⇒ Object


41
42
43
44
45
46
47
# File 'app/graphql/resolvers/base_resolver.rb', line 41

def self.resolver_complexity(args, child_complexity:)
  complexity = 1
  complexity += 1 if args[:sort]
  complexity += 5 if args[:search]

  complexity
end

.singleObject


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/graphql/resolvers/base_resolver.rb', line 8

def self.single
  @single ||= Class.new(self) do
    def ready?(**args)
      ready, early_return = super
      [ready, select_result(early_return)]
    end

    def resolve(**args)
      select_result(super)
    end

    def single?
      true
    end

    def select_result(results)
      results&.first
    end
  end
end

Instance Method Details

#current_userObject


83
84
85
# File 'app/graphql/resolvers/base_resolver.rb', line 83

def current_user
  context[:current_user]
end

#objectObject


61
62
63
64
65
66
# File 'app/graphql/resolvers/base_resolver.rb', line 61

def object
  super.tap do |obj|
    # If the field this resolver is used in is wrapped in a presenter, unwrap its subject
    break obj.subject if obj.is_a?(Gitlab::View::Presenter::Base)
  end
end

#select_result(results) ⇒ Object

Overridden in sub-classes (see .single, .last)


88
89
90
# File 'app/graphql/resolvers/base_resolver.rb', line 88

def select_result(results)
  results
end

#single?Boolean

Returns:

  • (Boolean)

79
80
81
# File 'app/graphql/resolvers/base_resolver.rb', line 79

def single?
  false
end

#synchronized_objectObject


68
69
70
71
72
73
74
75
76
77
# File 'app/graphql/resolvers/base_resolver.rb', line 68

def synchronized_object
  strong_memoize(:synchronized_object) do
    case object
    when BatchLoader::GraphQL
      object.sync
    else
      object
    end
  end
end