Ejemplo n.º 1
0
        private Object GetArgumentValue(IEdmTypeReference typeReference, GraphQLValue graphValue)
        {
            if (graphValue is GraphQLScalarValue scalarValue)
            {
                if (typeReference.IsString())
                {
                    return(scalarValue.Value);
                }

                return(ODataUriUtils.ConvertFromUriLiteral(scalarValue.Value, ODataVersion.V4, _edmModel, typeReference));
            }

            throw new NotSupportedException("argument " + graphValue.GetType().Name + " not supported");
        }
Ejemplo n.º 2
0
        private Object GetArgumentValue(IEdmTypeReference typeReference, GraphQLValue graphValue)
        {
            if (graphValue is GraphQLScalarValue scalarValue)
            {
                if (typeReference.IsString())
                {
                    return(scalarValue.Value);
                }

                return(ODataUriUtils.ConvertFromUriLiteral(scalarValue.Value, ODataVersion.V4, _edmModel, typeReference));
            }
            else if (graphValue is GraphQLVariable variable)
            {
                Type clrType = _edmModel.GetClrType(typeReference.Definition);
                return(_context.GetArgument(clrType, variable.Name.Value));
            }

            throw new NotSupportedException("Argument " + graphValue.GetType().Name + " not supported");
        }
Ejemplo n.º 3
0
    public void toAST_ok(Type graphType, object value)
    {
        if (graphType == typeof(BigIntGraphType))
        {
            value = new BigInteger(Convert.ToDecimal(value));
        }

        var g     = Create(graphType);
        var types = new Type[]
        {
            typeof(byte),
            typeof(sbyte),
            typeof(short),
            typeof(ushort),
            typeof(int),
            typeof(uint),
            typeof(long),
            typeof(ulong),
            typeof(BigInteger)
        };

        foreach (var type in types)
        {
            object converted;
            try
            {
                if (type == typeof(BigInteger))
                {
                    converted = new BigInteger((decimal)Convert.ChangeType(value, typeof(decimal)));
                }
                else
                {
                    converted = Convert.ChangeType(value, type);
                }
            }
            catch
            {
                continue;
            }
            var          astActual   = g.ToAST(converted);
            GraphQLValue astExpected = value switch
            {
                sbyte sb => new GraphQLIntValue(sb),
                byte b => new GraphQLIntValue(b),
                short s => new GraphQLIntValue(s),
                ushort us => new GraphQLIntValue(us),
                int i => new GraphQLIntValue(i),
                uint ui => new GraphQLIntValue(ui),
                long l => new GraphQLIntValue(l),
                ulong ul => new GraphQLIntValue(ul),
                BigInteger bi => new GraphQLIntValue(bi),
                float f => new GraphQLFloatValue(f),
                double d => new GraphQLFloatValue(d),
                _ => null
            };
            astActual.ShouldBeOfType(astExpected.GetType());
            astActual
            .ShouldBeAssignableTo <IHasValueNode>()
            .Value
            .ShouldBe(astExpected.ShouldBeAssignableTo <IHasValueNode>().Value);
        }
    }