public void BadFloatValues()
    {
        var type = new FloatGraphType();

        var value1 = new GraphQLFloatValue(_maxNumber);
        var value2 = new GraphQLFloatValue(_minNumber);

        type.CanParseLiteral(value1).ShouldBeFalse();
        type.CanParseLiteral(value2).ShouldBeFalse();

        Should.Throw <InvalidOperationException>(() => type.ParseLiteral(value1)).Message.ShouldStartWith("Unable to convert '1797693134862320000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0' literal from AST representation to the scalar type 'Float'");
        Should.Throw <InvalidOperationException>(() => type.ParseLiteral(value2)).Message.ShouldStartWith("Unable to convert '-1797693134862320000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0' literal from AST representation to the scalar type 'Float'");
    }
 public void coerces_null_to_null()
 {
     type.ParseValue(null).ShouldBeNull();
     type.ParseLiteral(new GraphQLNullValue()).ShouldBeNull();
 }
Beispiel #3
0
            public override object ParseLiteral(IValue value)
            {
                if (value is NullValue)
                {
                    return(null);
                }

                if (value is StringValue stringValue)
                {
                    return(ParseValue(stringValue.Value));
                }

                if (value is ObjectValue objectValue)
                {
                    var entries = objectValue.ObjectFields.ToDictionary(x => x.Name, x => _floatScalar.ParseLiteral(x.Value));
                    if (entries.Count != 3)
                    {
                        return(ThrowLiteralConversionError(value));
                    }
                    var x = (double)entries["x"];
                    var y = (double)entries["y"];
                    var z = (double)entries["z"];
                    return(new Vector3((float)x, (float)y, (float)z));
                }

                return(ThrowLiteralConversionError(value));
            }