Beispiel #1
0
        public int Visit(
            DocumentNode node,
            ISchema schema,
            ComplexityCalculation calculateComplexity)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

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

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

            var context = MaxComplexityVisitorContext
                          .New(schema, calculateComplexity);

            Visit(node, context);
            return(context.MaxComplexity);
        }
Beispiel #2
0
 public MaxComplexityRule(
     IValidateQueryOptionsAccessor options,
     ComplexityCalculation calculateComplexity)
 {
     _options = options
                ?? throw new ArgumentNullException(nameof(options));
     _calculateComplexity = calculateComplexity ?? DefaultComplexity;
 }
Beispiel #3
0
 internal protected MaxComplexityWithMultipliersVisitorContext(
     ISchema schema,
     IVariableCollection variables,
     ComplexityCalculation calculateComplexity)
     : base(schema, calculateComplexity)
 {
     _variables = variables;
 }
 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;
 }
 protected MaxComplexityVisitorContext(
     MaxComplexityVisitorContext context)
 {
     Schema               = context.Schema;
     FragmentPath         = context.FragmentPath;
     FieldPath            = context.FieldPath;
     Fragments            = context.Fragments;
     TypeContext          = context.TypeContext;
     _calculateComplexity = context._calculateComplexity;
     _root = context._root;
     Scope = context.Scope;
 }
 protected MaxComplexityVisitorContext(
     ISchema schema,
     ComplexityCalculation calculateComplexity)
 {
     _calculateComplexity = calculateComplexity;
     Schema       = schema;
     FragmentPath = ImmutableHashSet <string> .Empty;
     FieldPath    = ImmutableList <IOutputField> .Empty;
     Fragments    = new Dictionary <string, FragmentDefinitionNode>();
     _root        = this;
     Scope        = this;
 }
 protected MaxComplexityVisitorContext(
     ImmutableHashSet <string> fragmentPath,
     ImmutableList <IOutputField> fieldPath,
     MaxComplexityVisitorContext context)
 {
     FragmentPath         = fragmentPath;
     FieldPath            = fieldPath;
     Schema               = context.Schema;
     Fragments            = context.Fragments;
     TypeContext          = context.TypeContext;
     _calculateComplexity = context._calculateComplexity;
     _root = context._root;
     Scope = context.Scope;
 }
Beispiel #8
0
        public static IQueryExecutionBuilder AddComplexityCalculation(
            this IQueryExecutionBuilder builder,
            ComplexityCalculation complexityCalculation)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

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

            builder.Services.AddSingleton <ComplexityCalculation>(
                complexityCalculation);

            return(builder);
        }
Beispiel #9
0
 public static IValidationBuilder SetComplexityCalculation(
     this IValidationBuilder builder, ComplexityCalculation calculation) =>
 builder.ConfigureValidation(m =>
                             m.Modifiers.Add(o => o.ComplexityCalculation = calculation));