Class: GraphQL::StaticValidation::LiteralValidator
- Inherits:
-
Object
- Object
- GraphQL::StaticValidation::LiteralValidator
- Defined in:
- lib/graphql/static_validation/literal_validator.rb
Overview
Test whether ‘ast_value` is a valid input for `type`
Instance Method Summary collapse
Instance Method Details
#validate(ast_value, type) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/graphql/static_validation/literal_validator.rb', line 5 def validate(ast_value, type) if type.kind.non_null? (!ast_value.nil?) && validate(ast_value, type.of_type) elsif type.kind.list? item_type = type.of_type ensure_array(ast_value).all? { |val| validate(val, item_type) } elsif type.kind.scalar? && !ast_value.is_a?(GraphQL::Language::Nodes::AbstractNode) && !ast_value.is_a?(Array) type.valid_input?(ast_value) elsif type.kind.enum? && ast_value.is_a?(GraphQL::Language::Nodes::Enum) type.valid_input?(ast_value.name) elsif type.kind.input_object? && ast_value.is_a?(GraphQL::Language::Nodes::InputObject) required_input_fields_are_present(type, ast_value) && present_input_field_values_are_valid(type, ast_value) elsif ast_value.is_a?(GraphQL::Language::Nodes::VariableIdentifier) true else false end end |