diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 039cdd4..d060ebe 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -1,6 +1,6 @@ name: .NET Core -on: [push] +on: [pull_request] jobs: build: diff --git a/src/GraphQL.Conventions/Adapters/Engine/GraphQLEngine.cs b/src/GraphQL.Conventions/Adapters/Engine/GraphQLEngine.cs index 02e2307..38cd9f5 100644 --- a/src/GraphQL.Conventions/Adapters/Engine/GraphQLEngine.cs +++ b/src/GraphQL.Conventions/Adapters/Engine/GraphQLEngine.cs @@ -18,6 +18,7 @@ using GraphQL.Utilities; using GraphQL.Validation; using GraphQL.Validation.Complexity; +using GraphQL.Validation.Rules.Custom; using GraphQLParser.AST; // ReSharper disable once CheckNamespace @@ -63,9 +64,17 @@ private class NoopValidationRule : IValidationRule private class NoopNodeVisitor : INodeVisitor { - public void Enter(ASTNode node, ValidationContext context) { /* Noop */ } + public ValueTask EnterAsync(ASTNode node, ValidationContext context) + { + /* Noop */ + return default; + } - public void Leave(ASTNode node, ValidationContext context) { /* Noop */ } + public ValueTask LeaveAsync(ASTNode node, ValidationContext context) + { + /* Noop */ + return default; + } } private class WrappedDependencyInjector : IDependencyInjector @@ -293,7 +302,16 @@ internal async Task ExecuteAsync( rules = new[] { new NoopValidationRule() }; } - var validationRules = rules?.ToArray() ?? new IValidationRule[0]; + if (rules == null || rules.Count() == 0) + { + rules = DocumentValidator.CoreRules; + } + + if (complexityConfiguration != null) + { + rules = rules.Append(new ComplexityValidationRule(complexityConfiguration)); + } + var configuration = new ExecutionOptions { Schema = _schema, @@ -307,8 +325,7 @@ internal async Task ExecuteAsync( { typeof(IUserContext).FullName ?? nameof(IUserContext), userContext }, { typeof(IDependencyInjector).FullName ?? nameof(IDependencyInjector), dependencyInjector }, }, - ValidationRules = validationRules.Any() ? validationRules : null, - ComplexityConfiguration = complexityConfiguration, + ValidationRules = rules, CancellationToken = cancellationToken, ThrowOnUnhandledException = _throwUnhandledExceptions, }; diff --git a/src/GraphQL.Conventions/GraphQL.Conventions.csproj b/src/GraphQL.Conventions/GraphQL.Conventions.csproj index 3f16998..eb26bd1 100644 --- a/src/GraphQL.Conventions/GraphQL.Conventions.csproj +++ b/src/GraphQL.Conventions/GraphQL.Conventions.csproj @@ -29,9 +29,9 @@ - - - + + + diff --git a/test/GraphQL.Conventions.Tests/Attributes/MetaData/FieldTypeMetaDataAttributeTests.cs b/test/GraphQL.Conventions.Tests/Attributes/MetaData/FieldTypeMetaDataAttributeTests.cs index 1fe3b9e..27fd322 100644 --- a/test/GraphQL.Conventions.Tests/Attributes/MetaData/FieldTypeMetaDataAttributeTests.cs +++ b/test/GraphQL.Conventions.Tests/Attributes/MetaData/FieldTypeMetaDataAttributeTests.cs @@ -153,11 +153,11 @@ public TestValidationNodeVisitor(TestUserContext user) _user = user; } - public void Enter(ASTNode node, ValidationContext context) + public ValueTask EnterAsync(ASTNode node, ValidationContext context) { var fieldDef = context.TypeInfo.GetFieldDef(); - if (fieldDef == null) return; - if (fieldDef.Metadata != null && fieldDef.HasMetadata(nameof(TestCustomAttribute))) + if (fieldDef?.Metadata != null && + fieldDef.HasMetadata(nameof(TestCustomAttribute))) { var permissionMetaData = fieldDef.Metadata.First(x => x.Key == nameof(TestCustomAttribute)); var requiredValidation = permissionMetaData.Value as string; @@ -169,8 +169,14 @@ public void Enter(ASTNode node, ValidationContext context) $"Required validation '{requiredValidation}' is not present. Query will not be executed.", node)); } + + return default; } - public void Leave(ASTNode node, ValidationContext context) { /* Noop */ } + public ValueTask LeaveAsync(ASTNode node, ValidationContext context) + { + /* Noop */ + return default; + } } } diff --git a/test/GraphQL.Conventions.Tests/GraphQL.Conventions.Tests.csproj b/test/GraphQL.Conventions.Tests/GraphQL.Conventions.Tests.csproj index 9c4c254..bcd4434 100755 --- a/test/GraphQL.Conventions.Tests/GraphQL.Conventions.Tests.csproj +++ b/test/GraphQL.Conventions.Tests/GraphQL.Conventions.Tests.csproj @@ -12,8 +12,8 @@ - - + + diff --git a/test/GraphQL.Conventions.Tests/Web/RequestHandlerTests.cs b/test/GraphQL.Conventions.Tests/Web/RequestHandlerTests.cs index adf4131..3ebb5b2 100644 --- a/test/GraphQL.Conventions.Tests/Web/RequestHandlerTests.cs +++ b/test/GraphQL.Conventions.Tests/Web/RequestHandlerTests.cs @@ -62,7 +62,7 @@ public async Task Cannot_Run_Too_Complex_Query_Using_ComplexityConfiguration() .ProcessRequestAsync(request, null); response.Errors.Count.ShouldEqual(1); - response.Errors[0].Message.ShouldEqual("Error executing document. Query is too nested to execute. Depth is 2 levels, maximum allowed on this endpoint is 1."); + response.Errors[0].Message.ShouldEqual("Query is too nested to execute. Depth is 2 levels, maximum allowed on this endpoint is 1."); } [Test]