2019-12-10 07:53:40 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module ResolvesSnippets
|
|
|
|
extend ActiveSupport::Concern
|
2021-08-10 12:11:00 +00:00
|
|
|
include ResolvesIds
|
2019-12-10 07:53:40 +00:00
|
|
|
|
|
|
|
included do
|
2021-03-17 09:09:27 +00:00
|
|
|
type Types::SnippetType.connection_type, null: true
|
2019-12-10 07:53:40 +00:00
|
|
|
|
2020-11-09 21:08:48 +00:00
|
|
|
argument :ids, [::Types::GlobalIDType[::Snippet]],
|
2019-12-10 07:53:40 +00:00
|
|
|
required: false,
|
2021-02-23 09:10:45 +00:00
|
|
|
description: 'Array of global snippet IDs. For example, `gid://gitlab/ProjectSnippet/1`.'
|
2019-12-10 07:53:40 +00:00
|
|
|
|
|
|
|
argument :visibility, Types::Snippets::VisibilityScopesEnum,
|
|
|
|
required: false,
|
2021-08-18 00:11:18 +00:00
|
|
|
description: 'Visibility of the snippet.'
|
2019-12-10 07:53:40 +00:00
|
|
|
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-08-10 12:11:00 +00:00
|
|
|
ids: resolve_ids(args[:ids], ::Types::GlobalIDType[::Snippet]),
|
2019-12-10 07:53:40 +00:00
|
|
|
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
|