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); }
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); }
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)); }