lib/graphql/static_validation/validator.rb
# Validate `query` against the schema. Returns an array of message hashes.
# @param query [GraphQL::Query]
# @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)
        query.trace("validate", { validate: validate, query: query }) do
          can_skip_rewrite = query.context.interpreter? && query.schema.using_ast_analysis?
          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)
            rules_to_use.each do |rule_class_or_module|
              if rule_class_or_module.method_defined?(:validate)
                rule_class_or_module.new.validate(context)
              end
            end
            context.visitor.visit
            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 ) query . trace ( "validate" , { validate : validate , query : query } ) do can_skip_rewrite = query . context . interpreter? && query . schema . using_ast_analysis? 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 ) rules_to_use . each do | rule_class_or_module | if rule_class_or_module . method_defined? ( :validate ) rule_class_or_module . new . validate ( context ) end end context . visitor . visit 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 .
# Attach legacy-style rules # Only return this if there are no errors and validation was actually run
None
Array<Hash>
query
validate
None