dalrankov / fluentchoco Goto Github PK
View Code? Open in Web Editor NEWFluentValidation middleware for HotChocolate GraphQL
License: MIT License
FluentValidation middleware for HotChocolate GraphQL
License: MIT License
here's the error it throws
message: "Method not found: '!!0 HotChocolate.Resolvers.IResolverContext.ArgumentValue(HotChocolate.NameString)'."
stackTrace: " at FluentChoco.FluentValidationMiddleware.Invoke(IMiddlewareContext context)\r\n at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)\r\n at FluentChoco.FluentValidationMiddleware.Invoke(IMiddlewareContext context)\r\n at lambda_method7916(Closure , IMiddlewareContext , FluentValidationMiddleware )\r\n at HotChocolate.Resolvers.FieldClassMiddlewareFactory.<>c__DisplayClass5_0`1.<CreateDelegate>b__1(IMiddlewareContext context)\r\n at HotChocolate.AspNetCore.Authorization.AuthorizeMiddleware.InvokeAsync(IDirectiveContext context)\r\n at HotChocolate.Utilities.MiddlewareCompiler`1.ExpressionHelper.AwaitTaskHelper(Task task)\r\n at HotChocolate.Execution.Processing.Tasks.ResolverTask.ExecuteResolverPipelineAsync(CancellationToken cancellationToken)\r\n at HotChocolate.Execution.Processing.Tasks.ResolverTask.TryExecuteAsync(CancellationToken cancellationToken)"
removing the UseFluentValidation()
won't trigger that error but the fluent validation won't work anymore.
When I add .UseFluentValidation() on HotChocolate version 12.6.1, it throws the following error
message: "Method not found: 'HotChocolate.Types.IFieldCollection`1<HotChocolate.Types.IInputField> HotChocolate.Types.IOutputField.get_Arguments()'."
stackTrace: " at FluentChoco.FluentValidationMiddleware.Invoke(IMiddlewareContext context)\r\n at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)\r\n at FluentChoco.FluentValidationMiddleware.Invoke(IMiddlewareContext context)\r\n at lambda_method4315(Closure , IMiddlewareContext , FluentValidationMiddleware )\r\n at HotChocolate.Resolvers.FieldClassMiddlewareFactory.<>c__DisplayClass5_0`1.<CreateDelegate>b__1(IMiddlewareContext context)\r\n at HotChocolate.AspNetCore.Authorization.AuthorizeMiddleware.InvokeAsync(IDirectiveContext context)\r\n at HotChocolate.Utilities.MiddlewareCompiler`1.ExpressionHelper.AwaitTaskHelper(Task task)\r\n at HotChocolate.Execution.Processing.Tasks.ResolverTask.ExecuteResolverPipelineAsync(CancellationToken cancellationToken)\r\n at HotChocolate.Execution.Processing.Tasks.ResolverTask.TryExecuteAsync(CancellationToken cancellationToken)"
{
"errors": [
{
"message": "Unexpected Execution Error",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"addUser"
],
"extensions": {
"message": "Method not found: 'System.Collections.Generic.IReadOnlyDictionary`2<System.String,System.Object> HotChocolate.Types.IField.get_ContextData()'.",
"stackTrace": " at FluentChoco.ArgumentValidationOptions`1..ctor(IInputField argument, TArgument instance)\r\n at FluentChoco.FluentValidationMiddleware.Invoke(IMiddlewareContext context)\r\n at HotChocolate.Utilities.MiddlewareCompiler`1.ExpressionHelper.AwaitTaskHelper(Task task)\r\n at HotChocolate.Execution.Processing.ResolverTask.ExecuteResolverPipelineAsync(CancellationToken cancellationToken)\r\n at HotChocolate.Execution.Processing.ResolverTask.TryExecuteAsync(CancellationToken cancellationToken)"
}
}
]
}
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 must be atleast 8 characters, at least one uppercase letter, one lowercase letter, one number and one special character.")]
public string Password { get; set; }
}
}
Startup.cs
services.RegisterFluentValidators<Startup>();
services.AddGraphQLServer()
.UseFluentValidation<CustomErrorBuilder>()
CustomErrorBuilder
public class CustomErrorBuilder
: IValidationErrorBuilder
{
public IErrorBuilder BuildError(
IErrorBuilder builder,
ValidationFailure failure,
IInputField argument,
IMiddlewareContext context)
{
return builder.SetMessage(failure.ErrorMessage);
}
}
[ExtendObjectType(Name = "Mutation")]
public class UserMutations : BaseGraphQL
{
public async Task<int> AddUser(AddUserInput input, [Service] MailService mailService, [Service] UserManager<AppUser> userManager)
{
//Code for adding user
}
}
Did I miss anything ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.