mirror of
https://github.com/DrMboga/WotBlitzStatisticsBlazor.git
synced 2026-10-21 10:27:18 +02:00
Clan info with caching
This commit is contained in:
1 parent
089c6329ee
commit
d643c323b3
3 files changed
+23
-10
No files matched your search
@@ -1,4 +1,7 @@
|
||||
using HotChocolate.Types;
|
||||
using System.Threading;
|
||||
using GreenDonut;
|
||||
using HotChocolate.Resolvers;
|
||||
using HotChocolate.Types;
|
||||
using WotBlitzStatisticsPro.WgApiClient;
|
||||
using WotBlitzStatisticsPro.WgApiClient.Model;
|
||||
|
||||
@@ -10,10 +13,15 @@ namespace WotBlitzStatistics.GraphQl.ObjectTypes
|
||||
{
|
||||
// ToDo: Cache clan info!
|
||||
// https://hotchocolate.io/docs/dataloaders
|
||||
descriptor.Field("clanInfo")
|
||||
.Resolver(c => c.Service<IWargamingApiClient>()
|
||||
.GetClanInfo(c.Parent<ClanAccountInfo>().ClanId.Value));
|
||||
|
||||
}
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,9 @@ namespace WotBlitzStatistics.GraphQl
|
||||
services.AddSingleton<IWargamingApiSettings>(wgApiConfig);
|
||||
services.AddHttpClient<IWargamingApiClient, WargamingApiClient>();
|
||||
|
||||
// this enables you to use DataLoader in your resolvers.
|
||||
services.AddDataLoaderRegistry();
|
||||
|
||||
// Add GraphQL Services
|
||||
services.AddGraphQL(sp => SchemaBuilder.New()
|
||||
.AddServices(sp)
|
||||
|
||||
@@ -5,10 +5,12 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="HotChocolate.AspNetCore" Version="10.3.5" />
|
||||
<PackageReference Include="HotChocolate.AspNetCore.Authorization" Version="10.3.5" />
|
||||
<PackageReference Include="HotChocolate.AspNetCore.Playground" Version="10.3.5" />
|
||||
<PackageReference Include="HotChocolate.AspNetCore.Voyager" Version="10.3.5" />
|
||||
<PackageReference Include="HotChocolate.AspNetCore" Version="10.3.6" />
|
||||
<PackageReference Include="HotChocolate.AspNetCore.Abstractions" Version="10.3.6" />
|
||||
<PackageReference Include="HotChocolate.AspNetCore.Authorization" Version="10.3.6" />
|
||||
<PackageReference Include="HotChocolate.AspNetCore.Playground" Version="10.3.6" />
|
||||
<PackageReference Include="HotChocolate.AspNetCore.Voyager" Version="10.3.6" />
|
||||
<PackageReference Include="HotChocolate.Types.Filters" Version="10.3.6" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
Reference in new issue
Block a user