Esempio n. 1
0
        public __Type(Type t, Dictionary <Type, __Type> resolver, GraphQlCustomiseSchema customise, bool isInputType = false)
        {
            this.resolver        = resolver;
            this.customiseSchema = customise;
            dotNetType           = t;

            if (resolver.ContainsKey(t) == false)
            {
                resolver[t] = this;
            }

            if (TypeCheck.IsNumeric(t) || TypeCheck.IsString(t) || TypeCheck.IsDateTime(t) || TypeCheck.IsBoolean(t))
            {
                ScalarType();
            }
            else if (TypeCheck.IsEnum(t))
            {
                EnumType();
            }
            else if (TypeCheck.IsEnumerableType(t))
            {
                ListType();
            }
            else if (TypeCheck.IsClass(t) && isInputType)
            {
                InputObjectType();
            }
            else if (TypeCheck.IsClass(t))
            {
                ObjectOrInterfaceType(__TypeKind.OBJECT);
            }
            else if (t.IsInterface)
            {
                ObjectOrInterfaceType(__TypeKind.INTERFACE);
            }
            else if (TypeCheck.IsValueType(t))
            {
                throw new Exception($"Unexpected value type = {t.Name}");
            }
            else
            {
                throw new Exception($"Unexpected type = {t.Name}");
            }
        }
Esempio n. 2
0
        void ValidateArgumentType(GraphQLParser.ValueContext value, __Type input)
        {
            var checkType = input;

            // NON_NULL is indicator that type is necessary ofType represents underlying
            if (input.kind == __TypeKind.NON_NULL)
            {
                checkType = input.ofType;
            }

            if (value is GraphQLParser.StringValueContext)
            {
                if (checkType.kind != __TypeKind.SCALAR && (TypeCheck.IsString(checkType.dotNetType) == false && TypeCheck.IsEnum(checkType.dotNetType) == false))
                {
                    Error($"String value in argument does not match input type - {checkType.name}", value);
                }
            }
            else if (value is GraphQLParser.BooleanValueContext)
            {
                if (checkType.kind != __TypeKind.SCALAR && checkType.dotNetType != typeof(bool))
                {
                    Error($"Boolean value in argument does not match checkType - {checkType.name}", value);
                }
            }
            else if (value is GraphQLParser.NumberValueContext)
            {
                if (checkType.kind != __TypeKind.SCALAR && TypeCheck.IsNumeric(checkType.dotNetType) == false)
                {
                    Error($"Numeric value in argument does not match checkType - {checkType.name}", value);
                }
            }
            else if (value is GraphQLParser.ObjectValueContext)
            {
                if (checkType.kind != __TypeKind.INPUT_OBJECT)
                {
                    Error($"Object value in argument does not match checkType - {checkType.name}", value);
                }
            }
            else if (value is GraphQLParser.EnumValueContext)
            {
                if (checkType.kind != __TypeKind.ENUM)
                {
                    Error($"Enum value in argument does not match checkType - {checkType.name}", value);
                }
            }
            else if (value is GraphQLParser.ArrayValueContext)
            {
                if (checkType.kind != __TypeKind.LIST)
                {
                    Error($"Enum value in argument does not match checkType - {checkType.name}", value);
                }

                var lst = value as GraphQLParser.ArrayValueContext;

                foreach (var v in lst.array().value())
                {
                    ValidateArgumentType(v, checkType.ofType);
                }
            }
            else
            {
                Error($"Unexpected value type - {value.GetType()}", value);
            }
        }