Some Data loader stuff

This commit is contained in:
Mikhail Shabanov committed 2020-03-19 22:00:47 +01:00
1 parent d643c323b3
commit 83628d21bd
5 files changed
+61 -14

No files matched your search

@@ -2,6 +2,7 @@
using GreenDonut;
using HotChocolate.Resolvers;
using HotChocolate.Types;
using WotBlitzStatistics.GraphQl.Resolvers;
using WotBlitzStatisticsPro.WgApiClient;
using WotBlitzStatisticsPro.WgApiClient.Model;
@@ -11,17 +12,7 @@ namespace WotBlitzStatistics.GraphQl.ObjectTypes
{
protected override void Configure(IObjectTypeDescriptor<ClanAccountInfo> descriptor)
{
// ToDo: Cache clan info!
// https://hotchocolate.io/docs/dataloaders
descriptor.Field("clanInfo")
.Resolver(c =>
{
var warGamingClient = c.Service<IWargamingApiClient>();
var clanDataLoader = c.CacheDataLoader<long, ClanInfo>(
"clanInfoById",
clanId => warGamingClient.GetClanInfo(clanId));
return clanDataLoader.LoadAsync(c.Parent<ClanAccountInfo>().ClanId.Value);
});
descriptor.Include<ClanInfoResolver>();
}
}
}