Skip to content

Commit

Permalink
Merge pull request #2605 from planetarium/feature/gql/last-cleared-stage
Browse files Browse the repository at this point in the history
Introduce new GQL: lastClearedStage
  • Loading branch information
U-lis authored Nov 1, 2024
2 parents 164ba07 + 3fe66c8 commit 310861b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using GraphQL.Types;

namespace NineChronicles.Headless.GraphTypes.States.Models.World;

public class ClearedStageType : ObjectGraphType<(int WorldId, int StageId)>
{
public ClearedStageType()
{
Field<NonNullGraphType<IntGraphType>>("worldId", resolve: context => context.Source.WorldId);
Field<NonNullGraphType<IntGraphType>>("stageId", resolve: context => context.Source.StageId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ public WorldInformationType()
? world
: throw new ExecutionError($"Failed to fetch world {worldId}.");
});

Field<NonNullGraphType<ClearedStageType>>(
"lastClearedStage",
resolve: context =>
{
var found = context.Source.TryGetLastClearedStageId(out var stageId);
if (!found)
{
stageId = 0;
}
var worldFound = context.Source.TryGetWorldByStageId(stageId, out var world);
return (worldFound ? world.Id : 0, stageId);
}
);
}
}
}

0 comments on commit 310861b

Please sign in to comment.