Example #1
0
        public void DefaultScalarValueResolvers_InvalidInputValue(string expressionText, string inputText)
        {
            var generator = new InputResolverMethodGenerator(this.CreateSchema());

            var text        = inputText?.AsMemory() ?? ReadOnlyMemory <char> .Empty;
            var source      = new SourceText(text);
            var tokenStream = Lexer.Tokenize(source);

            tokenStream.Prime();
            InputValueNode node = null;

            if (!tokenStream.EndOfStream)
            {
                var maker = ValueMakerFactory.CreateMaker(tokenStream.ActiveToken);
                if (maker != null)
                {
                    node = maker.MakeNode(tokenStream) as InputValueNode;
                }
            }

            var inputValue     = QueryInputValueFactory.CreateInputValue(node);
            var typeExpression = GraphTypeExpression.FromDeclaration(expressionText);
            var resolver       = generator.CreateResolver(typeExpression);

            Assert.Throws <UnresolvedValueException>(() =>
            {
                resolver.Resolve(inputValue);
            });
        }
Example #2
0
        /// <summary>
        /// Converts a node read on a query document into a value representation that can be resolved
        /// to a usable .NET type in a query plan.
        /// </summary>
        /// <param name="valueNode">The value node.</param>
        /// <returns>IQueryInputValue.</returns>
        public static QueryInputValue CreateInputValue(InputValueNode valueNode)
        {
            if (valueNode == null)
            {
                return(null);
            }

            switch (valueNode)
            {
            case ListValueNode lvn:
                return(new QueryListInputValue(lvn));

            case NullValueNode nvn:
                return(new QueryNullInputValue(nvn));

            case ComplexValueNode cvn:
                return(new QueryComplexInputValue(cvn));

            case ScalarValueNode svn:
                return(new QueryScalarInputValue(svn));

            case EnumValueNode evn:
                return(new QueryEnumInputValue(evn));

            case VariableValueNode vvn:
                return(new QueryVariableReferenceInputValue(vvn));

            default:
                throw new ArgumentOutOfRangeException(
                          nameof(valueNode),
                          $"Unknown type '{valueNode?.GetType().FriendlyName()}'. " +
                          $"Factory is unable to generate a '{nameof(QueryInputValue)}' to fulfill the request.");
            }
        }