2019-12-10 02:53:40 -05:00
|
|
|
# frozen_string_literal: true
|
2020-11-17 07:09:15 -05:00
|
|
|
# rubocop:disable Graphql/ResolverType (inherited from ResolvesSnippets)
|
2019-12-10 02:53:40 -05:00
|
|
|
|
|
|
|
module Resolvers
|
|
|
|
class SnippetsResolver < BaseResolver
|
2021-08-10 08:11:00 -04:00
|
|
|
include ResolvesIds
|
2019-12-10 02:53:40 -05:00
|
|
|
include ResolvesSnippets
|
|
|
|
|
|
|
|
ERROR_MESSAGE = 'Filtering by both an author and a project is not supported'
|
|
|
|
|
|
|
|
alias_method :user, :object
|
|
|
|
|
2020-11-09 16:08:48 -05:00
|
|
|
argument :author_id, ::Types::GlobalIDType[::User],
|
2019-12-10 02:53:40 -05:00
|
|
|
required: false,
|
2021-08-19 14:10:32 -04:00
|
|
|
description: 'ID of an author.'
|
2019-12-10 02:53:40 -05:00
|
|
|
|
2020-11-09 16:08:48 -05:00
|
|
|
argument :project_id, ::Types::GlobalIDType[::Project],
|
2019-12-10 02:53:40 -05:00
|
|
|
required: false,
|
2021-08-19 14:10:32 -04:00
|
|
|
description: 'ID of a project.'
|
2019-12-10 02:53:40 -05:00
|
|
|
|
|
|
|
argument :type, Types::Snippets::TypeEnum,
|
|
|
|
required: false,
|
2021-08-19 14:10:32 -04:00
|
|
|
description: 'Type of snippet.'
|
2019-12-10 02:53:40 -05:00
|
|
|
|
|
|
|
argument :explore,
|
2021-07-22 08:10:04 -04:00
|
|
|
GraphQL::Types::Boolean,
|
2019-12-10 02:53:40 -05:00
|
|
|
required: false,
|
2021-01-11 19:10:42 -05:00
|
|
|
description: 'Explore personal snippets.'
|
2019-12-10 02:53:40 -05:00
|
|
|
|
|
|
|
def resolve(**args)
|
|
|
|
if args[:author_id].present? && args[:project_id].present?
|
|
|
|
raise Gitlab::Graphql::Errors::ArgumentError, ERROR_MESSAGE
|
|
|
|
end
|
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def snippet_finder_params(args)
|
|
|
|
super
|
2022-05-10 14:08:27 -04:00
|
|
|
.merge(author: resolve_ids(args[:author_id]),
|
|
|
|
project: resolve_ids(args[:project_id]),
|
2019-12-10 02:53:40 -05:00
|
|
|
explore: args[:explore])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|