initial commit
This commit is contained in:
28
Presentation/GraphQL/DataLoaders/KillsDataLoader.cs
Normal file
28
Presentation/GraphQL/DataLoaders/KillsDataLoader.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Application.Interfaces.Services;
|
||||
using Domain.Entities;
|
||||
using GreenDonut.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace GraphQLTEST.GraphQL.DataLoaders;
|
||||
|
||||
public class KillsByUserDataLoader : GroupedDataLoader<int, Kill>{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
public KillsByUserDataLoader(
|
||||
IServiceProvider serviceProvider,
|
||||
IBatchScheduler batchScheduler,
|
||||
DataLoaderOptions options): base(batchScheduler, options){
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
protected override async Task<ILookup<int, Kill>> LoadGroupedBatchAsync(IReadOnlyList<int> keys, CancellationToken cancellationToken)
|
||||
{
|
||||
await using var scope = _serviceProvider.CreateAsyncScope();
|
||||
var service = scope.ServiceProvider.GetRequiredService<IKillService>();
|
||||
|
||||
return await service.GetKillsByUserId(keys)
|
||||
.ToAsyncEnumerable()
|
||||
.ToLookupAsync(k => k.UserId, cancellationToken: cancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user