public static IValidationBuilder AddValidationRule <T>(
     this IValidationBuilder builder)
     where T : DocumentValidatorVisitor, new()
 {
     return(builder.ConfigureValidation(m =>
                                        m.Modifiers.Add(o => o.Rules.Add(new DocumentValidatorRule <T>(new T())))));
 }
 public static IValidationBuilder AddValidationRule <T>(
     this IValidationBuilder builder,
     Func <IServiceProvider, ValidationOptions, T> factory)
     where T : DocumentValidatorVisitor
 {
     return(builder.ConfigureValidation((s, m) =>
                                        m.Modifiers.Add(o => o.Rules.Add(new DocumentValidatorRule <T>(factory(s, o))))));
 }
Ejemplo n.º 3
0
 /// <summary>
 /// GraphQL execution will only consider the executable definitions
 /// Operation and Fragment.
 ///
 /// Type system definitions and extensions are not executable,
 /// and are not considered during execution.
 ///
 /// To avoid ambiguity, a document containing TypeSystemDefinition
 /// is invalid for execution.
 ///
 /// GraphQL documents not intended to be directly executed may
 /// include TypeSystemDefinition.
 ///
 /// http://spec.graphql.org/June2018/#sec-Executable-Definitions
 /// </summary>
 public static IValidationBuilder AddDocumentRules(
     this IValidationBuilder builder)
 {
     return(builder.ConfigureValidation(
                m => m.Modifiers.Add(o =>
     {
         if (o.Rules.All(t => t.GetType() != typeof(DocumentRule)))
         {
             o.Rules.Add(new DocumentRule());
         }
     })));
 }
Ejemplo n.º 4
0
 public static IValidationBuilder TryAddValidationRule <T>(
     this IValidationBuilder builder)
     where T : class, IDocumentValidatorRule, new()
 {
     return(builder.ConfigureValidation(m =>
                                        m.Modifiers.Add(o =>
     {
         if (o.Rules.All(t => t.GetType() != typeof(T)))
         {
             o.Rules.Add(new T());
         }
     })));
 }
Ejemplo n.º 5
0
 public static IValidationBuilder TryAddValidationVisitor <T>(
     this IValidationBuilder builder,
     bool isCacheable = true)
     where T : DocumentValidatorVisitor, new()
 {
     return(builder.ConfigureValidation(m =>
                                        m.Modifiers.Add(o =>
     {
         if (o.Rules.All(t => t.GetType() != typeof(DocumentValidatorRule <T>)))
         {
             o.Rules.Add(new DocumentValidatorRule <T>(new T(), isCacheable));
         }
     })));
 }
Ejemplo n.º 6
0
 public static IValidationBuilder TryAddValidationRule <T>(
     this IValidationBuilder builder,
     Func <IServiceProvider, ValidationOptions, T> factory)
     where T : DocumentValidatorVisitor
 {
     return(builder.ConfigureValidation((s, m) =>
                                        m.Modifiers.Add(o =>
     {
         if (o.Rules.All(t => t.GetType() != typeof(DocumentValidatorRule <T>)))
         {
             o.Rules.Add(new DocumentValidatorRule <T>(factory(s, o)));
         }
     })));
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Sets the maximum allowed depth of a query. The default
        /// value is <see langword="null"/>. The minimum allowed value is
        /// <c>1</c>.
        /// </summary>
        internal static IValidationBuilder SetAllowedExecutionDepth(
            this IValidationBuilder builder, int allowedExecutionDepth)
        {
            if (allowedExecutionDepth < 1)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(allowedExecutionDepth),
                          allowedExecutionDepth,
                          Resources.HotChocolateValidationBuilderExtensions_MinimumAllowedValue);
            }

            return(builder.ConfigureValidation(m =>
                                               m.Modifiers.Add(o => o.MaxAllowedExecutionDepth = allowedExecutionDepth)));
        }
Ejemplo n.º 8
0
 public static IValidationBuilder TryAddValidationRule <T>(
     this IValidationBuilder builder,
     Func <IServiceProvider, ValidationOptions, T> factory)
     where T : class, IDocumentValidatorRule
 {
     return(builder.ConfigureValidation((s, m) =>
                                        m.Modifiers.Add(o =>
     {
         T instance = factory(s, o);
         if (o.Rules.All(t => t.GetType() != instance.GetType()))
         {
             o.Rules.Add(instance);
         }
     })));
 }
Ejemplo n.º 9
0
 /// <summary>
 /// GraphQL execution will only consider the executable definitions
 /// Operation and Fragment.
 ///
 /// Type system definitions and extensions are not executable,
 /// and are not considered during execution.
 ///
 /// To avoid ambiguity, a document containing TypeSystemDefinition
 /// is invalid for execution.
 ///
 /// GraphQL documents not intended to be directly executed may
 /// include TypeSystemDefinition.
 ///
 /// http://spec.graphql.org/June2018/#sec-Executable-Definitions
 /// </summary>
 public static IValidationBuilder AddDocumentRules(
     this IValidationBuilder builder)
 {
     return(builder.ConfigureValidation(
                m => m.Modifiers.Add(o => o.Rules.Add(new DocumentRule()))));
 }
Ejemplo n.º 10
0
 internal static IValidationBuilder SetAllowedComplexity(
     this IValidationBuilder builder, int allowedComplexity) =>
 builder.ConfigureValidation(m =>
                             m.Modifiers.Add(o => o.MaxAllowedComplexity = allowedComplexity));
Ejemplo n.º 11
0
 internal static IValidationBuilder UseMultipliers(
     this IValidationBuilder builder, bool useMultipliers) =>
 builder.ConfigureValidation(m =>
                             m.Modifiers.Add(o => o.UseComplexityMultipliers = useMultipliers));
Ejemplo n.º 12
0
 public static IValidationBuilder SetComplexityCalculation(
     this IValidationBuilder builder, ComplexityCalculation calculation) =>
 builder.ConfigureValidation(m =>
                             m.Modifiers.Add(o => o.ComplexityCalculation = calculation));
 internal static IValidationBuilder SetAllowedExecutionDepth(
     this IValidationBuilder builder, int allowedExecutionDepth) =>
 builder.ConfigureValidation(m =>
                             m.Modifiers.Add(o => o.MaxAllowedExecutionDepth = allowedExecutionDepth));