dotnet-cqrs/PoweredSoft.CQRS.GraphQL.HotChocolate.DynamicQuery/DynamicQueryRunner.cs

28 lines
1016 B
C#
Raw Normal View History

2021-02-04 13:51:31 -05:00
using PoweredSoft.CQRS.DynamicQuery;
using PoweredSoft.CQRS.DynamicQuery.Abstractions;
using PoweredSoft.CQRS.GraphQL.DynamicQuery;
using System.Threading;
using System.Threading.Tasks;
namespace PoweredSoft.CQRS.GraphQL.HotChocolate.DynamicQuery
{
public class DynamicQueryRunner<TSource, TDestination>
where TSource : class
where TDestination : class
{
private readonly DynamicQueryHandler<TSource, TDestination> handler;
public DynamicQueryRunner(DynamicQueryHandler<TSource, TDestination> handler)
{
this.handler = handler;
}
public async Task<GraphQLDynamicQueryExecutionResult<TDestination>> RunAsync(IDynamicQuery<TSource, TDestination> query, CancellationToken cancellationToken = default)
{
var result = await handler.HandleAsync(query);
var outcome = new GraphQLDynamicQueryExecutionResult<TDestination>();
outcome.FromResult(result);
return outcome;
}
}
}