1# frozen_string_literal: true 2 3module Mutations 4 module ResolvesResourceParent 5 extend ActiveSupport::Concern 6 include Mutations::ResolvesGroup 7 include ResolvesProject 8 9 included do 10 argument :project_path, GraphQL::Types::ID, 11 required: false, 12 description: 'Full path of the project with which the resource is associated.' 13 14 argument :group_path, GraphQL::Types::ID, 15 required: false, 16 description: 'Full path of the group with which the resource is associated.' 17 end 18 19 def ready?(**args) 20 unless args[:project_path].present? ^ args[:group_path].present? 21 raise Gitlab::Graphql::Errors::ArgumentError, 22 'Exactly one of group_path or project_path arguments is required' 23 end 24 25 super 26 end 27 28 private 29 30 def authorized_resource_parent_find!(args) 31 authorized_find!(project_path: args.delete(:project_path), 32 group_path: args.delete(:group_path)) 33 end 34 35 def find_object(project_path: nil, group_path: nil) 36 if group_path.present? 37 resolve_group(full_path: group_path) 38 else 39 resolve_project(full_path: project_path) 40 end 41 end 42 end 43end 44