Esempio n. 1
0
        public object TranslatePerDefinition(object inputObject, GraphQLBaseType typeDefinition)
        {
            if (typeDefinition is GraphQLNonNull)
            {
                return(this.TranslatePerDefinition(inputObject, ((GraphQLNonNull)typeDefinition).UnderlyingNullableType));
            }

            if (typeDefinition is GraphQLInputObjectType)
            {
                return(this.CreateObjectFromDynamic((GraphQLInputObjectType)typeDefinition, (ExpandoObject)inputObject));
            }

            if (typeDefinition is GraphQLList)
            {
                if (inputObject == null)
                {
                    return(null);
                }

                if (ReflectionUtilities.IsCollection(inputObject.GetType()))
                {
                    return(ReflectionUtilities.ChangeValueType(this.CreateList((IEnumerable)inputObject, (GraphQLList)typeDefinition), this.schemaRepository.GetInputSystemTypeFor(typeDefinition)));
                }

                return(this.CreateSingleValueList(inputObject, (GraphQLList)typeDefinition));
            }

            return(inputObject);
        }
Esempio n. 2
0
        public void InputVariable_TypeInt32TooLarge_ReturnsNull()
        {
            Int64 inputVariable = Int64.MaxValue;
            var   result        = ReflectionUtilities.ChangeValueType(inputVariable, typeof(Int32));

            Assert.IsNull(result);
        }
Esempio n. 3
0
        public void InputVariable_TypeInt32_ReturnsCorrectly()
        {
            Int64 inputVariable = 123456789;
            var   result        = ReflectionUtilities.ChangeValueType(inputVariable, typeof(Int32));

            Assert.AreEqual(inputVariable, result);
        }
        private void AssignValueToObjectField(T result, GraphQLInputObjectTypeFieldInfo field, object value)
        {
            value = ReflectionUtilities.ChangeValueType(value, field.SystemType);

            ReflectionUtilities.MakeSetterFromLambda(field.Lambda)
            .DynamicInvoke(result, value);
        }
Esempio n. 5
0
        public void ChangeValueType_NonEnumerableToEnumerable_ReturnsNull()
        {
            var result  = ReflectionUtilities.ChangeValueType(1, typeof(int[]));
            var result2 = ReflectionUtilities.ChangeValueType("test", typeof(List <string>));

            Assert.IsNull(result);
            Assert.IsNull(result2);
        }
Esempio n. 6
0
        private IEnumerable CreateSingleValueList(object inputObject, GraphQLList typeDefinition)
        {
            var systemType = this.schemaRepository.GetInputSystemTypeFor(typeDefinition.MemberType);

            var singleValue = this.TranslatePerDefinition(inputObject, typeDefinition.MemberType);

            singleValue = ReflectionUtilities.ChangeValueType(singleValue, systemType);

            yield return(singleValue);
        }
Esempio n. 7
0
        public object TranslatePerDefinition(object inputObject, Type type)
        {
            var typeDefinition = this.GetType(type);

            if (inputObject is ExpandoObject && typeDefinition is GraphQLObjectType)
            {
                return(this.CreateObjectFromDynamic((GraphQLObjectType)typeDefinition, (ExpandoObject)inputObject));
            }

            return(ReflectionUtilities.ChangeValueType(inputObject, type));
        }
Esempio n. 8
0
        public object TranslatePerDefinition(object inputObject, GraphQLScalarType typeDefinition)
        {
            if (inputObject is ExpandoObject && typeDefinition is GraphQLObjectType)
            {
                return(this.CreateObjectFromDynamic((GraphQLObjectType)typeDefinition, (ExpandoObject)inputObject));
            }

            var systemType = this.GetType(typeDefinition);

            return(ReflectionUtilities.ChangeValueType(inputObject, systemType));
        }
Esempio n. 9
0
        private object GetValueForArgument(IList <GraphQLArgument> arguments, ParameterExpression e, object parent)
        {
            if (this.IsContextType(e))
            {
                return(this.CreateContextObject(e.Type, parent));
            }

            return(ReflectionUtilities.ChangeValueType(
                       this.GetArgumentValue(
                           arguments,
                           e.Name,
                           this.context.SchemaRepository.GetSchemaInputTypeFor(e.Type)),
                       e.Type));
        }
Esempio n. 10
0
        public object TranslatePerDefinition(object inputObject, System.Type type)
        {
            if (inputObject == null)
            {
                return(null);
            }

            var typeDefinition = this.schemaRepository.GetSchemaInputTypeFor(type);

            if (inputObject is ExpandoObject && typeDefinition is GraphQLInputObjectType)
            {
                return(this.CreateObjectFromDynamic((GraphQLInputObjectType)typeDefinition, (ExpandoObject)inputObject));
            }

            if (ReflectionUtilities.IsCollection(inputObject.GetType()) && typeDefinition is GraphQLList)
            {
                return(ReflectionUtilities.ChangeValueType(this.CreateList((IEnumerable)inputObject, (GraphQLList)typeDefinition), type));
            }

            return(ReflectionUtilities.ChangeValueType(inputObject, type));
        }
Esempio n. 11
0
        public GraphQLException[] IsValidLiteralValue(GraphQLScalarType inputType, Language.AST.GraphQLValue astValue)
        {
            if (inputType is GraphQLNonNullType)
            {
                if (astValue == null)
                {
                    return(new GraphQLException[]
                    {
                        new GraphQLException($"Expected {inputType.Name ?? "non-null"} found null")
                    });
                }

                return(this.IsValidLiteralValue(((GraphQLNonNullType)inputType).UnderlyingNullableType, astValue));
            }

            if (astValue == null)
            {
                return new GraphQLException[] { }
            }
            ;

            if (astValue.Kind == Language.AST.ASTNodeKind.Variable) // this method is checking only literals
            {
                return new GraphQLException[] { }
            }
            ;

            object value = this.GetLiteralValue(astValue);

            try
            {
                ReflectionUtilities.ChangeValueType(value, this.GetType(inputType));
            }
            catch (Exception ex)
            {
                return(new GraphQLException[] { new GraphQLException($"Expected {inputType.Name ?? "non-null"} found null", ex) });
            }

            return(new GraphQLException[] { });
        }