Skip to content

Commit

Permalink
Remove ThrowIfCancellationRequested from VisitAsync (#337)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane32 authored Jul 22, 2023
1 parent 98020b9 commit fab4691
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/GraphQLParser.Tests/Visitors/ASTVisitorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ public void ASTVisitor_Should_Throw_On_Unknown_Node()
}

[Fact]
public void ASTVisitor_Should_Respect_CancellationToken()
public void ASTVisitor_Should_Pass_CancellationToken()
{
var document = "scalar JSON".Parse();
var visitor = new MyVisitor();
using var cts = new CancellationTokenSource(500);
var context = new Context { CancellationToken = cts.Token };
context.CancellationToken.ThrowIfCancellationRequested();

Should.Throw<OperationCanceledException>(() => visitor.VisitAsync(document, context).GetAwaiter().GetResult());
}
Expand All @@ -48,6 +49,7 @@ private class MyVisitor : ASTVisitor<Context>
protected override async ValueTask VisitScalarTypeDefinitionAsync(GraphQLScalarTypeDefinition scalarTypeDefinition, Context context)
{
await Task.Delay(700);
context.CancellationToken.ThrowIfCancellationRequested();
await base.VisitScalarTypeDefinitionAsync(scalarTypeDefinition, context);
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/GraphQLParser/Visitors/ASTVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,6 @@ protected virtual async ValueTask VisitInputObjectTypeExtensionAsync(GraphQLInpu
/// <param name="context">Context passed into all INodeVisitor.VisitXXX methods.</param>
public virtual ValueTask VisitAsync(ASTNode? node, TContext context)
{
context.CancellationToken.ThrowIfCancellationRequested();

return node == null
? default
: node switch
Expand Down

0 comments on commit fab4691

Please sign in to comment.