Skip to content

Commit

Permalink
introduce "inventory" query
Browse files Browse the repository at this point in the history
  • Loading branch information
boscohyun committed May 27, 2024
1 parent ceaab2f commit 8b4e47b
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions Mimir/GraphQL/TypeExtensions/InventoryTypeExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Lib9c.GraphQL.Objects;
using Lib9c.GraphQL.Types;
using Libplanet.Crypto;
using Mimir.GraphQL.Factories;
using Mimir.GraphQL.Queries;
using Mimir.Repositories;

namespace Mimir.GraphQL.TypeExtensions;

public class InventoryTypeExtension : ObjectTypeExtension<Query>
{
protected override void Configure(IObjectTypeDescriptor<Query> descriptor)
{
descriptor
.Field("inventory")
.Argument("planetName", a => a.Type<NonNullType<PlanetNameEnumType>>())
.Argument("avatarAddress", a => a.Type<NonNullType<AddressType>>())
.Type<InventoryType>()
.ResolveWith<InventoryTypeExtension>(_ => GetInventory(
default!,
default!,
default!));
}

private static InventoryObject? GetInventory(
string planetName,
Address avatarAddress,
[Service] AvatarRepository avatarRepository)
{
var inventory = avatarRepository.GetInventory(planetName, avatarAddress);
if (inventory is null)
{
return null;
}

var consumables = inventory.Consumables.Select(ItemObjectFactory.Create).ToArray();
var costumes = inventory.Costumes.Select(ItemObjectFactory.Create).ToArray();
var equipments = inventory.Equipments.Select(ItemObjectFactory.Create).ToArray();
var materials = inventory.Materials.Select(ItemObjectFactory.Create).ToArray();
return new InventoryObject(
consumables,
costumes,
equipments,
materials);
}
}

0 comments on commit 8b4e47b

Please sign in to comment.