Skip to content

Commit

Permalink
GraphQL 7 (#233)
Browse files Browse the repository at this point in the history
Co-authored-by: Shane32 <[email protected]>
  • Loading branch information
SimonCropp and Shane32 authored Nov 11, 2022
1 parent be60ed2 commit 81106ed
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnetcore.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: .NET Core

on: [push]
on: [pull_request]

jobs:
build:
Expand Down
27 changes: 22 additions & 5 deletions src/GraphQL.Conventions/Adapters/Engine/GraphQLEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -293,7 +302,16 @@ internal async Task<ExecutionResult> 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,
Expand All @@ -307,8 +325,7 @@ internal async Task<ExecutionResult> 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,
};
Expand Down
6 changes: 3 additions & 3 deletions src/GraphQL.Conventions/GraphQL.Conventions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GraphQL" Version="5.3.0" />
<PackageReference Include="GraphQL.DataLoader" Version="5.3.0" />
<PackageReference Include="GraphQL.NewtonsoftJson" Version="5.3.0" />
<PackageReference Include="GraphQL" Version="7.0.0" />
<PackageReference Include="GraphQL.DataLoader" Version="7.0.0" />
<PackageReference Include="GraphQL.NewtonsoftJson" Version="7.0.0" />
<PackageReference Include="GraphQL.SystemReactive" Version="4.8.0" />
<PackageReference Include="System.Reflection" Version="4.3.0" />
<PackageReference Include="System.Runtime" Version="4.3.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GraphQL" Version="5.3.0" />
<PackageReference Include="GraphQL.DataLoader" Version="5.3.0" />
<PackageReference Include="GraphQL" Version="7.0.0" />
<PackageReference Include="GraphQL.DataLoader" Version="7.0.0" />
<PackageReference Include="GraphQL.SystemReactive" Version="4.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="Microsoft.TestPlatform.TestHost" Version="17.2.0" />
Expand Down
2 changes: 1 addition & 1 deletion test/GraphQL.Conventions.Tests/Web/RequestHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 81106ed

Please sign in to comment.