Overview
Hot Chocolate provides data middleware that applies common operations directly to your IQueryable or IExecutable data sources. Instead of implementing pagination, filtering, sorting, and projections by hand, you declare them on your fields and Hot Chocolate generates the corresponding GraphQL types and applies the operations at execution time.
Pagination
Hot Chocolate provides cursor-based connection pagination out of the box. Connections follow the Relay Cursor Connections Specification, giving clients a standardized way to page through large datasets. When backed by IQueryable, pagination translates directly to native database queries.
Filtering
When you return a list of entities, clients often need to filter them by operations like equals, contains, or startsWith. Hot Chocolate generates the necessary filter input types from your .NET models and translates applied filters into native database queries.
Sorting
Hot Chocolate generates sort input types from your .NET models, allowing clients to specify which fields to sort by and in which direction. Like filtering, sort operations translate to native database queries when backed by IQueryable.
Projections
Projections optimize database queries by selecting only the columns that match the fields requested in the GraphQL query. If a client requests name and id, Hot Chocolate queries only those columns from the database.
Batching
DataLoaders and batch resolvers solve the N+1 problem in GraphQL. When the execution engine resolves a list of objects and each needs related data, a DataLoader collects all individual requests and sends a single query for all keys at once.
- DataLoader for key-based batching with deduplication and caching.
- Batch Resolvers for simpler cases where caching is not needed.
Integrations
Hot Chocolate is not bound to a specific database. The data middleware works with any IQueryable provider. We provide specific guidance for the most common data sources:
- Entity Framework for EF Core DbContext patterns and pooling.
- MongoDB for the MongoDB driver integration.
- Marten for Marten document database support.
- Extending Filtering for building custom filter providers.