/// <summary> /// Creates a query that counts the number of models that comply to a set of conditions /// </summary> /// <typeparam name="TModel">The type of model to count</typeparam> /// <returns>A function that takes a graphql context and returns a count of models that satisfy the condition</returns> public static Func <ResolveFieldContext <object>, Task <object> > CreateCountQuery <TModel>() where TModel : class, IOwnerAbstractModel, new() { return(async context => { // Fetch the models that we need var models = QueryHelpers.CreateResolveFunction <TModel>()(context); // Apply conditions to the query models = QueryHelpers.CreateWhereCondition(context, models); models = QueryHelpers.CreateIdsCondition(context, models); models = QueryHelpers.CreateIdCondition(context, models); return new NumberObject { Number = await models.CountAsync() }; }); }