-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2282 from U-lis/feature/gql-claim-items
Introduce ClaimItems GQL endpoint
- Loading branch information
Showing
4 changed files
with
149 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
NineChronicles.Headless/GraphTypes/ActionQueryFields/ClaimItems.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Collections.Generic; | ||
using GraphQL; | ||
using GraphQL.Types; | ||
using Libplanet.Crypto; | ||
using Libplanet.Explorer.GraphTypes; | ||
using Libplanet.Types.Assets; | ||
using Nekoyume.Action; | ||
using NineChronicles.Headless.GraphTypes.Input; | ||
|
||
namespace NineChronicles.Headless.GraphTypes | ||
{ | ||
public partial class ActionQuery | ||
{ | ||
private void RegisterClaimItems() | ||
{ | ||
Field<NonNullGraphType<ByteStringType>>( | ||
"claimItems", | ||
arguments: new QueryArguments( | ||
new QueryArgument<NonNullGraphType<ListGraphType<NonNullGraphType<ClaimDataInputType>>>> | ||
{ | ||
Name = "claimData", | ||
Description = "List of pair of avatar address, List<FAV> to claim." | ||
} | ||
), | ||
resolve: context => | ||
{ | ||
var claimData = | ||
context.GetArgument< | ||
List<(Address avataAddress, IReadOnlyList<FungibleAssetValue> fungibleAssetValues)> | ||
>("claimData").AsReadOnly(); | ||
ActionBase action = new ClaimItems(claimData); | ||
return Encode(context, action); | ||
} | ||
); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
NineChronicles.Headless/GraphTypes/Input/ClaimDataInputType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using GraphQL.Types; | ||
using Libplanet.Crypto; | ||
using Libplanet.Explorer.GraphTypes; | ||
using Libplanet.Types.Assets; | ||
|
||
namespace NineChronicles.Headless.GraphTypes.Input; | ||
|
||
public class ClaimDataInputType : InputObjectGraphType<(Address avatarAddress, IReadOnlyList<FungibleAssetValue> favList)> | ||
{ | ||
public ClaimDataInputType() | ||
{ | ||
Field<NonNullGraphType<AddressType>>("avatarAddress"); | ||
Field<NonNullGraphType<ListGraphType<NonNullGraphType<FungibleAssetValueInputType>>>>("fungibleAssetValues"); | ||
} | ||
|
||
public override object ParseDictionary(IDictionary<string, object?> value) | ||
{ | ||
return ( | ||
(Address)value["avatarAddress"]!, | ||
(IReadOnlyList<FungibleAssetValue>)((object[])value["fungibleAssetValues"]!).Cast<FungibleAssetValue>().ToList() | ||
); | ||
} | ||
} |