Class: GraphQL::Schema::Validator::AllowNullValidator
- Inherits:
-
Validator
- Object
- 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).
Examples
Example: require a non-null value for an argument if it is provided
argument :name, String, required: false, validates: { allow_null: false }
Constant Summary collapse
- MESSAGE =
: String
"%{validated} can't be null"
Instance Method Summary collapse
-
#initialize(allow_null_positional = nil, allow_null: nil, message: MESSAGE, **default_options) ⇒ AllowNullValidator
constructor
: (?(bool | Proc | nil) allow_null_positional, ?allow_null: bool | Proc | nil, ?message: String | Proc, **untyped default_options) -> void.
-
#validate(_object, _context, value) ⇒ Object
: (untyped _object, GraphQL::Query::Context _context, untyped value) -> String?.
Constructor Details
#initialize(allow_null_positional = nil, allow_null: nil, message: MESSAGE, **default_options) ⇒ AllowNullValidator
: (?(bool | Proc | nil) allow_null_positional, ?allow_null: bool | Proc | nil, ?message: String | Proc, **untyped default_options) -> void
20 21 22 23 24 |
# File 'lib/graphql/schema/validator/allow_null_validator.rb', line 20 def initialize(allow_null_positional = nil, allow_null: nil, message: MESSAGE, **) = #: String | Proc super(**) @allow_null = allow_null.nil? ? allow_null_positional : allow_null end |
Instance Method Details
#validate(_object, _context, value) ⇒ Object
: (untyped _object, GraphQL::Query::Context _context, untyped value) -> String?
27 28 29 30 31 |
# File 'lib/graphql/schema/validator/allow_null_validator.rb', line 27 def validate(_object, _context, value) if value.nil? && !validation_parameter(@allow_null) validation_parameter() end end |