feat: Clan Resolver first step

This commit is contained in:
Mikhail Shabanov committed 2021-03-19 19:49:58 +01:00
1 parent 7f713e5357
commit 8fb1b170df
11 files changed
+203 -2

No files matched your search

@@ -0,0 +1,42 @@
using System;
using System.Linq;
using HotChocolate.Language;
using WotBlitzStatisticsPro.Common.Model;
namespace WotBlitzStatisticsPro.GraphQl.Helpers
{
public static class ParametersParser
{
private const RealmType DefaultRealm = RealmType.Ru;
private const RequestLanguage DefaultRequestLanguage = RequestLanguage.En;
public static RealmAndLanguage ParseOperation(this OperationDefinitionNode operationDefinition)
{
var realm = DefaultRealm;
var language = DefaultRequestLanguage;
var selections = operationDefinition?.SelectionSet.Selections.ToArray();
if (selections != null && selections.Length == 1)
{
var node = selections[0] as FieldNode;
if (node?.Arguments != null)
{
foreach (var argument in node.Arguments.Where(a => a != null))
{
switch (argument.Name.Value)
{
case "realmType" when argument?.Value?.Value != null:
realm = (RealmType)Enum.Parse(typeof(RealmType), argument.Value.Value.ToString() ?? "Ru", true);
break;
case "requestLanguage" when argument?.Value?.Value != null:
language = (RequestLanguage)Enum.Parse(typeof(RequestLanguage), argument.Value.Value.ToString() ?? "En", true);
break;
}
}
}
}
return new (realm, language);
}
}
}
@@ -1,10 +1,12 @@
using System;
using System.Threading.Tasks;
using HotChocolate.Types;
using WotBlitzStatisticsPro.Common.Model;
using WotBlitzStatisticsPro.Logic;
namespace WotBlitzStatisticsPro.GraphQl.Query
{
[ExtendObjectType(Name = "Query")]
public class WotBlitzStatisticsQuery
{
// 571050560 - mboga Eu
@@ -0,0 +1,18 @@
using HotChocolate.Types;
using WotBlitzStatisticsPro.Common.Model;
using WotBlitzStatisticsPro.GraphQl.Helpers;
using WotBlitzStatisticsPro.Logic;
namespace WotBlitzStatisticsPro.GraphQl.Resolvers
{
[ExtendObjectType(Name = "Query")]
public class AccountInfoResolver: ObjectType<AccountInfoResponse>
{
protected override void Configure(IObjectTypeDescriptor<AccountInfoResponse> descriptor)
{
descriptor.Field(t => t.ClanInfo)
.Resolver(ctx => ctx.Service<IWargamingClans>().GelClanInfoByAccount(ctx.Parent<AccountInfoResponse>().AccountId, ctx.Operation.ParseOperation()));
}
}
}
+4 -1
View File
@@ -9,6 +9,7 @@ using WotBlitzStatisticsPro.Common.Model;
using WotBlitzStatisticsPro.GraphQl.Mutation;
using WotBlitzStatisticsPro.GraphQl.ObjectTypes;
using WotBlitzStatisticsPro.GraphQl.Query;
using WotBlitzStatisticsPro.GraphQl.Resolvers;
using WotBlitzStatisticsPro.Logic;
namespace WotBlitzStatisticsPro.GraphQl
@@ -41,7 +42,9 @@ namespace WotBlitzStatisticsPro.GraphQl
// Add GraphQL Services
services.AddGraphQLServer()
.AddQueryType<WotBlitzStatisticsQuery>()
.AddQueryType(d => d.Name("Query"))
.AddType<WotBlitzStatisticsQuery>()
.AddType<AccountInfoResolver>()
.AddMutationType<WotBlitzStatisticsMutation>()
.AddType<AccountsSearchItemObjectType>()
.AddType<AccountsSearchObjectType>()
@@ -23,7 +23,6 @@
<ItemGroup>
<Folder Include="DataLoaders\" />
<Folder Include="Resolvers\" />
</ItemGroup>