public void SetBuilder(IValidationBuilder builder)
 {
     this.builder = builder;
 }
 /// <summary>
 /// Specifies that values must be a valid file path or directory, and the file path must already exist.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="errorMessage">A custom error message to display.</param>
 /// <returns>The builder.</returns>
 public static IValidationBuilder ExistingFileOrDirectory(this IValidationBuilder builder, string errorMessage = null)
 => builder.Satisfies <FileOrDirectoryExistsAttribute>(errorMessage);
Пример #3
0
 /// <summary>
 /// The target field of a field selection must be defined on the scoped
 /// type of the selection set. There are no limitations on alias names.
 ///
 /// http://spec.graphql.org/June2018/#sec-Field-Selections-on-Objects-Interfaces-and-Unions-Types
 ///
 /// AND
 ///
 /// Field selections on scalars or enums are never allowed,
 /// because they are the leaf nodes of any GraphQL query.
 ///
 /// Conversely the leaf field selections of GraphQL queries
 /// must be of type scalar or enum. Leaf selections on objects,
 /// interfaces, and unions without subfields are disallowed.
 ///
 /// http://spec.graphql.org/June2018/#sec-Leaf-Field-Selections
 /// </summary>
 public static IValidationBuilder AddFieldRules(
     this IValidationBuilder builder)
 {
     return(builder.TryAddValidationVisitor <FieldVisitor>());
 }
Пример #4
0
 /// <summary>
 /// If any operation defines more than one variable with the same name,
 /// it is ambiguous and invalid. It is invalid even if the type of the
 /// duplicate variable is the same.
 ///
 /// http://spec.graphql.org/June2018/#sec-Validation.Variables
 ///
 /// AND
 ///
 /// Variables can only be input types. Objects,
 /// unions, and interfaces cannot be used as inputs.
 ///
 /// http://spec.graphql.org/June2018/#sec-Variables-Are-Input-Types
 ///
 /// AND
 ///
 /// All variables defined by an operation must be used in that operation
 /// or a fragment transitively included by that operation.
 ///
 /// Unused variables cause a validation error.
 ///
 /// http://spec.graphql.org/June2018/#sec-All-Variables-Used
 ///
 /// AND
 ///
 /// Variables are scoped on a per‐operation basis. That means that
 /// any variable used within the context of an operation must be defined
 /// at the top level of that operation
 ///
 /// http://spec.graphql.org/June2018/#sec-All-Variable-Uses-Defined
 ///
 /// AND
 ///
 /// Variable usages must be compatible with the arguments
 /// they are passed to.
 ///
 /// Validation failures occur when variables are used in the context
 /// of types that are complete mismatches, or if a nullable type in a
 ///  variable is passed to a non‐null argument type.
 ///
 /// http://spec.graphql.org/June2018/#sec-All-Variable-Usages-are-Allowed
 /// </summary>
 public static IValidationBuilder AddVariableRules(
     this IValidationBuilder builder)
 {
     return(builder.TryAddValidationVisitor <VariableVisitor>());
 }
Пример #5
0
 /// <summary>
 /// GraphQL servers define what directives they support.
 /// For each usage of a directive, the directive must be available
 /// on that server.
 ///
 /// http://spec.graphql.org/June2018/#sec-Directives-Are-Defined
 ///
 /// AND
 ///
 /// GraphQL servers define what directives they support and where they
 /// support them.
 ///
 /// For each usage of a directive, the directive must be used in a
 /// location that the server has declared support for.
 ///
 /// http://spec.graphql.org/June2018/#sec-Directives-Are-In-Valid-Locations
 ///
 /// AND
 ///
 /// Directives are used to describe some metadata or behavioral change on
 /// the definition they apply to.
 ///
 /// When more than one directive of the
 /// same name is used, the expected metadata or behavior becomes ambiguous,
 /// therefore only one of each directive is allowed per location.
 ///
 /// http://spec.graphql.org/draft/#sec-Directives-Are-Unique-Per-Location
 /// </summary>
 public static IValidationBuilder AddDirectiveRules(
     this IValidationBuilder builder)
 {
     return(builder.TryAddValidationVisitor <DirectiveVisitor>());
 }
Пример #6
0
 internal static IValidationBuilder UseMultipliers(
     this IValidationBuilder builder, bool useMultipliers) =>
 builder.ConfigureValidation(m =>
                             m.Modifiers.Add(o => o.UseComplexityMultipliers = useMultipliers));
 /// <summary>
 /// Specifies that values must be a valid file path or directory, and the file path must not already exist.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="errorMessage">A custom error message to display.</param>
 /// <returns>The builder.</returns>
 public static IValidationBuilder NonExistingFileOrDirectory(this IValidationBuilder builder, string?errorMessage = null)
 => builder.Satisfies(new FileOrDirectoryNotExistsAttribute(), errorMessage);
 /// <summary>
 /// Specifies that values must match a regular expression.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="pattern">The regular expression.</param>
 /// <param name="errorMessage">A custom error message to display.</param>
 /// <returns>The builder.</returns>
 public static IValidationBuilder RegularExpression(this IValidationBuilder builder, string pattern, string errorMessage = null)
 => builder.Satisfies <RegularExpressionAttribute>(errorMessage, pattern);
 /// <summary>
 /// Specifies that values must be one of the values in a given set.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="comparer">The comparer used to determine if values match.</param>
 /// <param name="allowedValues">Allowed values.</param>
 /// <returns>The builder.</returns>
 public static IValidationBuilder Values(this IValidationBuilder builder, StringComparison comparer, params string[] allowedValues)
 {
     return(builder.Satisfies(new AllowedValuesAttribute(comparer, allowedValues)));
 }
 /// <summary>
 /// Specifies that values must be a path to a directory that already exists.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="errorMessage">A custom error message to display.</param>
 /// <returns>The builder.</returns>
 public static IValidationBuilder ExistingDirectory(this IValidationBuilder builder, string?errorMessage = null)
 => builder.Satisfies(new DirectoryExistsAttribute(), errorMessage);
 internal static IValidationBuilder SetAllowedExecutionDepth(
     this IValidationBuilder builder, int allowedExecutionDepth) =>
 builder.ConfigureValidation(m =>
                             m.Modifiers.Add(o => o.MaxAllowedExecutionDepth = allowedExecutionDepth));
 /// <summary>
 /// Every argument provided to a field or directive must be defined
 /// in the set of possible arguments of that field or directive.
 ///
 /// http://spec.graphql.org/June2018/#sec-Argument-Names
 ///
 /// AND
 ///
 /// Fields and directives treat arguments as a mapping of argument name
 /// to value.
 ///
 /// More than one argument with the same name in an argument set
 /// is ambiguous and invalid.
 ///
 /// http://spec.graphql.org/June2018/#sec-Argument-Uniqueness
 ///
 /// AND
 ///
 /// Arguments can be required. An argument is required if the argument
 /// type is non‐null and does not have a default value. Otherwise,
 /// the argument is optional.
 ///
 /// http://spec.graphql.org/June2018/#sec-Required-Arguments
 /// </summary>
 public static IValidationBuilder AddArgumentRules(
     this IValidationBuilder builder)
 {
     return(builder.TryAddValidationRule <ArgumentVisitor>());
 }
 /// <summary>
 /// Every input field provided in an input object value must be defined in
 /// the set of possible fields of that input object’s expected type.
 ///
 /// http://spec.graphql.org/June2018/#sec-Input-Object-Field-Names
 ///
 /// AND
 ///
 /// Input objects must not contain more than one field of the same name,
 /// otherwise an ambiguity would exist which includes an ignored portion
 /// of syntax.
 ///
 /// http://spec.graphql.org/June2018/#sec-Input-Object-Field-Uniqueness
 ///
 /// AND
 ///
 /// Input object fields may be required. Much like a field may have
 /// required arguments, an input object may have required fields.
 ///
 /// An input field is required if it has a non‐null type and does not have
 /// a default value. Otherwise, the input object field is optional.
 ///
 /// http://spec.graphql.org/June2018/#sec-Input-Object-Required-Fields
 ///
 /// AND
 ///
 /// Literal values must be compatible with the type expected in the position
 /// they are found as per the coercion rules defined in the Type System
 /// chapter.
 ///
 /// http://spec.graphql.org/June2018/#sec-Values-of-Correct-Type
 /// </summary>
 public static IValidationBuilder AddValueRules(
     this IValidationBuilder builder)
 {
     return(builder.TryAddValidationRule <ValueVisitor>());
 }
 /// <summary>
 /// Specifies that values must be legal file paths.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="errorMessage">A custom error message to display.</param>
 /// <returns>The builder.</returns>
 public static IValidationBuilder LegalFilePath(this IValidationBuilder builder, string errorMessage = null)
 => builder.Satisfies <LegalFilePathAttribute>(errorMessage);
 /// <summary>
 /// Specifies that values must be a string no more than <paramref name="length"/> characters long.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="length">The maximum length.</param>
 /// <param name="errorMessage">A custom error message to display.</param>
 /// <returns>The builder.</returns>
 public static IValidationBuilder MaxLength(this IValidationBuilder builder, int length, string?errorMessage = null)
 => builder.Satisfies(new MaxLengthAttribute(length), errorMessage);
 /// <summary>
 /// Specifies that values must be a string no more than <paramref name="length"/> characters long.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="length">The maximum length.</param>
 /// <param name="errorMessage">A custom error message to display.</param>
 /// <returns>The builder.</returns>
 public static IValidationBuilder MaxLength(this IValidationBuilder builder, int length, string errorMessage = null)
 => builder.Satisfies <MaxLengthAttribute>(errorMessage, length);
 /// <summary>
 /// Specifies that values must match a regular expression.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="pattern">The regular expression.</param>
 /// <param name="errorMessage">A custom error message to display.</param>
 /// <returns>The builder.</returns>
 public static IValidationBuilder RegularExpression(this IValidationBuilder builder, string pattern, string?errorMessage = null)
 => builder.Satisfies(new RegularExpressionAttribute(pattern), errorMessage);
Пример #18
0
 /// <summary>
 /// Adds a validation rule that only allows requests to use `__schema` or `__type`
 /// if the request carries an introspection allowed flag.
 /// </summary>
 public static IValidationBuilder AddIntrospectionAllowedRule(
     this IValidationBuilder builder) =>
 builder.TryAddValidationVisitor((_, _) => new IntrospectionVisitor(), false);
Пример #19
0
 /// <summary>
 /// Specifies that values must be a path to a directory that does not already exist.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="errorMessage">A custom error message to display.</param>
 /// <returns>The builder.</returns>
 public static IValidationBuilder NonExistingDirectory(this IValidationBuilder builder, string?errorMessage = null)
 => builder.Satisfies <DirectoryNotExistsAttribute>(errorMessage);
Пример #20
0
 public static IValidationBuilder SetComplexityCalculation(
     this IValidationBuilder builder, ComplexityCalculation calculation) =>
 builder.ConfigureValidation(m =>
                             m.Modifiers.Add(o => o.ComplexityCalculation = calculation));
 /// <summary>
 /// <para>
 /// Specifies that values must be one of the values in a given set.
 /// </para>
 /// <para>
 /// By default, value comparison is case-sensitive. To make matches case-insensitive, use <see cref="Values(IValidationBuilder, bool, string[])"/>.
 /// </para>
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="allowedValues">Allowed values.</param>
 /// <returns>The builder.</returns>
 public static IValidationBuilder Values(this IValidationBuilder builder, params string[] allowedValues)
 => builder.Values(ignoreCase: false, allowedValues: allowedValues);
Пример #22
0
 internal static IValidationBuilder SetAllowedComplexity(
     this IValidationBuilder builder, int allowedComplexity) =>
 builder.ConfigureValidation(m =>
                             m.Modifiers.Add(o => o.MaxAllowedComplexity = allowedComplexity));
 /// <summary>
 /// Specifies that values must be one of the values in a given set.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="comparer">The comparer used to determine if values match.</param>
 /// <param name="allowedValues">Allowed values.</param>
 /// <returns>The builder.</returns>
 public static IValidationBuilder Values(this IValidationBuilder builder, StringComparison comparer, params string[] allowedValues)
 {
     return(builder.Satisfies <ValuesAttribute>(ctorArgs: new object[] { comparer, allowedValues }));
 }
Пример #24
0
 /// <summary>
 /// Fragment definitions are referenced in fragment spreads by name.
 /// To avoid ambiguity, each fragment’s name must be unique within a
 /// document.
 ///
 /// http://spec.graphql.org/June2018/#sec-Fragment-Name-Uniqueness
 ///
 /// AND
 ///
 /// Defined fragments must be used within a document.
 ///
 /// http://spec.graphql.org/June2018/#sec-Fragments-Must-Be-Used
 ///
 /// AND
 ///
 /// Fragments can only be declared on unions, interfaces, and objects.
 /// They are invalid on scalars.
 /// They can only be applied on non‐leaf fields.
 /// This rule applies to both inline and named fragments.
 ///
 /// http://spec.graphql.org/June2018/#sec-Fragments-On-Composite-Types
 ///
 /// AND
 ///
 /// Fragments are declared on a type and will only apply when the
 /// runtime object type matches the type condition.
 ///
 /// They also are spread within the context of a parent type.
 ///
 /// A fragment spread is only valid if its type condition could ever
 /// apply within the parent type.
 ///
 /// http://spec.graphql.org/June2018/#sec-Fragment-spread-is-possible
 ///
 /// AND
 ///
 /// Named fragment spreads must refer to fragments defined within the
 /// document.
 ///
 /// It is a validation error if the target of a spread is not defined.
 ///
 /// http://spec.graphql.org/June2018/#sec-Fragment-spread-target-defined
 ///
 /// AND
 ///
 /// The graph of fragment spreads must not form any cycles including
 /// spreading itself. Otherwise an operation could infinitely spread or
 /// infinitely execute on cycles in the underlying data.
 ///
 /// http://spec.graphql.org/June2018/#sec-Fragment-spreads-must-not-form-cycles
 ///
 /// AND
 ///
 /// Fragments must be specified on types that exist in the schema.
 /// This applies for both named and inline fragments.
 /// If they are not defined in the schema, the query does not validate.
 ///
 /// http://spec.graphql.org/June2018/#sec-Fragment-Spread-Type-Existence
 /// </summary>
 public static IValidationBuilder AddFragmentRules(
     this IValidationBuilder builder)
 {
     return(builder.TryAddValidationVisitor <FragmentVisitor>());
 }
 /// <summary>
 /// Specifies that values must be a valid email address.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="errorMessage">A custom error message to display.</param>
 /// <returns>The builder.</returns>
 public static IValidationBuilder EmailAddress(this IValidationBuilder builder, string errorMessage = null)
 => builder.Satisfies <EmailAddressAttribute>(errorMessage);
Пример #26
0
 /// <summary>
 /// GraphQL allows a short‐hand form for defining query operations
 /// when only that one operation exists in the document.
 ///
 /// http://spec.graphql.org/June2018/#sec-Lone-Anonymous-Operation
 ///
 /// AND
 ///
 /// Each named operation definition must be unique within a document
 /// when referred to by its name.
 ///
 /// http://spec.graphql.org/June2018/#sec-Operation-Name-Uniqueness
 ///
 /// AND
 ///
 /// Subscription operations must have exactly one root field.
 ///
 /// http://spec.graphql.org/June2018/#sec-Single-root-field
 /// </summary>
 public static IValidationBuilder AddOperationRules(
     this IValidationBuilder builder)
 {
     return(builder.TryAddValidationVisitor <OperationVisitor>());
 }
 public ValidationDirector(IValidationBuilder builder)
 {
     this.builder = builder;
 }