public void CreateExpressionForMutation()
        {
            DocumentNode document = Utf8GraphQLParser.Parse("mutation { updateClient(strProp: \"test\") { strProp intProp dateProp child { strProp } sameClass { strProp } children { strProp } } }");

            var queryBuilder = QueryRequestBuilder.New().SetQuery(document);

            var queryRequest = queryBuilder.Create();

            var parser = new GraphToExpressionParser <TestClass>(queryRequest.Query as QueryDocument);

            var expression = parser.CreateExpression();

            expression.ToString().Should().Be("a => new {StrProp = a.StrProp, IntProp = a.IntProp, DateProp = a.DateProp, Child = new {StrProp = a.Child.StrProp}, SameClass = new {StrProp = a.SameClass.StrProp}, Children = a.Children.Select(b => new {StrProp = b.StrProp})}");
        }
        public void CreateBasicExpression()
        {
            DocumentNode document = Utf8GraphQLParser.Parse("{ testQuery { strProp intProp dateProp } }");

            var queryBuilder = QueryRequestBuilder.New().SetQuery(document);

            var queryRequest = queryBuilder.Create();

            var parser = new GraphToExpressionParser <TestClass>(queryRequest.Query as QueryDocument);

            var expression = parser.CreateExpression <TestClass>();

            expression.ToString().Should().Be("a => new {StrProp = a.StrProp, IntProp = a.IntProp, DateProp = a.DateProp}");
        }
        public void CreateExpressionForQuery()
        {
            DocumentNode document = Utf8GraphQLParser.Parse("{ testQuery { strProp intProp dateProp child { otherStrProp } sameClass { strProp } children { listStrProp } } }");

            var queryBuilder = QueryRequestBuilder.New().SetQuery(document);

            var queryRequest = queryBuilder.Create();

            var parser = new GraphToExpressionParser <TestClass>(queryRequest.Query as QueryDocument);

            var expression = parser.CreateExpression <TestClass>();

            expression.ToString().Should().Be("a => new {StrProp = a.StrProp, IntProp = a.IntProp, DateProp = a.DateProp, Child = new {OtherStrProp = a.Child.OtherStrProp}, SameClass = new {StrProp = a.SameClass.StrProp}, Children = a.Children.Select(b => new {ListStrProp = b.ListStrProp})}");
        }
        public void ClassConvertion()
        {
            DocumentNode document = Utf8GraphQLParser.Parse("{ testQuery { strProp innerProp intInnerProp } }");

            var queryBuilder = QueryRequestBuilder.New().SetQuery(document);

            var queryRequest = queryBuilder.Create();

            var parser = new GraphToExpressionParser <AttrData>(queryRequest.Query as QueryDocument);

            var expression = parser.CreateExpression <AttrSchema>();

            expression.ToString().Should().Be("a => new {StrProp = a.StrProp, Child = new {InnerProp = a.Child.InnerProp, IntInnerProp = a.Child.IntInnerProp}}");
        }
示例#5
0
        public void CreateExpressionFromComplexObjectWithListInside()
        {
            DocumentNode document = Utf8GraphQLParser.Parse("{ testQuery { child { otherStrProp secondChild { id } } } }");

            var queryBuilder = QueryRequestBuilder.New().SetQuery(document);

            var queryRequest = queryBuilder.Create();

            var parser = new GraphToExpressionParser <TestClass>(queryRequest.Query as QueryDocument);

            var expression = parser.CreateExpression <TestClass>();

            expression.ToString().Should().Be("a => new {Child = new {OtherStrProp = a.Child.OtherStrProp, SecondChild = a.Child.SecondChild.Select(b => new {Id = b.Id})}}");
        }
示例#6
0
        public void DoesNotThrowWithNonExitingPropertyInSchema()
        {
            DocumentNode document = Utf8GraphQLParser.Parse("{ testQuery { strProp noProp } }");

            var queryBuilder = QueryRequestBuilder.New().SetQuery(document);

            var queryRequest = queryBuilder.Create();

            var parser = new GraphToExpressionParser <AttrData>(queryRequest.Query as QueryDocument);

            var expression = parser.CreateExpression <AttrSchema>();

            expression.ToString().Should().Be("a => new {StrProp = a.StrProp}");
        }
示例#7
0
        public void ClassConvertion()
        {
            DocumentNode document = Utf8GraphQLParser.Parse("{ testQuery { strProp innerProp intInnerProp { val } prop } }");

            var queryBuilder = QueryRequestBuilder.New().SetQuery(document);

            var queryRequest = queryBuilder.Create();

            var parser = new GraphToExpressionParser <AttrData>(queryRequest.Query as QueryDocument);

            var expression = parser.CreateExpression <AttrSchema>();

            expression.ToString().Should().Be("a => new {StrProp = a.StrProp, Prop = a.Prop, Child = new {InnerProp = a.Child.InnerProp, IntInnerProp = a.Child.IntInnerProp.Select(b => new {Val = b.Val})}}");

            List <AttrData> test          = AttrData.CreateTestList();
            var             expressionRun = test.Select(expression.Compile());

            Assert.Equal(7, expressionRun.FirstOrDefault().Child.InnerProp);
        }
        public void FilterPaginationNodes()
        {
            DocumentNode document = Utf8GraphQLParser.Parse(@"
            {
                testQuery
                {
                    edges
                    {
                        node
                        {
                            strProp intProp dateProp child { otherStrProp }
                        }
                    }
                    nodes 
                    {
                        strProp intProp dateProp child { otherStrProp }
                    }
                    pageInfo
                    {
                        endCursor
                        hasNextPage
                        hasPreviousPage
                        startCursor
                    }
                    totalCount
                }
            }");

            var queryBuilder = QueryRequestBuilder.New().SetQuery(document);

            var queryRequest = queryBuilder.Create();

            var parser = new GraphToExpressionParser <TestClass>(queryRequest.Query as QueryDocument);

            var expression = parser.CreateExpression <TestClass>(usePagination: true);

            expression.ToString().Should().Be("a => new {StrProp = a.StrProp, IntProp = a.IntProp, DateProp = a.DateProp, Child = new {OtherStrProp = a.Child.OtherStrProp}}");
        }
        public void UnsupportedOperation()
        {
            DocumentNode document = Utf8GraphQLParser.Parse("subscription { onReview(episode: NEWHOPE) { stars comment } }");

            var queryBuilder = QueryRequestBuilder.New().SetQuery(document);

            var queryRequest = queryBuilder.Create();

            var parser = new GraphToExpressionParser <TestClass>(queryRequest.Query as QueryDocument);

            Exception exception = Assert.Throws <UnsupportedOperationException>(() => parser.CreateExpression());

            exception.Should().BeOfType(typeof(UnsupportedOperationException));
            exception.Message.Should().Be("There is no support for the operation Subscription");
        }