public IValidationResult Validate( string originalQuery, ISchema schema, Document document, IEnumerable <IValidationRule> rules = null) { var context = new ValidationContext { OriginalQuery = originalQuery, Schema = schema, Document = document, TypeInfo = new TypeInfo(schema) }; if (rules == null) { rules = CoreRules(); } var visitors = rules.Select(x => x.Validate(context)).ToList(); visitors.Insert(0, context.TypeInfo); #if DEBUG visitors.Insert(1, new DebugNodeVisitor()); #endif var basic = new BasicVisitor(visitors.ToArray()); basic.Visit(document); var result = new ValidationResult(); result.Errors.AddRange(context.Errors); return(result); }
/// <inheritdoc/> public async Task <IValidationResult> ValidateAsync( string originalQuery, ISchema schema, Document document, IEnumerable <IValidationRule> rules = null, IDictionary <string, object> userContext = null, Inputs inputs = null) { if (!schema.Initialized) { schema.Initialize(); } var context = new ValidationContext { OriginalQuery = originalQuery, Schema = schema, Document = document, TypeInfo = new TypeInfo(schema), UserContext = userContext, Inputs = inputs }; if (rules == null) { rules = CoreRules; } var awaitedVisitors = rules.Select(x => x.ValidateAsync(context)); var visitors = (await Task.WhenAll(awaitedVisitors)).ToList(); visitors.Insert(0, context.TypeInfo); // #if DEBUG // visitors.Insert(1, new DebugNodeVisitor()); // #endif var basic = new BasicVisitor(visitors); basic.Visit(document); if (context.HasErrors) { return(new ValidationResult(context.Errors)); } return(SuccessfullyValidatedResult.Instance); }
public List <VariableUsage> GetVariables(IHaveSelectionSet node) { var usages = new List <VariableUsage>(); var info = new TypeInfo(Schema); var listener = new EnterLeaveListener(_ => { _.Match <VariableReference>( varRef => usages.Add(new VariableUsage(varRef, info.GetInputType())) ); }); var visitor = new BasicVisitor(info, listener); visitor.Visit(node); return(usages); }
public IValidationResult Validate( string originalQuery, ISchema schema, Document document, IEnumerable <IValidationRule> rules = null, object userContext = null, Inputs inputs = null) { if (!schema.Initialized) { schema.Initialize(); } var context = new ValidationContext { OriginalQuery = originalQuery, Schema = schema, Document = document, TypeInfo = new TypeInfo(schema), UserContext = userContext, Inputs = inputs }; if (rules == null) { rules = CoreRules(); } var visitors = rules.Select(x => x.Validate(context)).ToList(); visitors.Insert(0, context.TypeInfo); // #if DEBUG // visitors.Insert(1, new DebugNodeVisitor()); // #endif var basic = new BasicVisitor(visitors); basic.Visit(document); var result = new ValidationResult(); result.Errors.AddRange(context.Errors); return(result); }
public IValidationResult Validate( string originalQuery, ISchema schema, Document document, IEnumerable<IValidationRule> rules = null, object userContext = null) { if (!schema.Initialized) { schema.Initialize(); } var context = new ValidationContext { OriginalQuery = originalQuery, Schema = schema, Document = document, TypeInfo = new TypeInfo(schema), UserContext = userContext }; if (rules == null) { rules = CoreRules(); } var visitors = rules.Select(x => x.Validate(context)).ToList(); visitors.Insert(0, context.TypeInfo); // #if DEBUG // visitors.Insert(1, new DebugNodeVisitor()); // #endif var basic = new BasicVisitor(visitors.ToArray()); basic.Visit(document); var result = new ValidationResult(); result.Errors.AddRange(context.Errors); return result; }
public IEnumerable<VariableUsage> GetVariables(IHaveSelectionSet node) { var usages = new List<VariableUsage>(); var info = new TypeInfo(Schema); var listener = new EnterLeaveListener(_ => { _.Match<VariableReference>( varRef => usages.Add(new VariableUsage {Node = varRef, Type = info.GetInputType()}) ); }); var visitor = new BasicVisitor(info, listener); visitor.Visit(node); return usages; }