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

spammable_mutation_fields.rb « mutations « concerns « mutations « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e5df85656183d8c2814f303678aee073bda9eb20 (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
# frozen_string_literal: true

module Mutations
  module SpammableMutationFields
    extend ActiveSupport::Concern

    included do
      field :spam,
            GraphQL::BOOLEAN_TYPE,
            null: true,
            description: 'Indicates whether the operation returns a record detected as spam.'
    end

    def with_spam_params(&block)
      request = Feature.enabled?(:snippet_spam) ? context[:request] : nil

      yield.merge({ api: true, request: request })
    end

    def with_spam_fields(spammable, &block)
      { spam: spammable.spam? }.merge!(yield)
    end
  end
end