lib/graphql/static_validation/validator.rb
def validate(query, validate: true, timeout: nil)
        query.trace("validate", { validate: validate, query: query }) do
          can_skip_rewrite = query.context.interpreter? && query.schema.using_ast_analysis? && query.schema.is_a?(Class)
          errors = if validate == false && can_skip_rewrite
            []
          else
            rules_to_use = validate ? @rules : []
            visitor_class = BaseVisitor.including_rules(rules_to_use, rewrite: !can_skip_rewrite)

            context = GraphQL::StaticValidation::ValidationContext.new(query, visitor_class)

            begin
              # CAUTION: Usage of the timeout module makes the assumption that validation rules are stateless Ruby code that requires no cleanup if process was interrupted. This means no blocking IO calls, native gems, locks, or `rescue` clauses that must be reached.
              # A timeout value of 0 or nil will execute the block without any timeout.
              Timeout::timeout(timeout) do
                # Attach legacy-style rules.
                # Only loop through rules if it has legacy-style rules
                unless (legacy_rules = rules_to_use - GraphQL::StaticValidation::ALL_RULES).empty?
                  legacy_rules.each do |rule_class_or_module|
                    if rule_class_or_module.method_defined?(:validate)
                      rule_class_or_module.new.validate(context)
                    end
                  end
                end

                context.visitor.visit
              end
            rescue Timeout::Error
              handle_timeout(query, context)
            end

            context.errors
          end

          irep = if errors.empty? && context
            # Only return this if there are no errors and validation was actually run
            context.visitor.rewrite_document
          else
            nil
          end

          {
            errors: errors,
            irep: irep,
          }
        end
      end
# Validate `query` against the schema. Returns an array of message hashes.
# @param query [GraphQL::Query]
# @param validate [Boolean]
# @param timeout [Float] Number of seconds to wait before aborting validation. Any positive number may be used, including Floats to specify fractional seconds.
# @return [Array<Hash>]
Validate `query` against the schema. Returns an array of message hashes.
Validate ` query ` against the schema . Returns an array of message hashes .
def validate(query, validate: true, timeout: nil)
        query.trace("validate", { validate: validate, query: query }) do
          can_skip_rewrite = query.context.interpreter? && query.schema.using_ast_analysis? && query.schema.is_a?(Class)
          errors = if validate == false && can_skip_rewrite
            []
          else
            rules_to_use = validate ? @rules : []
            visitor_class = BaseVisitor.including_rules(rules_to_use, rewrite: !can_skip_rewrite)
            context = GraphQL::StaticValidation::ValidationContext.new(query, visitor_class)
            begin
              Timeout::timeout(timeout) do
                unless (legacy_rules = rules_to_use - GraphQL::StaticValidation::ALL_RULES).empty?
                  legacy_rules.each do |rule_class_or_module|
                    if rule_class_or_module.method_defined?(:validate)
                      rule_class_or_module.new.validate(context)
                    end
                  end
                end
                context.visitor.visit
              end
            rescue Timeout::Error
              handle_timeout(query, context)
            end
            context.errors
          end
          irep = if errors.empty? && context
            context.visitor.rewrite_document
          else
            nil
          end
          {
            errors: errors,
            irep: irep,
          }
        end
      end
def validate ( query , validate : true , timeout : nil ) query . trace ( "validate" , { validate : validate , query : query } ) do can_skip_rewrite = query . context . interpreter? && query . schema . using_ast_analysis? && query . schema . is_a? ( Class ) errors = if validate == false && can_skip_rewrite [ ] else rules_to_use = validate ? @rules : [ ] visitor_class = BaseVisitor . including_rules ( rules_to_use , rewrite : ! can_skip_rewrite ) context = GraphQL :: StaticValidation :: ValidationContext . new ( query , visitor_class ) begin Timeout :: timeout ( timeout ) do unless ( legacy_rules = rules_to_use - GraphQL :: StaticValidation :: ALL_RULES ) . empty? legacy_rules . each do | rule_class_or_module | if rule_class_or_module . method_defined? ( :validate ) rule_class_or_module . new . validate ( context ) end end end context . visitor . visit end rescue Timeout :: Error handle_timeout ( query , context ) end context . errors end irep = if errors . empty? && context context . visitor . rewrite_document else nil end { errors : errors , irep : irep , } end end
Validate `query` against the schema.
Validate ` query ` against the schema .
# CAUTION: Usage of the timeout module makes the assumption that validation rules are stateless Ruby code that requires no cleanup if process was interrupted. This means no blocking IO calls, native gems, locks, or `rescue` clauses that must be reached. # A timeout value of 0 or nil will execute the block without any timeout. # Attach legacy-style rules. # Only loop through rules if it has legacy-style rules # Only return this if there are no errors and validation was actually run
None
Array<Hash>
query
validate
timeout
Number of seconds to wait before aborting validation. Any positive number may be used, including Floats to specify fractional seconds.
Number of seconds to wait before aborting validation . Any positive number may be used including Floats to specify fractional seconds .
None