class GraphQL::Schema::Validator::InclusionValidator
You can use this to allow certain values for an argument.
Usually, a GraphQL::Schema::Enum is better for this, because itโs self-documenting.
Examples
Example: only allow certain values for an argument
argument :favorite_prime, Integer, required: true, validates: { inclusion: { in: [2, 3, 5, 7, 11, ... ] } }
Public Class Methods
# File lib/graphql/schema/validator/inclusion_validator.rb, line 27 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
Parameters
-
message(String) -
in(Array) โ The values to allow
Calls superclass method
GraphQL::Schema::Validator::new
Public Instance Methods
# File lib/graphql/schema/validator/inclusion_validator.rb, line 34 def validate(_object, _context, value) if permitted_empty_value?(value) # pass elsif !validation_parameter(@in_list).include?(value) validation_parameter(@message) end end