Visit() 공개 메소드

public Visit ( INode node ) : void
node INode
리턴 void
예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
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);
        }
예제 #4
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);
        }
        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;
        }
예제 #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;
        }