class GraphQL::Schema::Validator::ExclusionValidator
Use this to specifically reject values from an argument.
@example disallow certain values
argument :favorite_non_prime, Integer, required: true, validates: { exclusion: { in: [2, 3, 5, 7, ... ]} }
Public Class Methods
new(message: "%{validated} is reserved", in:, **default_options)
click to toggle source
@param message [String] @param in [Array] The values to reject
Calls superclass method
GraphQL::Schema::Validator::new
# File lib/graphql/schema/validator/exclusion_validator.rb, line 16 def initialize(message: "%{validated} is reserved", in:, **default_options) # `in` is a reserved word, so work around that @in_list = binding.local_variable_get(:in) @message = message super(**default_options) end
Public Instance Methods
validate(_object, _context, value)
click to toggle source
# File lib/graphql/schema/validator/exclusion_validator.rb, line 23 def validate(_object, _context, value) if permitted_empty_value?(value) # pass elsif @in_list.include?(value) @message end end