Graph.ArgumentValidator 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Graph.ArgumentValidator --version 1.0.0
NuGet\Install-Package Graph.ArgumentValidator -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Graph.ArgumentValidator" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Graph.ArgumentValidator --version 1.0.0
#r "nuget: Graph.ArgumentValidator, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Graph.ArgumentValidator as a Cake Addin
#addin nuget:?package=Graph.ArgumentValidator&version=1.0.0

// Install Graph.ArgumentValidator as a Cake Tool
#tool nuget:?package=Graph.ArgumentValidator&version=1.0.0

Adds support for validating input arguments in HotChocolate

Generally, we use attributes from System.ComponentModel.DataAnnotations for validating our input models in controllers.

As HotChocolate doesn't validate input arguments, After installing this package, By just adding 2 lines of code in your Startup.cs file. You will be adding support for validation to all input models in your Queries/Mutations.

Tech Note: You can use all validation attributes/rules from System.ComponentModel.DataAnnotations (ex: Required, MinLength, Regex etc). This package just adds a middleware to the hot chocolate resolver for validating your input models as configured in below steps.

Steps for configuring validator

Step 1

Go to StartUp.cs file and inside ConfigureServices make the following changes.

Step 2

Keep this code to validate all inputs of GraphQL Query/Mutation.

ValidatorSettings.ValidateAllInputs = true;

Step 3

Add argument validator to services by referring to below code

services
  .AddGraphQLServer()
  .AddArgumentValidator();

Additional Configuration

If you don't want to validate all inputs then you can skip step 2 and follow the optional step i.e

Just add the Validatable attribute to the class u defined for input.

Ex:

    using System.ComponentModel.DataAnnotations;
    using Graph.ArgumentValidator;
    
    namespace Demo
    {
        [Validatable]
        public class AddUserInput
        {
            [Required, MinLength(4, ErrorMessage = "Username must be atleast 4 characters.")]
            public string UserName { get; set; }

            [Required, RegularExpression(@"^[^@\s]+@[^@\s]+\.[^@\s]+$", ErrorMessage = "Email Id format is invalid")]
            public string Email { get; set; }

            [Required, RegularExpression(@"^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$", ErrorMessage = "Password needs to be more strong.")]
            public string Password { get; set; }
        }
    }

When the user is given wrong values to input, this is how the response from GraphQL Server will look like

{
  "errors": [
    {
      "message": "Username must be at least 4 characters."
    },
    {
      "message": "Password needs to be more strong."
    }
  ]
}
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.0 3,625 11/7/2023
2.1.2 32,374 6/19/2022
2.1.1 14,778 3/10/2022
2.1.0 3,998 12/3/2021
2.0.0 7,910 10/10/2021
1.0.1 25,034 3/18/2021
1.0.0 853 3/6/2021