dataloaders
Skill13 starsChanged 10 days agoMITView on GitHub
How Hot Chocolate DataLoaders batch the reviews asked for by every movie or author in a response into one Application query - source-generated DataLoaders, batching under the paging limit, and using them from a type. Use when a field on a list item needs data from another query, or when a query makes one database call per item.
In this repository41 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- add-a-use-caseSkill
- api-conventionsSkill
- branches-and-pull-requestsSkill
- cancellationSkill
- ci-for-your-solutionSkill
- ci-pipelineSkill
- clean-architecture-layersSkill
- configuration-and-environmentsSkill
- coverageSkill
- csharp-house-styleSkill
- data-access-ef-coreSkill
- database-migrationsSkill
- docker-and-composeSkill
- docs-and-voiceSkill
- errors-and-exceptionsSkill
- expose-a-use-caseSkill
- family-syncSkill
- health-checksSkill
- integration-testsSkill
- mapping-with-mapperlySkill
- mediatorSkill
- nitroSkill
- optional-token-authSkill
- packages-and-dependenciesSkill
- pagingSkill
- presentation-integration-testsSkill
- releasesSkill
- sample-dataSkill
- schema-snapshotSkill
- security-findingsSkill
- serilogSkill
- telemetrySkill
- template-authoringSkill
- test-designSkill
- time-providerSkill
- unit-testsSkill
- validationSkill
- writing-a-skillSkill
- xml-docs-and-openapiSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 20
Add an Application query that takes a list of ids and returns a dictionary (add-a-use-case), like GetReviewsForMoviesQuery.
- Very specific: line 21
Add a [DataLoader] method that chunks the ids by Paging.MaxLimit and sends the query for each chunk.
- Very specific: line 24
Test a list query that asks for the child field, and check the counts match (presentation-integration-tests).
- Very specific: line 41
Call sender.Send from a resolver on a list item.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
DataLoaders
The rule
A field on a list item never sends its own query. Asking for the reviews of 50 movies must cost one Application query, not 50. DataLoaders in src/Presentation/GraphQL/DataLoaders/ collect the ids asked for during one request and load them together.
They're static methods with [DataLoader]. The source generator creates an interface and class for each one: GetReviewsByMovieIdAsync becomes IReviewsByMovieIdDataLoader. Each takes the ids, then ISender and the token, and returns a Dictionary<id, value> with an entry for every id, empty when there's nothing.
Batches are split into chunks of Paging.MaxLimit, because the Application queries refuse more ids than that.
Steps
- Add an Application query that takes a list of ids and returns a dictionary (
add-a-use-case), likeGetReviewsForMoviesQuery. - Add a
[DataLoader]method that chunks the ids byPaging.MaxLimitand sends the query for each chunk. - Return an entry for every id asked for, so callers can use
LoadRequiredAsync. - In the type, add a resolver that takes
[Parent], the generated DataLoader interface and the token, and callsLoadRequiredAsync(parent.Id, cancellationToken). - Test a list query that asks for the child field, and check the counts match (
presentation-integration-tests).
Example
// src/Presentation/GraphQL/Types/MovieSummaryType.cs
public static async Task<List<Review>> GetReviewsAsync(
[Parent] MovieSummary movie,
IReviewsByMovieIdDataLoader reviews,
CancellationToken cancellationToken)
{
return await reviews.LoadRequiredAsync(movie.Id, cancellationToken);
}Don't
- Call
sender.Sendfrom a resolver on a list item. - Return a dictionary missing some ids.
- Send more than
Paging.MaxLimitids in one Application query.
Check
dotnet test tests/Presentation.Tests.Integration --filter "FullyQualifiedName~Movies|FullyQualifiedName~Authors"Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

