debian-mirror-gitlab/app/graphql/resolvers/snippets_resolver.rb

49 lines
1.5 KiB
Ruby
Raw Normal View History

2020-01-01 13:55:28 +05:30
# frozen_string_literal: true
2021-01-29 00:20:46 +05:30
# rubocop:disable Graphql/ResolverType (inherited from ResolvesSnippets)
2020-01-01 13:55:28 +05:30
module Resolvers
class SnippetsResolver < BaseResolver
include ResolvesSnippets
ERROR_MESSAGE = 'Filtering by both an author and a project is not supported'
alias_method :user, :object
2021-01-29 00:20:46 +05:30
argument :author_id, ::Types::GlobalIDType[::User],
2020-01-01 13:55:28 +05:30
required: false,
2021-03-08 18:12:59 +05:30
description: 'The ID of an author.'
2020-01-01 13:55:28 +05:30
2021-01-29 00:20:46 +05:30
argument :project_id, ::Types::GlobalIDType[::Project],
2020-01-01 13:55:28 +05:30
required: false,
2021-03-08 18:12:59 +05:30
description: 'The ID of a project.'
2020-01-01 13:55:28 +05:30
argument :type, Types::Snippets::TypeEnum,
required: false,
2021-03-08 18:12:59 +05:30
description: 'The type of snippet.'
2020-01-01 13:55:28 +05:30
argument :explore,
GraphQL::BOOLEAN_TYPE,
required: false,
2021-03-08 18:12:59 +05:30
description: 'Explore personal snippets.'
2020-01-01 13:55:28 +05:30
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)
2021-01-29 00:20:46 +05:30
# TODO: remove the type arguments when the compatibility layer is removed
# See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883
2020-01-01 13:55:28 +05:30
super
2021-01-29 00:20:46 +05:30
.merge(author: resolve_ids(args[:author_id], ::Types::GlobalIDType[::User]),
project: resolve_ids(args[:project_id], ::Types::GlobalIDType[::Project]),
2020-01-01 13:55:28 +05:30
explore: args[:explore])
end
end
end