Example #1
0
        public static IQueryExecutionBuilder AddQueryValidation(
            this IQueryExecutionBuilder builder,
            IValidateQueryOptionsAccessor options)
        {
            builder.Services.AddQueryValidation(options);

            return(builder);
        }
Example #2
0
 public MaxComplexityRule(
     IValidateQueryOptionsAccessor options,
     ComplexityCalculation calculateComplexity)
 {
     _options = options
                ?? throw new ArgumentNullException(nameof(options));
     _calculateComplexity = calculateComplexity ?? DefaultComplexity;
 }
Example #3
0
        public MaxDepthVisitor(IValidateQueryOptionsAccessor options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _maxExecutionDepth = options.MaxExecutionDepth ?? int.MaxValue;
        }
 public MaxComplexityMiddleware(
     QueryDelegate next,
     IValidateQueryOptionsAccessor options,
     ComplexityCalculation complexityCalculation)
 {
     _next = next
             ?? throw new ArgumentNullException(nameof(next));
     _options = options
                ?? throw new ArgumentNullException(nameof(options));
     _calculation = complexityCalculation ?? DefaultComplexity;
 }
Example #5
0
        private IQueryValidator CreateValidator(
            IValidateQueryOptionsAccessor options)
        {
            var services = new ServiceCollection();

            services.AddQueryValidation(options);
            services.AddDefaultValidationRules();

            return(services.BuildServiceProvider()
                   .GetRequiredService <IQueryValidator>());
        }
Example #6
0
        public static IServiceCollection AddQueryValidation(
            this IServiceCollection services,
            IValidateQueryOptionsAccessor options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            return(services
                   .AddSingleton(options)
                   .AddSingleton <IQueryValidator, QueryValidator>());
        }
Example #7
0
 public ValidateQueryMiddleware(
     QueryDelegate next,
     IQueryValidator validator,
     Cache <QueryValidationResult> validatorCache,
     IValidateQueryOptionsAccessor options)
 {
     _next = next ??
             throw new ArgumentNullException(nameof(next));
     _validator = validator ??
                  throw new ArgumentNullException(nameof(validator));
     _validatorCache = validatorCache ??
                       new Cache <QueryValidationResult>(Defaults.CacheSize);
     _options = options ??
                throw new ArgumentNullException(nameof(options));
 }
        public MaxDepthVisitor(IValidateQueryOptionsAccessor options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (!options.MaxExecutionDepth.HasValue)
            {
                throw new ArgumentException(
                          "The max depth visitor can only be used " +
                          "if a max query depth is defined.");
            }

            _maxExecutionDepth = options.MaxExecutionDepth.Value;
        }
Example #9
0
        public static IQueryExecutionBuilder AddQueryValidation(
            this IQueryExecutionBuilder builder,
            IValidateQueryOptionsAccessor options)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            builder.Services.AddQueryValidation(options);

            return(builder);
        }
Example #10
0
 public MaxDepthRule(IValidateQueryOptionsAccessor options)
 {
     _options = options
                ?? throw new ArgumentNullException(nameof(options));
     _visitor = new MaxDepthVisitor(_options);
 }