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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 lines
1.3 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
2021-10-27 15:23:28 +05:30
include ResolvesIds
2020-01-01 13:55:28 +05:30
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-11-11 11:23:49 +05:30
description: '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-11-11 11:23:49 +05:30
description: 'ID of a project.'
2020-01-01 13:55:28 +05:30
argument :type, Types::Snippets::TypeEnum,
required: false,
2021-11-11 11:23:49 +05:30
description: 'Type of snippet.'
2020-01-01 13:55:28 +05:30
argument :explore,
2021-10-27 15:23:28 +05:30
GraphQL::Types::Boolean,
2020-01-01 13:55:28 +05:30
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)
super
2022-07-16 23:28:13 +05:30
.merge(author: resolve_ids(args[:author_id]),
project: resolve_ids(args[:project_id]),
2020-01-01 13:55:28 +05:30
explore: args[:explore])
end
end
end