Example #1
0
        public QueryValidationResult Validate(
            ISchema schema,
            DocumentNode queryDocument)
        {
            if (_options.MaxExecutionDepth.HasValue)
            {
                var visitor = new MaxDepthVisitor(_options);
                visitor.Visit(queryDocument);

                return(visitor.IsMaxDepthReached
                    ? new QueryValidationResult(
                           new ValidationError(
                               "The query exceded the maximum allowed execution " +
                               $"depth of {_options.MaxExecutionDepth.Value}.",
                               visitor.ViolatingFields.ToArray()))
                    : QueryValidationResult.OK);
            }
            return(QueryValidationResult.OK);
        }
Example #2
0
 public MaxDepthRule(IValidateQueryOptionsAccessor options)
 {
     _options = options
                ?? throw new ArgumentNullException(nameof(options));
     _visitor = new MaxDepthVisitor(_options);
 }