Skip to content

Commit 98020b9

Browse files
authored
Add DefaultVisitorContext and NullVisitorContext (#336)
* Add DefaultVisitorContext and NullVisitorContext * Update api approvals
1 parent e5bc3f9 commit 98020b9

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/GraphQLParser.ApiTests/GraphQLParser.approved.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,10 @@ namespace GraphQLParser.Visitors
933933
public System.Threading.CancellationToken CancellationToken { get; init; }
934934
public System.Collections.Generic.Stack<GraphQLParser.AST.ASTNode> Parents { get; init; }
935935
}
936+
public struct DefaultVisitorContext : GraphQLParser.Visitors.IASTVisitorContext
937+
{
938+
public System.Threading.CancellationToken CancellationToken { get; set; }
939+
}
936940
public interface IASTVisitorContext
937941
{
938942
System.Threading.CancellationToken CancellationToken { get; }
@@ -960,6 +964,10 @@ namespace GraphQLParser.Visitors
960964
public MaxDepthVisitor() { }
961965
public override System.Threading.Tasks.ValueTask VisitAsync(GraphQLParser.AST.ASTNode? node, TContext context) { }
962966
}
967+
public struct NullVisitorContext : GraphQLParser.Visitors.IASTVisitorContext
968+
{
969+
public System.Threading.CancellationToken CancellationToken { get; }
970+
}
963971
public static class PrintContextExtensions
964972
{
965973
public static System.Threading.Tasks.ValueTask WriteAsync<TContext>(this TContext context, GraphQLParser.ROM value)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace GraphQLParser.Visitors;
2+
3+
/// <summary>
4+
/// An implementation of <see cref="IASTVisitorContext"/> that only contains a <see cref="CancellationToken"/>.
5+
/// Ideal for use in cases where there is no context variables.
6+
/// </summary>
7+
public struct DefaultVisitorContext : IASTVisitorContext
8+
{
9+
/// <inheritdoc/>
10+
public CancellationToken CancellationToken { get; set; }
11+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace GraphQLParser.Visitors;
2+
3+
/// <summary>
4+
/// An implementation of <see cref="IASTVisitorContext"/> that does nothing.
5+
/// Ideal for use in cases where the visitor runs synchronously, there is no context
6+
/// variables, and cancellation is not required.
7+
/// </summary>
8+
public struct NullVisitorContext : IASTVisitorContext
9+
{
10+
/// <inheritdoc/>
11+
public readonly CancellationToken CancellationToken => default;
12+
}

0 commit comments

Comments
 (0)