public void MaxComplexityReachedWithUnions(
            int maxAllowedComplexity,
            bool hasErrors)
        {
            // arrange
            DocumentNode query = Utf8GraphQLParser.Parse(@"
                {
                    bazOrBar {
                        ... on Foo {
                            ... on Foo {
                                field
                                ... on Bar {
                                    baz {
                                        foo {
                                            field
                                        }
                                    }
                                }
                            }
                        }
                        ... on Bar {
                            baz {
                                foo {
                                    field
                                }
                            }
                        }
                    }
                }
            ");

            ISchema schema = CreateSchema();

            var rule = new MaxComplexityRule(new QueryExecutionOptions
            {
                MaxOperationComplexity = maxAllowedComplexity
            }, null);

            // act
            QueryValidationResult result = rule.Validate(schema, query);

            // assert
            Assert.Equal(hasErrors, result.HasErrors);
            result.MatchSnapshot("MaxComplexityReachedWithUnions" + maxAllowedComplexity);
        }
Exemplo n.º 2
0
        public void MaxComplexityReachedWithCustomCalculateDelegate(
            int maxAllowedComplexity,
            bool hasErrors)
        {
            // arrange
            DocumentNode query = Parser.Default.Parse(@"
                {
                    foo {
                        ... on Foo {
                            ... on Foo {
                                field
                                ... on Bar {
                                    baz {
                                        foo {
                                            field
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            ");

            ISchema schema = CreateSchema();

            var rule = new MaxComplexityRule(new QueryExecutionOptions
            {
                MaxOperationComplexity = maxAllowedComplexity
            }, c => c.Cost.Complexity * 2);

            // act
            QueryValidationResult result = rule.Validate(schema, query);

            // assert
            Assert.Equal(hasErrors, result.HasErrors);
            result.MatchSnapshot(
                "MaxComplexityReachedWithCustomCalculateDelegate_" +
                maxAllowedComplexity);
        }
Exemplo n.º 3
0
        public void MaxComplexityReached(
            int maxAllowedComplexity,
            bool hasErrors)
        {
            // arrange
            DocumentNode query = Parser.Default.Parse(@"
                {
                    foo {
                        ... on Foo {
                            ... on Foo {
                                field
                                ... on Bar {
                                    baz {
                                        foo {
                                            field
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            ");

            ISchema schema = CreateSchema();

            var rule = new MaxComplexityRule(new QueryExecutionOptions
            {
                MaxOperationComplexity = maxAllowedComplexity
            }, null);

            // act
            QueryValidationResult result = rule.Validate(schema, query);

            // assert
            Assert.Equal(hasErrors, result.HasErrors);
            result.MatchSnapshot(
                SnapshotNameExtension.Create(maxAllowedComplexity));
        }