diff --git a/NineChronicles.Headless/GraphTypes/GuildType.cs b/NineChronicles.Headless/GraphTypes/GuildType.cs new file mode 100644 index 000000000..fdfb46f8b --- /dev/null +++ b/NineChronicles.Headless/GraphTypes/GuildType.cs @@ -0,0 +1,38 @@ +using GraphQL.Types; +using Libplanet.Crypto; +using Libplanet.Explorer.GraphTypes; +using Nekoyume.Model.Guild; + +namespace NineChronicles.Headless.GraphTypes; + +public class GuildType : ObjectGraphType +{ + public Address Address { get; set; } + + public Address ValidatorAddress { get; set; } + + public Address GuildMasterAddress { get; set; } + + public GuildType() + { + Field>( + nameof(Address), + description: "Address of the guild", + resolve: context => context.Source.Address); + Field>( + nameof(ValidatorAddress), + description: "Validator address of the guild", + resolve: context => context.Source.ValidatorAddress); + Field>( + nameof(GuildMasterAddress), + description: "Guild master address of the guild", + resolve: context => context.Source.GuildMasterAddress); + } + + public static GuildType FromDelegatee(Guild guild) => new GuildType + { + Address = guild.Address, + ValidatorAddress = guild.ValidatorAddress, + GuildMasterAddress = guild.GuildMasterAddress, + }; +} diff --git a/NineChronicles.Headless/GraphTypes/StateQuery.cs b/NineChronicles.Headless/GraphTypes/StateQuery.cs index 302c9a817..a02057e7d 100644 --- a/NineChronicles.Headless/GraphTypes/StateQuery.cs +++ b/NineChronicles.Headless/GraphTypes/StateQuery.cs @@ -721,7 +721,7 @@ public StateQuery() } ); - Field( + Field( name: "guild", description: "State for guild.", arguments: new QueryArguments( @@ -740,9 +740,13 @@ public StateQuery() } var repository = new GuildRepository(new World(context.Source.WorldState), new HallowActionContext { }); - var joinedGuild = (Address?)repository.GetJoinedGuild(agentAddress); + if (repository.GetJoinedGuild(agentAddress) is { } guildAddress) + { + var guild = repository.GetGuild(guildAddress); + return GuildType.FromDelegatee(guild); + } - return joinedGuild; + return null; } );