GraphQL endpoints for modlist status

This commit is contained in:
Timothy Baldridge 2020-01-09 06:36:27 -07:00
parent 5d22e3d094
commit a9362f51e8
3 changed files with 92 additions and 1 deletions

View File

@ -19,7 +19,7 @@ namespace Wabbajack.BuildServer.Controllers
}
[HttpGet]
[Route("status")]
[Route("status.json")]
public async Task<IList<ModlistSummary>> HandleGetLists()
{
return await Db.ModListStatus.AsQueryable().Select(m => m.Summary).ToListAsync();

View File

@ -0,0 +1,67 @@
using System.Collections.Generic;
using System.Linq;
using GraphQL.Types;
using Wabbajack.BuildServer.Models;
using Wabbajack.Lib.ModListRegistry;
namespace Wabbajack.BuildServer.GraphQL
{
public class ModListStatusType : ObjectGraphType<ModListStatus>
{
public ModListStatusType()
{
Name = "ModlistSummary";
Description = "Short summary of a modlist status";
Field(x => x.Id).Description("Name of the modlist");
Field(x => x.Metadata.Title).Description("Human-friendly name of the modlist");
Field<ListGraphType<ModListArchiveType>>("Archives",
arguments: new QueryArguments(new QueryArgument<ArchiveEnumFilterType>
{
Name = "filter", Description = "Type of archives to return"
}),
resolve: context =>
{
var arg = context.GetArgument<string>("filter");
var archives = (IEnumerable<DetailedStatusItem>)context.Source.DetailedStatus.Archives;
switch (arg)
{
case "FAILED":
archives = archives.Where(a => a.IsFailing);
break;
case "PASSED":
archives = archives.Where(a => !a.IsFailing);
break;
default:
break;
}
return archives;
});
}
}
public class ModListArchiveType : ObjectGraphType<DetailedStatusItem>
{
public ModListArchiveType()
{
Field(x => x.IsFailing).Description("Is this archive failing validation?");
Field(x => x.Archive.Name).Description("Name of the archive");
Field(x => x.Archive.Hash).Description("Hash of the archive");
Field(x => x.Archive.Size).Description("Size of the archive");
}
}
public class ArchiveEnumFilterType : EnumerationGraphType
{
public ArchiveEnumFilterType()
{
Name = "ArchiveFilterEnum";
Description = "What archives should be returned from a sublist";
AddValue("ALL", "All archives are returned", "ALL");
AddValue("FAILED", "All archives are returned", "FAILED");
AddValue("PASSED", "All archives are returned", "PASSED");
}
}
}

View File

@ -19,6 +19,30 @@ namespace Wabbajack.BuildServer.GraphQL
var data = db.Jobs.AsQueryable().Where(j => j.Ended == null).ToList();
return data;
});
FieldAsync<ListGraphType<ModListStatusType>>("modLists",
arguments: new QueryArguments(new QueryArgument<ArchiveEnumFilterType>
{
Name = "filter", Description = "Filter lists to those that only have these archive classifications"
}),
resolve: async context =>
{
var arg = context.GetArgument<string>("filter");
var lists = db.ModListStatus.AsQueryable();
switch (arg)
{
case "FAILED":
lists = lists.Where(l => l.DetailedStatus.HasFailures);
break;
case "PASSED":
lists = lists.Where(a => !a.DetailedStatus.HasFailures);
break;
default:
break;
}
return await lists.ToListAsync();
});
FieldAsync<ListGraphType<JobType>>("job",
arguments: new QueryArguments(