summaryrefslogtreecommitdiff
path: root/app/graphql/resolvers/namespace_projects_resolver.rb
blob: e841132eea7c082da2bc1392f81d8909337ecea0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# frozen_string_literal: true

module Resolvers
  class NamespaceProjectsResolver < BaseResolver
    argument :include_subgroups, GraphQL::BOOLEAN_TYPE,
             required: false,
             default_value: false,
             description: 'Include also subgroup projects'

    type Types::ProjectType, null: true

    def resolve(include_subgroups:)
      # The namespace could have been loaded in batch by `BatchLoader`.
      # At this point we need the `id` or the `full_path` of the namespace
      # to query for projects, so make sure it's loaded and not `nil` before continuing.
      namespace = object.respond_to?(:sync) ? object.sync : object
      return Project.none if namespace.nil?

      if include_subgroups
        namespace.all_projects.with_route
      else
        namespace.projects.with_route
      end
    end

    def self.resolver_complexity(args, child_complexity:)
      complexity = super
      complexity + 10
    end
  end
end

Resolvers::NamespaceProjectsResolver.prepend_if_ee('::EE::Resolvers::NamespaceProjectsResolver')