lib/rails/graphql/helpers/with_validator.rb in rails-graphql-0.2.1 vs lib/rails/graphql/helpers/with_validator.rb in rails-graphql-1.0.0.beta

- old
+ new

@@ -1,10 +1,10 @@ # frozen_string_literal: true -module Rails # :nodoc: - module GraphQL # :nodoc: - module Helpers # :nodoc: +module Rails + module GraphQL + module Helpers # Helper that contains the main exceptions and validation process for a # value against a type module WithValidator delegate :ordinalize, to: 'ActiveSupport::Inflector' @@ -20,31 +20,31 @@ return if result.blank? message, idx = result base_error = idx.present? \ - ? "#{ordinalize(idx + 1)} value of the #{gql_name} #{type}" \ - : "#{gql_name} #{type} value" + ? +"#{ordinalize(idx + 1)} value of the #{gql_name} #{type}" \ + : +"#{gql_name} #{type} value" - raise InvalidValueError, "The #{base_error} #{message}." + raise InvalidValueError, +"The #{base_error} #{message}." end private - def validate_array(value) # :nodoc: + def validate_array(value) return 'is not an array' unless value.is_a?(Enumerable) value.each_with_index do |val, idx| err = validate_null(val, :nullable?) || validate_type(val) return err, idx unless err.nil? end end - def validate_null(value, checker = :null?) # :nodoc: + def validate_null(value, checker = :null?) 'can not be null' if value.nil? && !send(checker) end - def validate_type(value) # :nodoc: + def validate_type(value) 'is invalid' if leaf_type? && !type_klass.valid_output?(value) end end end end