public void Validate_Input_With_Non_Null_Props_That_Have_No_Value_And_No_DefaultValue() { // arrange ISchema schema = SchemaBuilder.New() .AddDocumentFromString(@" type Query { test(bar: Bar): String } input Bar { a: String! } ") .Use(next => context => default(ValueTask)) .Create(); IInputField field = schema.QueryType.Fields["test"].Arguments["bar"]; // act var report = ArgumentNonNullValidator.Validate( field, new ObjectValueNode(), Path.New("root")); // assert Assert.True(report.HasErrors); Assert.Equal("/root/a", report.Path.ToString()); }
public void Validate_Input_With_Non_Null_Props_That_Have_No_Value_But_A_DefaultValue() { // arrange ISchema schema = SchemaBuilder.New() .AddDocumentFromString(@" type Query { test(bar: Bar): String } input Bar { a: String! = ""bar"" } ") .Use(next => context => Task.CompletedTask) .Create(); IInputField field = schema.QueryType.Fields["test"].Arguments["bar"]; // act Report report = ArgumentNonNullValidator.Validate( field, new ObjectValueNode(), Path.New("root")); // assert Assert.False(report.HasErrors); }
private void CreateArgumentValue( FieldInfo fieldInfo, IInputField argument, IValueNode literal) { if (fieldInfo.Arguments == null) { fieldInfo.Arguments = new Dictionary <NameString, ArgumentValue>(); } Report report = ArgumentNonNullValidator.Validate( argument.Type, literal, Path.New(argument.Name)); if (report.HasErrors) { IError error = ErrorBuilder.New() .SetMessage(string.Format( CultureInfo.InvariantCulture, TypeResources.ArgumentValueBuilder_NonNull, argument.Name, TypeVisualizer.Visualize(report.Type))) .AddLocation(fieldInfo.Selection) .SetExtension(_argumentProperty, report.Path.ToCollection()) .SetPath(fieldInfo.Path.AppendOrCreate( fieldInfo.ResponseName)) .Build(); fieldInfo.Arguments[argument.Name] = new ArgumentValue(argument, error); } else if (argument.Type.IsLeafType() && IsLeafLiteral(literal)) { object coerced = CoerceArgumentValue(argument, ParseLiteral(argument.Type, literal)); fieldInfo.Arguments[argument.Name] = new ArgumentValue( argument, literal.GetValueKind(), coerced); } else { object coerced = CoerceArgumentValue(argument, literal); fieldInfo.Arguments[argument.Name] = new ArgumentValue( argument, literal.GetValueKind(), coerced); } }