Class: Gitlab::Graphql::Validators::AtLeastOneOfValidator

Inherits:
GraphQL::Schema::Validator
  • Object
show all
Defined in:
lib/gitlab/graphql/validators/at_least_one_of_validator.rb

Instance Method Summary collapse

Constructor Details

#initialize(at_least_one_of_arg_names, **default_options) ⇒ AtLeastOneOfValidator

Returns a new instance of AtLeastOneOfValidator.



7
8
9
10
11
# File 'lib/gitlab/graphql/validators/at_least_one_of_validator.rb', line 7

def initialize(at_least_one_of_arg_names, **default_options)
  @at_least_one_of_arg_names = at_least_one_of_arg_names

  super(**default_options)
end

Instance Method Details

#validate(_object, _context, args) ⇒ Object



13
14
15
16
17
18
# File 'lib/gitlab/graphql/validators/at_least_one_of_validator.rb', line 13

def validate(_object, _context, args)
  return if args.slice(*@at_least_one_of_arg_names).compact.size >= 1

  arg_str = @at_least_one_of_arg_names.map { |x| x.to_s.camelize(:lower) }.join(', ')
  "At least one of [#{arg_str}] arguments is required."
end