Installation
Prerequisites
- .NET 8.0 or later
- HotChocolate 16+
Add the NuGet Package
- .NET CLI
- Package Manager
dotnet add package Community.HotChocolate.Data.GroupingInstall-Package Community.HotChocolate.Data.GroupingRegister the Convention
using HotChocolate.Data.Grouping;
builder.Services
.AddGraphQL()
.AddGrouping()
.AddFiltering()
.AddQueryType<Query>();See Convention for the inline and subclass variants.
Decorate a Query Field
Mark any field returning IQueryable<T> or IEnumerable<T> with [UseGrouping]:
public class Query
{
[UseGrouping]
public IQueryable<Employee> GetEmployeeGrouping(MyDbContext db) => db.Employees;
}The middleware wraps the return type as [EntityGrouping!]!, adds a filterNullParent: Boolean = false argument, and composes with [UseFiltering] when present (where runs before the GROUP BY).