Beispiel #1
0
        public object GetLiteralValue(Language.AST.GraphQLValue value)
        {
            switch (value.Kind)
            {
            case Language.AST.ASTNodeKind.BooleanValue: return(((Language.AST.GraphQLValue <bool>)value).Value);

            case Language.AST.ASTNodeKind.IntValue: return(((Language.AST.GraphQLValue <int>)value).Value);

            case Language.AST.ASTNodeKind.FloatValue: return(((Language.AST.GraphQLValue <float>)value).Value);

            case Language.AST.ASTNodeKind.StringValue: return(((Language.AST.GraphQLValue <string>)value).Value);

            case Language.AST.ASTNodeKind.EnumValue: return(((Language.AST.GraphQLValue <string>)value).Value);
            }

            return(null);
        }
Beispiel #2
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[] { });
        }