コード例 #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);
        }
コード例 #2
0
 public MaxComplexityRule(
     IValidateQueryOptionsAccessor options,
     ComplexityCalculation calculateComplexity)
 {
     _options = options
                ?? throw new ArgumentNullException(nameof(options));
     _calculateComplexity = calculateComplexity ?? DefaultComplexity;
 }
コード例 #3
0
 internal protected MaxComplexityWithMultipliersVisitorContext(
     ISchema schema,
     IVariableCollection variables,
     ComplexityCalculation calculateComplexity)
     : base(schema, calculateComplexity)
 {
     _variables = variables;
 }
コード例 #4
0
 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;
 }
コード例 #5
0
 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;
 }
コード例 #6
0
 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;
 }
コード例 #7
0
 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;
 }
コード例 #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);
        }
コード例 #9
0
 public static IValidationBuilder SetComplexityCalculation(
     this IValidationBuilder builder, ComplexityCalculation calculation) =>
 builder.ConfigureValidation(m =>
                             m.Modifiers.Add(o => o.ComplexityCalculation = calculation));