Пример #1
0
        public void ListOfListValueResolver()
        {
            var innerList1 = new QueryListInputValue(new FakeSyntaxNode());

            innerList1.ListItems.Add(new QueryScalarInputValue(new FakeSyntaxNode(), "15", ScalarValueType.Number));
            innerList1.ListItems.Add(new QueryScalarInputValue(new FakeSyntaxNode(), "12", ScalarValueType.Number));

            var innerList2 = new QueryListInputValue(new FakeSyntaxNode());

            innerList2.ListItems.Add(new QueryScalarInputValue(new FakeSyntaxNode(), "30", ScalarValueType.Number));
            innerList2.ListItems.Add(new QueryScalarInputValue(new FakeSyntaxNode(), "40", ScalarValueType.Number));

            var outerList = new QueryListInputValue(new FakeSyntaxNode());

            outerList.ListItems.Add(innerList1);
            outerList.ListItems.Add(innerList2);

            var typeExpression = GraphTypeExpression.FromDeclaration("[[Int]]");
            var generator      = new InputResolverMethodGenerator(this.CreateSchema());

            var resolver = generator.CreateResolver(typeExpression);
            var result   = resolver.Resolve(outerList) as IEnumerable;

            CollectionAssert.AreEqual(new List <IEnumerable <int> > {
                new List <int> {
                    15, 12
                }, new List <int> {
                    30, 40
                }
            }, result);
        }
Пример #2
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);
            });
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="QueryVariable" /> class.
 /// </summary>
 /// <param name="node">The node.</param>
 public QueryVariable(VariableNode node)
 {
     this.Node            = Validation.ThrowIfNullOrReturn(node, nameof(node));
     this.Name            = node.Name.ToString();
     this.TypeExpression  = GraphTypeExpression.FromDeclaration(node.TypeExpression.Span);
     this.UsedByArguments = new List <QueryInputArgument>();
 }
Пример #4
0
        public void BasicListValueResolver()
        {
            var sourceList = new QueryListInputValue(new FakeSyntaxNode());

            sourceList.ListItems.Add(new QueryScalarInputValue(new FakeSyntaxNode(), "15", ScalarValueType.Number));
            sourceList.ListItems.Add(new QueryScalarInputValue(new FakeSyntaxNode(), "12", ScalarValueType.Number));

            var typeExpression = GraphTypeExpression.FromDeclaration("[Int]");
            var generator      = new InputResolverMethodGenerator(this.CreateSchema());

            var resolver = generator.CreateResolver(typeExpression);
            var result   = resolver.Resolve(sourceList) as IEnumerable;

            CollectionAssert.AreEqual(new List <int> {
                15, 12
            }, result);
        }
        public void ParseDeclaration(
            string declarationText,
            bool isValid,
            GTW[] expectedModifiers,
            string expectedTypeName)
        {
            var declaration = GraphTypeExpression.FromDeclaration(declarationText.AsSpan());

            Assert.AreEqual(isValid, declaration.IsValid);

            if (isValid)
            {
                Assert.AreEqual(expectedTypeName, declaration.TypeName);
                Assert.AreEqual(expectedModifiers.Length, declaration.Wrappers.Length);
                for (var i = 0; i < expectedModifiers.Length; i++)
                {
                    Assert.AreEqual(expectedModifiers[i], declaration.Wrappers[i]);
                }

                Assert.AreEqual(declarationText, declaration.ToString());
            }
        }