using System; using System.Collections.Generic; using GraphQL; using GraphQL.Types; using GraphQLParser.AST; using MongoDB.Driver; using MongoDB.Driver.Linq; using Wabbajack.BuildServer.Models; using Wabbajack.Common; namespace Wabbajack.BuildServer.GraphQL { public class Query : ObjectGraphType { public Query(DBContext db) { Field>("unfinishedJobs", resolve: context => { var data = db.Jobs.AsQueryable().Where(j => j.Ended == null).ToList(); return data; }); FieldAsync>("modLists", arguments: new QueryArguments(new QueryArgument { Name = "filter", Description = "Filter lists to those that only have these archive classifications" }), resolve: async context => { var arg = context.GetArgument("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>("job", arguments: new QueryArguments( new QueryArgument {Name = "id", Description = "Id of the Job"}), resolve: async context => { var id = context.GetArgument("id"); var data = await db.Jobs.AsQueryable().Where(j => j.Id == id).ToListAsync(); return data; }); FieldAsync>("uploadedFiles", resolve: async context => { var data = await db.UploadedFiles.AsQueryable().ToListAsync(); return data; }); FieldAsync>("dailyUniqueMetrics", arguments: new QueryArguments( new QueryArgument {Name = "metric_type", Description = "The grouping of metric data to query"} ), resolve: async context => { var group = context.GetArgument("metric_type"); return await Metric.Report(db, group); }); } } }