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>("job", arguments: new QueryArguments( new QueryArgument {Name = "id", Description = "Id of the Job"}), resolve: async context => { var id = Guid.Parse(context.GetArgument("id")); var data = await db.Jobs.AsQueryable().Where(j => j.Id == id).ToListAsync(); return data; }); Field ("indexedFileTree", arguments: new QueryArguments( new QueryArgument {Name = "hash", Description = "Hash of the Job"}), resolve: context => { var hash = context.GetArgument("hash"); var data = db.IndexedFiles.AsQueryable().Where(j => j.Hash == hash).FirstOrDefault(); 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); }); } } }