Skip to content

Commit

Permalink
Merge pull request #205 from ipdae/improve/issue-204
Browse files Browse the repository at this point in the history
Add current block index in world boss ranking query
  • Loading branch information
ipdae authored Aug 23, 2022
2 parents debb543 + 7c8921e commit 2bc012b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
19 changes: 12 additions & 7 deletions NineChronicles.DataProvider.Tests/WorldBossRankingQueryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ public class WorldBossRankingQueryTest : TestBase, IDisposable
[Fact]
public async Task WorldBossRanking()
{
const string query = @"query {
worldBossRanking(raidId: 1) {
ranking
avatarName
}
}";
const string query = $@"query {{
worldBossRanking(raidId: 1) {{
blockIndex
rankingInfo {{
ranking
avatarName
}}
}}
}}";
for (int idx = 0; idx < 2; idx++)
{
for (int i = 0; i < 200; i++)
Expand All @@ -43,7 +46,9 @@ public async Task WorldBossRanking()

await Context.SaveChangesAsync();
var result = await ExecuteAsync(query);
var models = (object[])((Dictionary<string, object>) ((ExecutionNode) result.Data).ToValue())["worldBossRanking"];
var data = (Dictionary<string, object>)((Dictionary<string, object>) ((ExecutionNode) result.Data).ToValue())["worldBossRanking"];
Assert.Equal(0L, data["blockIndex"]);
var models = (object[]) data["rankingInfo"];
Assert.Equal(100, models.Length);
}

Expand Down
21 changes: 21 additions & 0 deletions NineChronicles.DataProvider/GraphTypes/WorldBossRankingInfoType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace NineChronicles.DataProvider.GraphTypes
{
using System.Collections.Generic;
using GraphQL.Types;
using NineChronicles.DataProvider.Store.Models;

public class WorldBossRankingInfoType : ObjectGraphType<(long blockIndex, List<WorldBossRankingModel> worldBossRankingModels)>
{
public WorldBossRankingInfoType()
{
Field<NonNullGraphType<LongGraphType>>(
"blockIndex",
resolve: context => context.Source.blockIndex
);
Field<NonNullGraphType<ListGraphType<WorldBossRankingType>>>(
"rankingInfo",
resolve: context => context.Source.worldBossRankingModels
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public NineChroniclesSummaryQuery(MySqlStore store, StandaloneContext standalone
name: "dauQuery",
resolve: context => new DauQuery(store)
);
Field<ListGraphType<WorldBossRankingType>>(
Field<WorldBossRankingInfoType>(
name: "worldBossRanking",
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<IntGraphType>>
Expand Down Expand Up @@ -248,7 +248,7 @@ public NineChroniclesSummaryQuery(MySqlStore store, StandaloneContext standalone
}
}

return result;
return (StandaloneContext.BlockChain?.Tip?.Index ?? 0, result);
});
Field<IntGraphType>(
name: "worldBossTotalUsers",
Expand Down

0 comments on commit 2bc012b

Please sign in to comment.