1# frozen_string_literal: true 2 3module Resolvers 4 class GroupMilestonesResolver < MilestonesResolver 5 argument :include_descendants, GraphQL::Types::Boolean, 6 required: false, 7 description: 'Include milestones from all subgroups and subprojects.' 8 argument :include_ancestors, GraphQL::Types::Boolean, 9 required: false, 10 description: 'Include milestones from all parent groups.' 11 12 type Types::MilestoneType.connection_type, null: true 13 14 private 15 16 def parent_id_parameters(args) 17 include_ancestors = args[:include_ancestors].present? 18 include_descendants = args[:include_descendants].present? 19 return { group_ids: parent.id } unless include_ancestors || include_descendants 20 21 group_ids = if include_ancestors && include_descendants 22 parent.self_and_hierarchy 23 elsif include_ancestors 24 parent.self_and_ancestors 25 else 26 parent.self_and_descendants 27 end 28 29 project_ids = if include_descendants 30 group_projects.with_issues_or_mrs_available_for_user(current_user) 31 else 32 nil 33 end 34 35 { 36 group_ids: group_ids.public_or_visible_to_user(current_user).select(:id), 37 project_ids: project_ids 38 } 39 end 40 41 def group_projects 42 GroupProjectsFinder.new( 43 group: parent, 44 current_user: current_user, 45 options: { include_subgroups: true } 46 ).execute 47 end 48 end 49end 50