class GraphQL::Schema::Validation

This module provides a function for validating GraphQL types.

Its {RULES} contain objects that respond to `#call(type)`. Rules are looked up for given types (by class ancestry), then applied to the object until an error is returned.

Remove this in GraphQL-Ruby 2.0 when schema instances are removed.

Constants

RULES

A mapping of `{Class => [Proc, Proc…]}` pairs. To validate an instance, find entries where `object.is_a?(key)` is true. Then apply each rule from the matching values.

Public Class Methods

validate(object) click to toggle source

Lookup the rules for `object` based on its class, Then returns an error message or `nil` @param object [Object] something to be validated @return [String, Nil] error message, if there was one

# File lib/graphql/schema/validation.rb, line 16
def self.validate(object)
  RULES.each do |parent_class, validations|
    if object.is_a?(parent_class)
      validations.each do |rule|
        if error = rule.call(object)
          return error
        end
      end
    end
  end
  nil
end