graphql-dotnet / parser

A lexer and parser for GraphQL in .NET
MIT License
216 stars 43 forks source link

Suggested feature: default AST visitor context #332

Closed Shane32 closed 1 year ago

Shane32 commented 1 year ago

Currently there is no default implementation of IASTVisitorContext. I suggest providing one with a CancellationToken and one without a CancellationToken (where => default;).

In a similar vein, perhaps we should add an extension method to run a visitor synchronously. Many visitors will not run asynchronously and will not need a cancellation token. .GetAwaiter().GetResult() produces a warning as it will not work correctly if run on a truly asynchronous task, but .ToTask() returns Task.CompletedTask for a completed ValueTask and so perhaps .ToTask().GetAwaiter().GetResult() is an allocation-free and safe method to expose externally.