├── icon.png ├── test ├── __snapshots__ │ ├── ValidationTests.Ensure_Validation_Works_On_Arguments_ValidEmail.snap │ ├── ValidationTests.Ensure_Validation_Works_On_InputObjects_ValidEmail.snap │ ├── ValidationTests.Ensure_Validation_Works_On_StudentWithScoreCard.snap │ ├── ValidationTests.Ensure_Validation_Works_On_NonDuplicateEmail.snap │ ├── ValidationTests.Ensure_Validation_Works_On_DuplicateEmail.snap │ ├── ValidationTests.Ensure_Validation_Works_On_Arguments.snap │ ├── ValidationTests.Ensure_Validation_Works_On_InputObjects.snap │ └── ValidationTests.Ensure_Validation_Works_On_StudentWithOutScoreCard.snap ├── Graph.ArgumentValidator.Tests.csproj └── ValidationTests.cs ├── src ├── WellKnownContextData.cs ├── ValidatableAttribute.cs ├── RequestExecutorBuilderExtensions.cs ├── Graph.ArgumentValidator.csproj ├── Directory.Build.props ├── ValidationMiddleware.cs └── ValidationTypeInterceptor.cs ├── Sample ├── appsettings.Development.json ├── appsettings.json ├── Program.cs ├── Sample.csproj └── Properties │ └── launchSettings.json ├── Shared ├── MyInput.cs ├── Shared.csproj ├── DuplicateEmailValidatorService.cs ├── Student.cs ├── DuplicateEmailValidtorAttribute.cs └── Query.cs ├── .vscode └── tasks.json ├── LICENSE ├── .gitattributes ├── README.md ├── Graph.ArgumentValidator.sln └── .gitignore /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VarunSaiTeja/Graph.ArgumentValidator/HEAD/icon.png -------------------------------------------------------------------------------- /test/__snapshots__/ValidationTests.Ensure_Validation_Works_On_Arguments_ValidEmail.snap: -------------------------------------------------------------------------------- 1 | { 2 | "data": { 3 | "argIsEmail": "abc@abc.com" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /test/__snapshots__/ValidationTests.Ensure_Validation_Works_On_InputObjects_ValidEmail.snap: -------------------------------------------------------------------------------- 1 | { 2 | "data": { 3 | "argIsInput": "abc@abc.com" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /test/__snapshots__/ValidationTests.Ensure_Validation_Works_On_StudentWithScoreCard.snap: -------------------------------------------------------------------------------- 1 | { 2 | "data": { 3 | "checkPass": "Varun at Gayatri is passed" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /test/__snapshots__/ValidationTests.Ensure_Validation_Works_On_NonDuplicateEmail.snap: -------------------------------------------------------------------------------- 1 | { 2 | "data": { 3 | "checkDuplicateEmail": "You are good to go, this email not registred yet." 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /src/WellKnownContextData.cs: -------------------------------------------------------------------------------- 1 | namespace Graph.ArgumentValidator 2 | { 3 | internal static class WellKnownContextData 4 | { 5 | public const string ValidationDelegate = nameof(ValidationDelegate); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Sample/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Sample/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /Shared/MyInput.cs: -------------------------------------------------------------------------------- 1 | using Graph.ArgumentValidator; 2 | using System.ComponentModel.DataAnnotations; 3 | 4 | namespace Shared 5 | { 6 | [Validatable] 7 | public class MyInput 8 | { 9 | [EmailAddress, Required] 10 | public string Email { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Shared/Shared.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/ValidatableAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Graph.ArgumentValidator 4 | { 5 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = true, AllowMultiple = false)] 6 | public class ValidatableAttribute : Attribute 7 | { 8 | public ValidatableAttribute() 9 | { 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Sample/Program.cs: -------------------------------------------------------------------------------- 1 | using Graph.ArgumentValidator; 2 | using Shared; 3 | 4 | var builder = WebApplication.CreateBuilder(args); 5 | 6 | builder.Services 7 | .AddGraphQLServer() 8 | .AddArgumentValidator() 9 | .AddQueryType(); 10 | builder.Services 11 | .AddSingleton(); 12 | 13 | var app = builder.Build(); 14 | 15 | app.MapGraphQL(); 16 | 17 | app.Run(); -------------------------------------------------------------------------------- /test/__snapshots__/ValidationTests.Ensure_Validation_Works_On_DuplicateEmail.snap: -------------------------------------------------------------------------------- 1 | { 2 | "errors": [ 3 | { 4 | "message": "Email already exist", 5 | "locations": [ 6 | { 7 | "line": 1, 8 | "column": 3 9 | } 10 | ], 11 | "path": [ 12 | "email" 13 | ], 14 | "extensions": { 15 | "field": "email" 16 | } 17 | } 18 | ], 19 | "data": { 20 | "checkDuplicateEmail": null 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sample/Sample.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /test/__snapshots__/ValidationTests.Ensure_Validation_Works_On_Arguments.snap: -------------------------------------------------------------------------------- 1 | { 2 | "errors": [ 3 | { 4 | "message": "The String field is not a valid e-mail address.", 5 | "locations": [ 6 | { 7 | "line": 1, 8 | "column": 3 9 | } 10 | ], 11 | "path": [ 12 | "email" 13 | ], 14 | "extensions": { 15 | "field": "email" 16 | } 17 | } 18 | ], 19 | "data": { 20 | "argIsEmail": null 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Shared/DuplicateEmailValidatorService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Shared 4 | { 5 | public class DuplicateEmailValidatorService 6 | { 7 | public bool IsEmailExist(string newEmail) 8 | { 9 | var existingEmails = new List 10 | { 11 | "varun@gmail.com", 12 | "teja@gmail.com" 13 | }; 14 | 15 | return !existingEmails.Contains(newEmail); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /test/__snapshots__/ValidationTests.Ensure_Validation_Works_On_InputObjects.snap: -------------------------------------------------------------------------------- 1 | { 2 | "errors": [ 3 | { 4 | "message": "The Email field is not a valid e-mail address.", 5 | "locations": [ 6 | { 7 | "line": 1, 8 | "column": 3 9 | } 10 | ], 11 | "path": [ 12 | "input" 13 | ], 14 | "extensions": { 15 | "field": "email" 16 | } 17 | } 18 | ], 19 | "data": { 20 | "argIsInput": null 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /test/__snapshots__/ValidationTests.Ensure_Validation_Works_On_StudentWithOutScoreCard.snap: -------------------------------------------------------------------------------- 1 | { 2 | "errors": [ 3 | { 4 | "message": "`scoreCard` is a required field and cannot be null.", 5 | "locations": [ 6 | { 7 | "line": 1, 8 | "column": 26 9 | } 10 | ], 11 | "path": [ 12 | "checkPass" 13 | ], 14 | "extensions": { 15 | "field": "scoreCard", 16 | "specifiedBy": "https://spec.graphql.org/October2021/#sec-Input-Object-Required-Fields" 17 | } 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /src/RequestExecutorBuilderExtensions.cs: -------------------------------------------------------------------------------- 1 | using HotChocolate.Execution.Configuration; 2 | using Microsoft.Extensions.DependencyInjection; 3 | 4 | namespace Graph.ArgumentValidator 5 | { 6 | public static class RequestExecutorBuilderExtensions 7 | { 8 | public static IRequestExecutorBuilder AddArgumentValidator( 9 | this IRequestExecutorBuilder requestExecutorBuilder) 10 | { 11 | requestExecutorBuilder.TryAddTypeInterceptor(); 12 | 13 | return requestExecutorBuilder; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Shared/Student.cs: -------------------------------------------------------------------------------- 1 | using Graph.ArgumentValidator; 2 | using System.ComponentModel.DataAnnotations; 3 | 4 | namespace Shared 5 | { 6 | [Validatable] 7 | public class Student 8 | { 9 | [Required(AllowEmptyStrings = false)] 10 | public string FirstName { get; set; } 11 | [Required] 12 | public ScoreCardInfo ScoreCard { get; set; } 13 | 14 | public class ScoreCardInfo 15 | { 16 | [Required] 17 | public int TotalScore { get; set; } 18 | 19 | [Required(AllowEmptyStrings = false)] 20 | public string School { get; set; } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Shared/DuplicateEmailValidtorAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace Shared 4 | { 5 | public class DuplicateEmailValidtorAttribute : ValidationAttribute 6 | { 7 | protected override ValidationResult IsValid(object valueObj, ValidationContext validationContext) 8 | { 9 | var value = valueObj as string; 10 | var service = (DuplicateEmailValidatorService)validationContext.GetService(typeof(DuplicateEmailValidatorService)); 11 | return service.IsEmailExist(value) ? ValidationResult.Success : new ValidationResult("Email already exist"); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "label": "build", 8 | "command": "dotnet", 9 | "type": "shell", 10 | "args": [ 11 | "build", 12 | // Ask dotnet build to generate full paths for file names. 13 | "/property:GenerateFullPaths=true", 14 | // Do not generate summary otherwise it leads to duplicate errors in Problems panel 15 | "/consoleloggerparameters:NoSummary" 16 | ], 17 | "group": "build", 18 | "presentation": { 19 | "reveal": "silent" 20 | }, 21 | "problemMatcher": "$msCompile" 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /src/Graph.ArgumentValidator.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | net8.0; net6.0 6 | net8.0; net6.0; netstandard2.0 7 | HotChocolate.Validator, HotChocolate, GraphQL 8 | icon.png 9 | true 10 | true 11 | $(Version) 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | True 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Sample/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:23573", 8 | "sslPort": 44334 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "graphql", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "Sample": { 21 | "commandName": "Project", 22 | "launchBrowser": true, 23 | "launchUrl": "weatherforecast", 24 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 25 | "environmentVariables": { 26 | "ASPNETCORE_ENVIRONMENT": "Development" 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | latest 4 | https://github.com/VarunSaiTeja/Graph.ArgumentValidator 5 | https://github.com/VarunSaiTeja/Graph.ArgumentValidator 6 | git 7 | Varun Teja 8 | Varun Teja 9 | $(MSBuildProjectName) 10 | Input Argument Validator for HotChocolate 11 | $(MSBuildProjectName) 12 | $(MSBuildProjectName) 13 | $(MSBuildProjectName) 14 | latest 15 | 16 | $(MSBuildProjectName) 17 | MIT 18 | 19 | 4.0.0 20 | 21 | 22 | -------------------------------------------------------------------------------- /Shared/Query.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace Shared 4 | { 5 | public class Query 6 | { 7 | public string ArgIsEmail([EmailAddress, Required] string email) => email; 8 | 9 | /// 10 | /// Gives validation failed result if email already exist. Other wise *You are good to go...* 11 | /// 12 | /// 13 | /// 14 | public string CheckDuplicateEmail([EmailAddress, Required][DuplicateEmailValidtor] string email) => "You are good to go, this email not registred yet."; 15 | 16 | public string ArgIsInput(MyInput input) => input.Email; 17 | 18 | public string CheckPass(Student student) 19 | { 20 | if (student.ScoreCard.TotalScore > 30) 21 | return $"{student.FirstName} at {student.ScoreCard.School} is passed"; 22 | else 23 | return $"{student.FirstName} at {student.ScoreCard.School} is failed"; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /test/Graph.ArgumentValidator.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | runtime; build; native; contentfiles; analyzers; buildtransitive 18 | all 19 | 20 | 21 | runtime; build; native; contentfiles; analyzers; buildtransitive 22 | all 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Microsoft Corporation. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE 22 | -------------------------------------------------------------------------------- /src/ValidationMiddleware.cs: -------------------------------------------------------------------------------- 1 | using HotChocolate; 2 | using HotChocolate.Resolvers; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using HotChocolate.Execution; 8 | 9 | namespace Graph.ArgumentValidator 10 | { 11 | internal class ValidationMiddleware 12 | { 13 | private readonly FieldDelegate _next; 14 | 15 | public ValidationMiddleware(FieldDelegate next) 16 | { 17 | _next = next; 18 | } 19 | 20 | // this middleware is ensured to only execute on fields that have arguments that need validation. 21 | public async Task InvokeAsync(IMiddlewareContext context) 22 | { 23 | var errors = new List(); 24 | var hasErrors = false; 25 | 26 | // we could even further optimize and aggregate this list in the interceptor and inject it into the middleware 27 | foreach (var argument in context.Selection.Field.Arguments) 28 | { 29 | if (argument.ContextData.TryGetValue(WellKnownContextData.ValidationDelegate, out object value) && 30 | value is Validate validate) 31 | { 32 | var input = context.ArgumentValue(argument.Name); 33 | var validationContext = new ValidationContext(input, context.Services, null); 34 | validate(input, validationContext, errors); 35 | 36 | if (errors.Any()) 37 | { 38 | foreach (var validationResult in errors) 39 | { 40 | var field = validationResult.MemberNames.FirstOrDefault() ?? argument.Name; 41 | 42 | context.ReportError(ErrorBuilder.New() 43 | .SetMessage(validationResult.ErrorMessage) 44 | .SetExtension("field", char.ToLowerInvariant(field[0]) + field.Substring(1)) 45 | .SetPath(new List 46 | { 47 | argument.Name 48 | }) 49 | .Build()); 50 | } 51 | 52 | errors.Clear(); 53 | hasErrors = true; 54 | } 55 | } 56 | } 57 | 58 | if (!hasErrors) 59 | { 60 | await _next(context); 61 | } 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /test/ValidationTests.cs: -------------------------------------------------------------------------------- 1 | using HotChocolate; 2 | using HotChocolate.Execution; 3 | using Microsoft.Extensions.DependencyInjection; 4 | using Shared; 5 | using Snapshooter.Xunit; 6 | using System.Threading.Tasks; 7 | using Xunit; 8 | 9 | namespace Graph.ArgumentValidator.Tests 10 | { 11 | public class ValidationTests 12 | { 13 | /// 14 | /// Gives the JSON result of execution 15 | /// 16 | /// GraphQL query to be executed 17 | /// JSON result of GraphQL Query 18 | static async Task ExecuteRequest(string request) 19 | { 20 | var resonse = await new ServiceCollection() 21 | .AddScoped(_ => new DuplicateEmailValidatorService()) 22 | .AddGraphQL() 23 | .AddQueryType() 24 | .AddArgumentValidator() 25 | .ExecuteRequestAsync(request); 26 | return resonse.ToJson(); 27 | } 28 | 29 | [Fact] 30 | public async Task Ensure_Validation_Works_On_Arguments() 31 | { 32 | var result = await ExecuteRequest("{ argIsEmail(email: \"abc\") }"); 33 | 34 | result.MatchSnapshot(); 35 | } 36 | 37 | [Fact] 38 | public async Task Ensure_Validation_Works_On_Arguments_ValidEmail() 39 | { 40 | var result = await ExecuteRequest("{ argIsEmail(email: \"abc@abc.com\") }"); 41 | 42 | result.MatchSnapshot(); 43 | } 44 | 45 | [Fact] 46 | public async Task Ensure_Validation_Works_On_InputObjects() 47 | { 48 | var result = await ExecuteRequest("{ argIsInput(input: { email: \"abc\" }) }"); 49 | 50 | result.MatchSnapshot(); 51 | } 52 | 53 | [Fact] 54 | public async Task Ensure_Validation_Works_On_InputObjects_ValidEmail() 55 | { 56 | var result = await ExecuteRequest("{ argIsInput(input: { email: \"abc@abc.com\" }) }"); 57 | 58 | result.MatchSnapshot(); 59 | } 60 | 61 | 62 | [Fact] 63 | public async Task Ensure_Validation_Works_On_DuplicateEmail() 64 | { 65 | var result = await ExecuteRequest("{ checkDuplicateEmail( email: \"varun@gmail.com\" ) }"); 66 | 67 | result.MatchSnapshot(); 68 | } 69 | 70 | [Fact] 71 | public async Task Ensure_Validation_Works_On_NonDuplicateEmail() 72 | { 73 | var result = await ExecuteRequest("{ checkDuplicateEmail( email: \"sai@gmail.com\" ) }"); 74 | 75 | result.MatchSnapshot(); 76 | } 77 | 78 | [Fact] 79 | public async Task Ensure_Validation_Works_On_StudentWithScoreCard() 80 | { 81 | var result = await ExecuteRequest("query{checkPass(student: { firstName: \"Varun\",scoreCard: { school: \"Gayatri\",totalScore: 85} })}"); 82 | 83 | result.MatchSnapshot(); 84 | } 85 | 86 | [Fact] 87 | public async Task Ensure_Validation_Works_On_StudentWithOutScoreCard() 88 | { 89 | var result = await ExecuteRequest("query{checkPass(student: { firstName: \"Varun\"})}"); 90 | 91 | result.MatchSnapshot(); 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/ValidationTypeInterceptor.cs: -------------------------------------------------------------------------------- 1 | using HotChocolate.Configuration; 2 | using HotChocolate.Resolvers; 3 | using HotChocolate.Types.Descriptors.Definitions; 4 | using System.Collections.Generic; 5 | using System.ComponentModel.DataAnnotations; 6 | using System.Linq; 7 | 8 | namespace Graph.ArgumentValidator 9 | { 10 | internal delegate void Validate(object value, ValidationContext validationContext, ICollection validationResults); 11 | 12 | internal class ValidationTypeInterceptor : TypeInterceptor 13 | { 14 | private FieldMiddleware _middleware; 15 | 16 | public override void OnBeforeCompleteType( 17 | ITypeCompletionContext completionContext, 18 | DefinitionBase definition) 19 | { 20 | if (definition is ObjectTypeDefinition objectTypeDef) 21 | { 22 | foreach (var fieldDef in objectTypeDef.Fields) 23 | { 24 | // most fields do not need validation. 25 | bool needValidation = false; 26 | 27 | foreach (var argumentDef in fieldDef.Arguments) 28 | { 29 | if (argumentDef.Parameter is not null && 30 | argumentDef.Parameter.IsDefined(typeof(ValidationAttribute), true)) 31 | { 32 | var attributes = argumentDef.Parameter 33 | .GetCustomAttributes(typeof(ValidationAttribute), true) 34 | .OfType() 35 | .ToArray(); 36 | 37 | // we will set a marker for this argument to be validated. 38 | argumentDef.ContextData[WellKnownContextData.ValidationDelegate] = 39 | new Validate((value, context, errors) => Validator.TryValidateValue(value, context, errors, attributes)); 40 | needValidation = true; 41 | } 42 | else if (argumentDef.Parameter is not null && 43 | argumentDef.Parameter.ParameterType.IsDefined(typeof(ValidatableAttribute), true)) 44 | { 45 | // we will set a marker for this argument to be validated. 46 | argumentDef.ContextData[WellKnownContextData.ValidationDelegate] = 47 | new Validate((value, context, errors) => Validator.TryValidateObject(value, context, errors, true)); 48 | needValidation = true; 49 | } 50 | } 51 | 52 | if (needValidation) 53 | { 54 | // if validation is needed we will ensure that a validation middleware exists. 55 | if (_middleware is null) 56 | { 57 | // if no middleware is yet created we will compile a middleware from our 58 | // ValidationMiddleware class. 59 | _middleware = FieldClassMiddlewareFactory.Create(); 60 | } 61 | 62 | // we add the validation middleware to the first spot so that validation is executed first. 63 | fieldDef.MiddlewareDefinitions.Insert(0, new FieldMiddlewareDefinition(_middleware)); 64 | } 65 | } 66 | } 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Graph.ArgumentValidator 2 | 3 | ## Adds support for validating input arguments in HotChocolate 4 | 5 | NuGet Version 6 | NuGet Downloads 7 | 8 | Generally, we use attributes from System.ComponentModel.DataAnnotations for validating our input models in controllers. 9 | 10 | 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. 11 | 12 | [!["Buy Me A Coffee"](https://cdn.buymeacoffee.com/assets/img/home-page-v3/bmc-new-logo.png)](https://www.buymeacoffee.com/varunteja) 13 | 14 | 15 | **Installation Note**: 16 | 17 | Use Graph.ArgumentValidator v4.0.0 if you are using HotChocolate v14. 18 | 19 | Use Graph.ArgumentValidator v3.0.0 if you are using HotChocolate v13. 20 | 21 | Use Graph.ArgumentValidator v2.0.0 if you are using HotChocolate v12. 22 | 23 | Use Graph.ArgumentValidator v1.0.1 if you are using HotChocolate v11. 24 | 25 | 26 | **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 the below steps. 27 | 28 | 29 | ## Steps for configuring validator 30 | 31 | 32 | ### Step 1 33 | Go to StartUp.cs file and inside ConfigureServices make the following changes. 34 | 35 | ### Step 2 36 | Add argument validator to services by referring to below code 37 | ```csharp 38 | services 39 | .AddGraphQLServer() 40 | .AddArgumentValidator(); 41 | ``` 42 | 43 | 44 | ### Step 3 45 | Just add the `Validatable` attribute to all the classes you defined for input. 46 | 47 | Ex: 48 | ```csharp 49 | using System.ComponentModel.DataAnnotations; 50 | using Graph.ArgumentValidator; 51 | 52 | namespace Demo 53 | { 54 | [Validatable] 55 | public class RegisterUserInput 56 | { 57 | [Required, MinLength(4, ErrorMessage = "Username must be atleast 4 characters.")] 58 | public string UserName { get; set; } 59 | 60 | [Required, EmailAddress(ErrorMessage = "Email Id format is invalid.")] 61 | public string Email { get; set; } 62 | 63 | [Required, RegularExpression(@"^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$", ErrorMessage = "Password needs to be more strong.")] 64 | public string Password { get; set; } 65 | 66 | [Compare(nameof(Password), ErrorMessage = "Passwords do not match!")] 67 | public string ConfirmPassword { get; set; } 68 | } 69 | 70 | public class UserMutations 71 | { 72 | public int RegisterUser(RegisterUserInput input, [Service] UserService userService) 73 | { 74 | return userService.RegisterUser(input); 75 | } 76 | } 77 | } 78 | ``` 79 | 80 | Another way of providing inline validation for Primitive data types 81 | ```csharp 82 | using System.ComponentModel.DataAnnotations; 83 | using Graph.ArgumentValidator; 84 | 85 | namespace Demo 86 | { 87 | public class Mutations 88 | { 89 | public bool RegisterUserPhone([Required(ErrorMessage = "Email is required")string email, 90 | [Phone(ErrorMessage = "Invalid Phone Number")] string phone) 91 | { 92 | return userService.RegisterUserPhone(email,phone); 93 | } 94 | } 95 | } 96 | ``` 97 | 98 | 99 | When the user is given the following wrong values to the mutation input 100 | ```graphql 101 | mutation{ 102 | registerUser(input:{userName:"va2", password:"weak", confirmPassword:"strong", email:"varun"}) 103 | } 104 | ``` 105 | 106 | This is the response we got from GraphQL Server 107 | ```json 108 | { 109 | "errors": [ 110 | { 111 | "message": "Username must be atleast 4 characters.", 112 | "path": [ 113 | "input" 114 | ], 115 | "extensions": { 116 | "field": "userName" 117 | } 118 | }, 119 | { 120 | "message": "Email Id format is invalid.", 121 | "path": [ 122 | "input" 123 | ], 124 | "extensions": { 125 | "field": "email" 126 | } 127 | }, 128 | { 129 | "message": "Password needs to be more strong.", 130 | "path": [ 131 | "input" 132 | ], 133 | "extensions": { 134 | "field": "password" 135 | } 136 | }, 137 | { 138 | "message": "Passwords do not match!", 139 | "path": [ 140 | "input" 141 | ], 142 | "extensions": { 143 | "field": "confirmPassword" 144 | } 145 | } 146 | ] 147 | } 148 | ``` 149 | -------------------------------------------------------------------------------- /Graph.ArgumentValidator.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.1.32228.430 5 | MinimumVisualStudioVersion = 15.0.26124.0 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Graph.ArgumentValidator", "src\Graph.ArgumentValidator.csproj", "{59435C05-1155-47A5-9361-2702B320EB83}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Graph.ArgumentValidator.Tests", "test\Graph.ArgumentValidator.Tests.csproj", "{F31CE4C8-0B88-492B-9AE2-92D731D51B88}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample", "Sample\Sample.csproj", "{F7DE9337-9B11-4126-B6BD-233DA24E5EA1}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared", "Shared\Shared.csproj", "{60CAB6E7-8015-4A6C-91CB-EDAB13A09F3D}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Debug|x64 = Debug|x64 18 | Debug|x86 = Debug|x86 19 | Release|Any CPU = Release|Any CPU 20 | Release|x64 = Release|x64 21 | Release|x86 = Release|x86 22 | EndGlobalSection 23 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 24 | {59435C05-1155-47A5-9361-2702B320EB83}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {59435C05-1155-47A5-9361-2702B320EB83}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {59435C05-1155-47A5-9361-2702B320EB83}.Debug|x64.ActiveCfg = Debug|Any CPU 27 | {59435C05-1155-47A5-9361-2702B320EB83}.Debug|x64.Build.0 = Debug|Any CPU 28 | {59435C05-1155-47A5-9361-2702B320EB83}.Debug|x86.ActiveCfg = Debug|Any CPU 29 | {59435C05-1155-47A5-9361-2702B320EB83}.Debug|x86.Build.0 = Debug|Any CPU 30 | {59435C05-1155-47A5-9361-2702B320EB83}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {59435C05-1155-47A5-9361-2702B320EB83}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {59435C05-1155-47A5-9361-2702B320EB83}.Release|x64.ActiveCfg = Release|Any CPU 33 | {59435C05-1155-47A5-9361-2702B320EB83}.Release|x64.Build.0 = Release|Any CPU 34 | {59435C05-1155-47A5-9361-2702B320EB83}.Release|x86.ActiveCfg = Release|Any CPU 35 | {59435C05-1155-47A5-9361-2702B320EB83}.Release|x86.Build.0 = Release|Any CPU 36 | {F31CE4C8-0B88-492B-9AE2-92D731D51B88}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 37 | {F31CE4C8-0B88-492B-9AE2-92D731D51B88}.Debug|Any CPU.Build.0 = Debug|Any CPU 38 | {F31CE4C8-0B88-492B-9AE2-92D731D51B88}.Debug|x64.ActiveCfg = Debug|Any CPU 39 | {F31CE4C8-0B88-492B-9AE2-92D731D51B88}.Debug|x64.Build.0 = Debug|Any CPU 40 | {F31CE4C8-0B88-492B-9AE2-92D731D51B88}.Debug|x86.ActiveCfg = Debug|Any CPU 41 | {F31CE4C8-0B88-492B-9AE2-92D731D51B88}.Debug|x86.Build.0 = Debug|Any CPU 42 | {F31CE4C8-0B88-492B-9AE2-92D731D51B88}.Release|Any CPU.ActiveCfg = Release|Any CPU 43 | {F31CE4C8-0B88-492B-9AE2-92D731D51B88}.Release|Any CPU.Build.0 = Release|Any CPU 44 | {F31CE4C8-0B88-492B-9AE2-92D731D51B88}.Release|x64.ActiveCfg = Release|Any CPU 45 | {F31CE4C8-0B88-492B-9AE2-92D731D51B88}.Release|x64.Build.0 = Release|Any CPU 46 | {F31CE4C8-0B88-492B-9AE2-92D731D51B88}.Release|x86.ActiveCfg = Release|Any CPU 47 | {F31CE4C8-0B88-492B-9AE2-92D731D51B88}.Release|x86.Build.0 = Release|Any CPU 48 | {F7DE9337-9B11-4126-B6BD-233DA24E5EA1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 49 | {F7DE9337-9B11-4126-B6BD-233DA24E5EA1}.Debug|Any CPU.Build.0 = Debug|Any CPU 50 | {F7DE9337-9B11-4126-B6BD-233DA24E5EA1}.Debug|x64.ActiveCfg = Debug|Any CPU 51 | {F7DE9337-9B11-4126-B6BD-233DA24E5EA1}.Debug|x64.Build.0 = Debug|Any CPU 52 | {F7DE9337-9B11-4126-B6BD-233DA24E5EA1}.Debug|x86.ActiveCfg = Debug|Any CPU 53 | {F7DE9337-9B11-4126-B6BD-233DA24E5EA1}.Debug|x86.Build.0 = Debug|Any CPU 54 | {F7DE9337-9B11-4126-B6BD-233DA24E5EA1}.Release|Any CPU.ActiveCfg = Release|Any CPU 55 | {F7DE9337-9B11-4126-B6BD-233DA24E5EA1}.Release|Any CPU.Build.0 = Release|Any CPU 56 | {F7DE9337-9B11-4126-B6BD-233DA24E5EA1}.Release|x64.ActiveCfg = Release|Any CPU 57 | {F7DE9337-9B11-4126-B6BD-233DA24E5EA1}.Release|x64.Build.0 = Release|Any CPU 58 | {F7DE9337-9B11-4126-B6BD-233DA24E5EA1}.Release|x86.ActiveCfg = Release|Any CPU 59 | {F7DE9337-9B11-4126-B6BD-233DA24E5EA1}.Release|x86.Build.0 = Release|Any CPU 60 | {60CAB6E7-8015-4A6C-91CB-EDAB13A09F3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 61 | {60CAB6E7-8015-4A6C-91CB-EDAB13A09F3D}.Debug|Any CPU.Build.0 = Debug|Any CPU 62 | {60CAB6E7-8015-4A6C-91CB-EDAB13A09F3D}.Debug|x64.ActiveCfg = Debug|Any CPU 63 | {60CAB6E7-8015-4A6C-91CB-EDAB13A09F3D}.Debug|x64.Build.0 = Debug|Any CPU 64 | {60CAB6E7-8015-4A6C-91CB-EDAB13A09F3D}.Debug|x86.ActiveCfg = Debug|Any CPU 65 | {60CAB6E7-8015-4A6C-91CB-EDAB13A09F3D}.Debug|x86.Build.0 = Debug|Any CPU 66 | {60CAB6E7-8015-4A6C-91CB-EDAB13A09F3D}.Release|Any CPU.ActiveCfg = Release|Any CPU 67 | {60CAB6E7-8015-4A6C-91CB-EDAB13A09F3D}.Release|Any CPU.Build.0 = Release|Any CPU 68 | {60CAB6E7-8015-4A6C-91CB-EDAB13A09F3D}.Release|x64.ActiveCfg = Release|Any CPU 69 | {60CAB6E7-8015-4A6C-91CB-EDAB13A09F3D}.Release|x64.Build.0 = Release|Any CPU 70 | {60CAB6E7-8015-4A6C-91CB-EDAB13A09F3D}.Release|x86.ActiveCfg = Release|Any CPU 71 | {60CAB6E7-8015-4A6C-91CB-EDAB13A09F3D}.Release|x86.Build.0 = Release|Any CPU 72 | EndGlobalSection 73 | GlobalSection(SolutionProperties) = preSolution 74 | HideSolutionNode = FALSE 75 | EndGlobalSection 76 | GlobalSection(ExtensibilityGlobals) = postSolution 77 | SolutionGuid = {F48721F7-2E9A-45D3-B934-6F1C154AB522} 78 | EndGlobalSection 79 | EndGlobal 80 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # JetBrains IDE files 131 | .idea/ 132 | 133 | # ReSharper is a .NET coding add-in 134 | _ReSharper*/ 135 | *.[Rr]e[Ss]harper 136 | *.DotSettings.user 137 | 138 | # TeamCity is a build add-in 139 | _TeamCity* 140 | 141 | # DotCover is a Code Coverage Tool 142 | *.dotCover 143 | 144 | # AxoCover is a Code Coverage Tool 145 | .axoCover/* 146 | !.axoCover/settings.json 147 | 148 | # Coverlet is a free, cross platform Code Coverage Tool 149 | coverage*.json 150 | coverage*.xml 151 | coverage*.info 152 | 153 | # Visual Studio code coverage results 154 | *.coverage 155 | *.coveragexml 156 | 157 | # NCrunch 158 | _NCrunch_* 159 | .*crunch*.local.xml 160 | nCrunchTemp_* 161 | 162 | # MightyMoose 163 | *.mm.* 164 | AutoTest.Net/ 165 | 166 | # Web workbench (sass) 167 | .sass-cache/ 168 | 169 | # Installshield output folder 170 | [Ee]xpress/ 171 | 172 | # DocProject is a documentation generator add-in 173 | DocProject/buildhelp/ 174 | DocProject/Help/*.HxT 175 | DocProject/Help/*.HxC 176 | DocProject/Help/*.hhc 177 | DocProject/Help/*.hhk 178 | DocProject/Help/*.hhp 179 | DocProject/Help/Html2 180 | DocProject/Help/html 181 | 182 | # Click-Once directory 183 | publish/ 184 | 185 | # Publish Web Output 186 | *.[Pp]ublish.xml 187 | *.azurePubxml 188 | # Note: Comment the next line if you want to checkin your web deploy settings, 189 | # but database connection strings (with potential passwords) will be unencrypted 190 | *.pubxml 191 | *.publishproj 192 | 193 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 194 | # checkin your Azure Web App publish settings, but sensitive information contained 195 | # in these scripts will be unencrypted 196 | PublishScripts/ 197 | 198 | # NuGet Packages 199 | *.nupkg 200 | # NuGet Symbol Packages 201 | *.snupkg 202 | # The packages folder can be ignored because of Package Restore 203 | **/[Pp]ackages/* 204 | # except build/, which is used as an MSBuild target. 205 | !**/[Pp]ackages/build/ 206 | # Uncomment if necessary however generally it will be regenerated when needed 207 | #!**/[Pp]ackages/repositories.config 208 | # NuGet v3's project.json files produces more ignorable files 209 | *.nuget.props 210 | *.nuget.targets 211 | 212 | # Microsoft Azure Build Output 213 | csx/ 214 | *.build.csdef 215 | 216 | # Microsoft Azure Emulator 217 | ecf/ 218 | rcf/ 219 | 220 | # Windows Store app package directories and files 221 | AppPackages/ 222 | BundleArtifacts/ 223 | Package.StoreAssociation.xml 224 | _pkginfo.txt 225 | *.appx 226 | *.appxbundle 227 | *.appxupload 228 | 229 | # Visual Studio cache files 230 | # files ending in .cache can be ignored 231 | *.[Cc]ache 232 | # but keep track of directories ending in .cache 233 | !?*.[Cc]ache/ 234 | 235 | # Others 236 | ClientBin/ 237 | ~$* 238 | *~ 239 | *.dbmdl 240 | *.dbproj.schemaview 241 | *.jfm 242 | *.pfx 243 | *.publishsettings 244 | orleans.codegen.cs 245 | 246 | # Including strong name files can present a security risk 247 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 248 | #*.snk 249 | 250 | # Since there are multiple workflows, uncomment next line to ignore bower_components 251 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 252 | #bower_components/ 253 | 254 | # RIA/Silverlight projects 255 | Generated_Code/ 256 | 257 | # Backup & report files from converting an old project file 258 | # to a newer Visual Studio version. Backup files are not needed, 259 | # because we have git ;-) 260 | _UpgradeReport_Files/ 261 | Backup*/ 262 | UpgradeLog*.XML 263 | UpgradeLog*.htm 264 | ServiceFabricBackup/ 265 | *.rptproj.bak 266 | 267 | # SQL Server files 268 | *.mdf 269 | *.ldf 270 | *.ndf 271 | 272 | # Business Intelligence projects 273 | *.rdl.data 274 | *.bim.layout 275 | *.bim_*.settings 276 | *.rptproj.rsuser 277 | *- [Bb]ackup.rdl 278 | *- [Bb]ackup ([0-9]).rdl 279 | *- [Bb]ackup ([0-9][0-9]).rdl 280 | 281 | # Microsoft Fakes 282 | FakesAssemblies/ 283 | 284 | # GhostDoc plugin setting file 285 | *.GhostDoc.xml 286 | 287 | # Node.js Tools for Visual Studio 288 | .ntvs_analysis.dat 289 | node_modules/ 290 | 291 | # Visual Studio 6 build log 292 | *.plg 293 | 294 | # Visual Studio 6 workspace options file 295 | *.opt 296 | 297 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 298 | *.vbw 299 | 300 | # Visual Studio LightSwitch build output 301 | **/*.HTMLClient/GeneratedArtifacts 302 | **/*.DesktopClient/GeneratedArtifacts 303 | **/*.DesktopClient/ModelManifest.xml 304 | **/*.Server/GeneratedArtifacts 305 | **/*.Server/ModelManifest.xml 306 | _Pvt_Extensions 307 | 308 | # Paket dependency manager 309 | .paket/paket.exe 310 | paket-files/ 311 | 312 | # FAKE - F# Make 313 | .fake/ 314 | 315 | # CodeRush personal settings 316 | .cr/personal 317 | 318 | # Python Tools for Visual Studio (PTVS) 319 | __pycache__/ 320 | *.pyc 321 | 322 | # Cake - Uncomment if you are using it 323 | # tools/** 324 | # !tools/packages.config 325 | 326 | # Tabs Studio 327 | *.tss 328 | 329 | # Telerik's JustMock configuration file 330 | *.jmconfig 331 | 332 | # BizTalk build output 333 | *.btp.cs 334 | *.btm.cs 335 | *.odx.cs 336 | *.xsd.cs 337 | 338 | # OpenCover UI analysis results 339 | OpenCover/ 340 | 341 | # Azure Stream Analytics local run output 342 | ASALocalRun/ 343 | 344 | # MSBuild Binary and Structured Log 345 | *.binlog 346 | 347 | # NVidia Nsight GPU debugger configuration file 348 | *.nvuser 349 | 350 | # MFractors (Xamarin productivity tool) working folder 351 | .mfractor/ 352 | 353 | # Local History for Visual Studio 354 | .localhistory/ 355 | 356 | # BeatPulse healthcheck temp database 357 | healthchecksdb 358 | 359 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 360 | MigrationBackup/ 361 | 362 | # Ionide (cross platform F# VS Code tools) working folder 363 | .ionide/ 364 | 365 | # Fody - auto-generated XML schema 366 | FodyWeavers.xsd --------------------------------------------------------------------------------