Skip to content

Commit

Permalink
Merge pull request #2238 from planetarium/feature/gql-aura-summon
Browse files Browse the repository at this point in the history
Introduce auraSummon ActionQuery
  • Loading branch information
U-lis authored Sep 7, 2023
2 parents e174c1c + 242a8dc commit 1b19cc8
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
29 changes: 29 additions & 0 deletions NineChronicles.Headless.Tests/GraphTypes/ActionQueryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1311,5 +1311,34 @@ private static IEnumerable<object[]> GetMemberDataOfUnloadFromMyGarages()
"memo",
};
}

[Fact]
public async Task AuraSummon()
{
var random = new Random();
var avatarAddress = new PrivateKey().ToAddress();
var groupId = random.Next(10001, 10002 + 1);
// FIXME: Change 10 to AuraSummon.SummonLimit
var summonCount = random.Next(1, 10 + 1);

var query = $@"{{
auraSummon(
avatarAddress: ""{avatarAddress}"",
groupId: {groupId},
summonCount: {summonCount}
)
}}";

var queryResult = await ExecuteQueryAsync<ActionQuery>(query, standaloneContext: _standaloneContext);
var data = (Dictionary<string, object>)((ExecutionNode)queryResult.Data!).ToValue()!;
var plainValue = _codec.Decode(ByteUtil.ParseHex((string)data["auraSummon"]));
Assert.IsType<Dictionary>(plainValue);
var actionBase = DeserializeNCAction(plainValue);
var action = Assert.IsType<AuraSummon>(actionBase);

Assert.Equal(avatarAddress, action.AvatarAddress);
Assert.Equal(groupId, action.GroupId);
Assert.Equal(summonCount, action.SummonCount);
}
}
}
1 change: 1 addition & 0 deletions NineChronicles.Headless/GraphTypes/ActionQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ public ActionQuery(StandaloneContext standaloneContext)
RegisterCombinationConsumable();
RegisterMead();
RegisterGarages();
RegisterSummon();

Field<NonNullGraphType<CraftQuery>>(
name: "craftQuery",
Expand Down
43 changes: 43 additions & 0 deletions NineChronicles.Headless/GraphTypes/ActionQueryFields/Summon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using GraphQL;
using GraphQL.Types;
using Libplanet.Crypto;
using Libplanet.Explorer.GraphTypes;
using Nekoyume.Action;

namespace NineChronicles.Headless.GraphTypes;

public partial class ActionQuery
{
private void RegisterSummon()
{
Field<NonNullGraphType<ByteStringType>>(
"auraSummon",
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<AddressType>>
{
Name = "avatarAddress",
Description = "Avatar address to get summoned items"
},
new QueryArgument<NonNullGraphType<IntGraphType>>
{
Name = "groupId",
Description = "Summon group id"
},
new QueryArgument<NonNullGraphType<IntGraphType>>
{
Name = "summonCount",
Description = "Count to summon. Must between 1 and 10."
}
),
resolve: context =>
{
var avatarAddr = context.GetArgument<Address>("avatarAddress");
var groupId = context.GetArgument<int>("groupId");
var summonCount = context.GetArgument<int>("summonCount");

ActionBase action = new AuraSummon(avatarAddr, groupId, summonCount);
return Encode(context, action);
}
);
}
}

0 comments on commit 1b19cc8

Please sign in to comment.