Class: GraphQL::Schema::Validator::AllowNullValidator
- Inherits:
-
GraphQL::Schema::Validator
- Object
- GraphQL::Schema::Validator
- GraphQL::Schema::Validator::AllowNullValidator
- Defined in:
- lib/graphql/schema/validator/allow_null_validator.rb
Overview
Use this to specifically reject or permit nil
values (given as null
from GraphQL).
Constant Summary collapse
- MESSAGE =
"%{validated} can't be null"
Constants included from FindInheritedValue::EmptyObjects
FindInheritedValue::EmptyObjects::EMPTY_ARRAY, FindInheritedValue::EmptyObjects::EMPTY_HASH
Instance Attribute Summary
Attributes inherited from GraphQL::Schema::Validator
Instance Method Summary collapse
-
#initialize(allow_null_positional, allow_null: nil, message: MESSAGE, **default_options) ⇒ AllowNullValidator
constructor
A new instance of AllowNullValidator.
- #validate(_object, _context, value) ⇒ Object
Methods inherited from GraphQL::Schema::Validator
from_config, install, #partial_format, #permitted_empty_value?, uninstall, validate!
Constructor Details
#initialize(allow_null_positional, allow_null: nil, message: MESSAGE, **default_options) ⇒ AllowNullValidator
Returns a new instance of AllowNullValidator.
12 13 14 15 16 |
# File 'lib/graphql/schema/validator/allow_null_validator.rb', line 12 def initialize(allow_null_positional, allow_null: nil, message: MESSAGE, **) @message = super(**) @allow_null = allow_null.nil? ? allow_null_positional : allow_null end |
Instance Method Details
#validate(_object, _context, value) ⇒ Object
18 19 20 21 22 |
# File 'lib/graphql/schema/validator/allow_null_validator.rb', line 18 def validate(_object, _context, value) if value.nil? && !@allow_null @message end end |