Exemple #1
0
        private void HandleType(object value, InputObjectType type,
                                IReadOnlyCollection <IDirective> directives, FieldValidationContext ctx)
        {
            if (value == null)
            {
                return;
            }

            ValidateValue(value, directives, ctx);

            foreach (var field in type.Fields)
            {
                var fieldValue      = field.GetValue(value);
                var fieldDirectives = GetValidationDirectives(field.Directives);
                var childCtx        = new FieldValidationContext(field.Name);
                HandleInput(fieldValue, field.Type, fieldDirectives, childCtx);
                ctx.AddErrored(childCtx);
            }
        }
Exemple #2
0
        public Task Run(IMiddlewareContext context, FieldDelegate next)
        {
            var rootCtx = new FieldValidationContext(context.Field.Name);

            foreach (var inputField in context.Field.Arguments)
            {
                var directives = GetValidationDirectives(inputField.Directives);
                var value      = context.Argument <object>(inputField.Name);
                var ctx        = new FieldValidationContext(inputField.Name);
                HandleInput(value, inputField.Type, directives, ctx);
                rootCtx.AddErrored(ctx);
            }

            if (rootCtx.HasErrors())
            {
                var errorsProperty = new ErrorProperty("FieldValidationError", rootCtx);
                var error          = new QueryError("Invalid input data", errorsProperty);

                throw new QueryException(error);
            }

            return(next.Invoke(context));
        }
Exemple #3
0
        private void HandleType(object value, ListType type,
                                IReadOnlyCollection <IDirective> directives, FieldValidationContext ctx)
        {
            if (value == null)
            {
                return;
            }

            ValidateValue(value, directives, ctx);

            if (type.ElementType is IInputType)
            {
                var list         = (IEnumerable)value;
                var elementType  = (IInputType)type.ElementType;
                var elementIndex = 0;

                foreach (var element in list)
                {
                    var childCtx = new FieldValidationContext((elementIndex++).ToString());
                    HandleInput(element, elementType, null, childCtx);
                    ctx.AddErrored(childCtx);
                }
            }
        }