Sha256: b4080bbb9fa6b0ef10dc16e92212f8e705e69c93de857685d801165b160f9102
Contents?: true
Size: 1006 Bytes
Versions: 1
Compression:
Stored size: 1006 Bytes
Contents
# Test whether `ast_value` is a valid input for `type` class GraphQL::StaticValidation::LiteralValidator include GraphQL::StaticValidation::Message::MessageHelper attr_reader :errors def validate(ast_value, type) if type.kind.non_null? (!ast_value.nil?) && validate(ast_value, type.of_type) elsif type.kind.list? && ast_value.is_a?(Array) item_type = type.of_type ast_value.all? { |val| validate(val, item_type) } elsif type.kind.scalar? !type.coerce(ast_value).nil? elsif type.kind.enum? && ast_value.is_a?(GraphQL::Nodes::Enum) !type.coerce(ast_value.name).nil? elsif type.kind.input_object? && ast_value.is_a?(GraphQL::Nodes::InputObject) fields = type.input_fields ast_value.pairs.all? do |value| field_type = fields[value.name].type present_if_required = field_type.kind.non_null? ? !value.nil? : true present_if_required && validate(value.value, field_type) end else false end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
graphql-0.2.0 | lib/graph_ql/static_validation/literal_validator.rb |