debian-mirror-gitlab/app/graphql/resolvers/concerns/resolves_snippets.rb

47 lines
1.1 KiB
Ruby
Raw Normal View History

2020-01-01 13:55:28 +05:30
# frozen_string_literal: true
module ResolvesSnippets
extend ActiveSupport::Concern
2021-10-27 15:23:28 +05:30
include ResolvesIds
2020-01-01 13:55:28 +05:30
included do
2021-04-29 21:17:54 +05:30
type Types::SnippetType.connection_type, null: true
2020-01-01 13:55:28 +05:30
2021-01-29 00:20:46 +05:30
argument :ids, [::Types::GlobalIDType[::Snippet]],
2020-01-01 13:55:28 +05:30
required: false,
2021-04-17 20:07:23 +05:30
description: 'Array of global snippet IDs. For example, `gid://gitlab/ProjectSnippet/1`.'
2020-01-01 13:55:28 +05:30
argument :visibility, Types::Snippets::VisibilityScopesEnum,
required: false,
2021-10-27 15:23:28 +05:30
description: 'Visibility of the snippet.'
2020-01-01 13:55:28 +05:30
end
def resolve(**args)
resolve_snippets(args)
end
private
def resolve_snippets(args)
SnippetsFinder.new(context[:current_user], snippet_finder_params(args)).execute
end
def snippet_finder_params(args)
{
2021-10-27 15:23:28 +05:30
ids: resolve_ids(args[:ids], ::Types::GlobalIDType[::Snippet]),
2020-01-01 13:55:28 +05:30
scope: args[:visibility]
}.merge(options_by_type(args[:type]))
end
def options_by_type(type)
case type
when 'personal'
{ only_personal: true }
when 'project'
{ only_project: true }
else
{}
end
end
end