Welcome to mirror list, hosted at ThFree Co, Russian Federation.

snippets_resolver.rb « resolvers « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 149bd8fa1ce32f7d51599076b71cfb65093a8c03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true
# rubocop:disable Graphql/ResolverType (inherited from ResolvesSnippets)

module Resolvers
  class SnippetsResolver < BaseResolver
    include ResolvesIds
    include ResolvesSnippets

    ERROR_MESSAGE = 'Filtering by both an author and a project is not supported'

    alias_method :user, :object

    argument :author_id, ::Types::GlobalIDType[::User],
              required: false,
              description: 'ID of an author.'

    argument :project_id, ::Types::GlobalIDType[::Project],
              required: false,
              description: 'ID of a project.'

    argument :type, Types::Snippets::TypeEnum,
              required: false,
              description: 'Type of snippet.'

    argument :explore,
              GraphQL::Types::Boolean,
              required: false,
              description: 'Explore personal snippets.'

    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)
      # TODO: remove the type arguments when the compatibility layer is removed
      # See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883
      super
        .merge(author: resolve_ids(args[:author_id], ::Types::GlobalIDType[::User]),
               project: resolve_ids(args[:project_id], ::Types::GlobalIDType[::Project]),
               explore: args[:explore])
    end
  end
end