Exemplo n.º 1
0
    public OperationComplexityMiddleware(
        RequestDelegate next,
        DocumentValidatorContextPool contextPool,
        IComplexityAnalyzerOptionsAccessor options,
        IComplexityAnalyzerCache cache,
        VariableCoercionHelper coercionHelper)
    {
        _next = next ??
                throw new ArgumentNullException(nameof(next));
        _contextPool = contextPool ??
                       throw new ArgumentNullException(nameof(contextPool));
        _settings = options?.Complexity ??
                    throw new ArgumentNullException(nameof(options));
        _cache = cache ??
                 throw new ArgumentNullException(nameof(cache));
        _coercionHelper = coercionHelper ??
                          throw new ArgumentNullException(nameof(coercionHelper));

        _compiler = new ComplexityAnalyzerCompilerVisitor(_settings);
    }
 public static int Calculate(
     IOutputField field,
     FieldNode selection,
     CostDirective costDirective,
     int fieldDepth,
     int nodeDepth,
     int childComplexity,
     IVariableValueCollection variables,
     InputParser inputParser,
     ComplexityAnalyzerSettings analyzerSettings)
 {
     return(analyzerSettings.Calculation.Invoke(
                new ComplexityContext(
                    field,
                    selection,
                    costDirective,
                    fieldDepth,
                    nodeDepth,
                    childComplexity,
                    analyzerSettings.DefaultComplexity,
                    variables,
                    inputParser)));
 }
 public ComplexityAnalyzerCompilerVisitor(ComplexityAnalyzerSettings settings)
 {
     _settings = Constant(settings, typeof(ComplexityAnalyzerSettings));
 }