Skip to content

Commit

Permalink
Revert "Merge pull request #6 from Mehdigma/patch-1"
Browse files Browse the repository at this point in the history
This reverts commit 9238396, reversing
changes made to 202cf4b.
  • Loading branch information
VarunSaiTeja committed Jun 19, 2022
1 parent 9238396 commit 556af9d
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions src/ValidationMiddleware.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using HotChocolate;
using HotChocolate;
using HotChocolate.Resolvers;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;

namespace Graph.ArgumentValidator
Expand Down Expand Up @@ -31,7 +30,7 @@ public async Task InvokeAsync(IMiddlewareContext context)
{
var input = context.ArgumentValue<object>(argument.Name);
var validationContext = new ValidationContext(input, context.Services, null);
RecursiveValidate(input, context, errors);
validate(input, validationContext, errors);

if (errors.Any())
{
Expand All @@ -57,20 +56,5 @@ public async Task InvokeAsync(IMiddlewareContext context)
await _next(context);
}
}

public void RecursiveValidate(object input, IMiddlewareContext context, List<ValidationResult> errors)
{
var validationContext = new ValidationContext(input, context.Services, null);
Validator.TryValidateObject(input, validationContext, errors, true);

PropertyInfo[] props = input.GetType().GetProperties();
foreach (PropertyInfo prop in props)
{
object propInput = input.GetType().GetProperty(prop.Name).GetValue(input, null);
if (propInput != null && propInput.GetType().Namespace != "System")
RecursiveValidate(propInput, context, errors);
}

}
}
}

0 comments on commit 556af9d

Please sign in to comment.