agentleFS
LeanMeanCleanAppsLeanMeanCleanApps/CleanGraphQLApi/.agents/skills/dataloaders/SKILL.md

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.

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
  1. Very specific:

    Add an Application query that takes a list of ids and returns a dictionary (add-a-use-case), like GetReviewsForMoviesQuery.

    line 20
  2. Very specific:

    Add a [DataLoader] method that chunks the ids by Paging.MaxLimit and sends the query for each chunk.

    line 21
  3. Very specific:

    Test a list query that asks for the child field, and check the counts match (presentation-integration-tests).

    line 24
  4. Very specific:

    Call sender.Send from a resolver on a list item.

    line 41

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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

  1. Add an Application query that takes a list of ids and returns a dictionary (add-a-use-case), like GetReviewsForMoviesQuery.
  2. Add a [DataLoader] method that chunks the ids by Paging.MaxLimit and sends the query for each chunk.
  3. Return an entry for every id asked for, so callers can use LoadRequiredAsync.
  4. In the type, add a resolver that takes [Parent], the generated DataLoader interface and the token, and calls LoadRequiredAsync(parent.Id, cancellationToken).
  5. 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.Send from a resolver on a list item.
  • Return a dictionary missing some ids.
  • Send more than Paging.MaxLimit ids in one Application query.

Check

dotnet test tests/Presentation.Tests.Integration --filter "FullyQualifiedName~Movies|FullyQualifiedName~Authors"

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.