コード例 #1
0
        public static async Task ValidateAsync(this IField field, JToken value, ValidationContext context, Action <string> addError)
        {
            try
            {
                var typedValue = value.IsNull() ? null : JsonValueConverter.ConvertValue(field, value);

                foreach (var validator in ValidatorsFactory.CreateValidators(field))
                {
                    await validator.ValidateAsync(typedValue, context, addError);
                }
            }
            catch
            {
                addError("<FIELD> is not a valid value.");
            }
        }
コード例 #2
0
        private IValidator CreateFieldValidator(IRootField field, bool isPartial)
        {
            var partitioning = partitionResolver(field.Partitioning);

            var fieldValidator   = new FieldValidator(ValidatorsFactory.CreateValidators(field).ToArray(), field);
            var fieldsValidators = new Dictionary <string, (bool IsOptional, IValidator Validator)>();

            foreach (var partition in partitioning)
            {
                fieldsValidators[partition.Key] = (partition.IsOptional, fieldValidator);
            }

            var isLanguage = field.Partitioning.Equals(Partitioning.Language);

            var type = isLanguage ? "language" : "invariant value";

            return(new ObjectValidator <IJsonValue>(fieldsValidators, isPartial, type, JsonValue.Null));
        }