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);
        }
Esempio n. 2
0
        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;
        }
Esempio n. 3
0
        /// <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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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;
        }