class GraphQL::Schema::Validator::InclusionValidator


validates: { inclusion: { in: [2, 3, 5, 7, 11, … ] } }
argument :favorite_prime, Integer, required: true,
@example only allow certain values for an argument
Usually, a {GraphQL::Schema::Enum} is better for this, because it’s self-documenting.
You can use this to allow certain values for an argument.

def initialize(in:, message: "%{validated} is not included in the list", **default_options)

Parameters:
  • in (Array) -- The values to allow
  • message (String) --
def initialize(in:, message: "%{validated} is not included in the list", **default_options)
  # `in` is a reserved word, so work around that
  @in_list = binding.local_variable_get(:in)
  @message = message
  super(**default_options)
end

def validate(_object, _context, value)

def validate(_object, _context, value)
  if permitted_empty_value?(value)
    # pass
  elsif !@in_list.include?(value)
    @message
  end
end