agentleFS
LeanMeanCleanAppsLeanMeanCleanApps/CleanGraphQLApi/.agents/skills/expose-a-use-case/SKILL.md

expose-a-use-case

Skill13 starsChanged 10 days agoMITView on GitHub

How to put an Application use case on the Hot Chocolate GraphQL schema - static partial query and mutation classes, source-generated types, mutation conventions with typed errors, Relay connections, authorization, XML comments as schema descriptions, and tests. Use when adding or changing a query, mutation, field or type in this GraphQL API.

4 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

7 rules. 0 are common, 0 are distinctive, and 7 are very specific to this project.

  • 0

    Common

    Most of the 4 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Add the use case first (add-a-use-case).

    line 28
  2. Very specific:

    Add the field to the feature's class in Queries/ or Mutations/.

    line 29
  3. Very specific:

    Document the method (<summary>, <param> for each argument except sender and the token).

    line 34
  4. Very specific:

    Update the schema snapshot (schema-snapshot), then test the field through HTTP (presentation-integration-tests).

    line 35
  5. Very specific:

    Use Hot Chocolate's [UseOffsetPaging], [UseFiltering] or [UseSorting], or return IQueryable.

    line 92
  6. Very specific:

    Write input or payload classes for a mutation, or return a Boolean to say it worked.

    line 94
  7. Very specific:

    Document sender or the cancellation token.

    line 96

“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “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

Expose a use case (GraphQL)

The rule

The schema is built from code by Hot Chocolate's source generator (HotChocolate.Types.Analyzers), registered in one call: AddPresentationTypes() in src/Presentation/Extensions/ProgramExtensions.cs. Everything lives in src/Presentation/GraphQL/:

FolderHoldsShape
Queries/Root query fields, one class per feature[QueryType] public static partial class MovieQueries
Mutations/Root mutation fields[MutationType] public static partial class ReviewMutations
Types/How an Application entity appears in the schema[ObjectType<Movie>] public static partial class MovieType with static partial void Configure(...)
Errors/Typed mutation errors and the error filterapi-conventions
DataLoaders/Batched lookups for fields on list itemsdataloaders

Each field method is public static async, takes its arguments, then ISender sender and CancellationToken cancellationToken, builds the Application request, sends it and returns the result. Fields hold no rules: validation and not-found come from Application. A mutation's [Error<T>] attributes turn them into typed errors in its payload, and ApplicationErrorFilter turns them into GraphQL errors everywhere else (api-conventions).

Hot Chocolate reads XML comments, so a field's <summary> and <param> tags and an entity record's <param> tags become the schema descriptions.

Steps

  1. Add the use case first (add-a-use-case).
  2. Add the field to the feature's class in Queries/ or Mutations/. The method name minus Get and Async becomes the field name (GetMovies is movies).
  3. In a solution with authentication, put [Authorize] on every field, version included (optional-token-auth). Without it, leave the attribute out; the examples below show it.
  4. Lists use [UsePaging(ConnectionName = "...")], take int? first and string? after, and return page.ToConnection() with after.ToOffset() as the offset (api-conventions).
  5. A mutation takes its input fields as plain arguments and returns the result itself. AddMutationConventions(applyToAllMutations: true) wraps them in <Mutation>Input and <Mutation>Payload. Add [Error<ValidationError>] and [Error<NotFoundError>] for the failures it can raise, and [UseMutationConvention(PayloadFieldName = "...")] when the result isn't an entity, such as reviewId on deleteReview.
  6. A new entity gets a type in Types/: declare each field, mark non-null strings with NonNullType<StringType>, and resolve child lists on list items through a DataLoader.
  7. Document the method (<summary>, <param> for each argument except sender and the token). The <param> tags become the input fields' descriptions.
  8. Update the schema snapshot (schema-snapshot), then test the field through HTTP (presentation-integration-tests).

Example

// src/Presentation/GraphQL/Queries/MovieQueries.cs
/// <summary>
/// Lists movies ordered by title, one page at a time, optionally only those whose title contains a search term.
/// </summary>
/// <param name="query">The words to look for in the title, ignoring case. Leave empty to list every movie.</param>
[UsePaging(ConnectionName = "Movies")]
[Authorize]
public static async Task<Connection<MovieSummary>> GetMovies(
    string? query,
    int? first,
    string? after,
    ISender sender,
    CancellationToken cancellationToken)
{
    var page = await sender.Send(new Movies.GetMovies.GetMoviesQuery
    {
        Query = query,
        Offset = after.ToOffset(),
        Limit = first ?? Paging.DefaultLimit
    }, cancellationToken);

    return page.ToConnection();
}
// src/Presentation/GraphQL/Mutations/ReviewMutations.cs
/// <summary>
/// Changes the star rating of a review and returns the updated review. The author and the movie of a review can't change.
/// </summary>
/// <param name="id">The unique identifier of the review.</param>
/// <param name="stars">The new star rating, from 1 to 5.</param>
[Authorize]
[Error<ValidationError>]
[Error<NotFoundError>]
public static async Task<Review> UpdateReview(
    Guid id,
    int stars,
    ISender sender,
    CancellationToken cancellationToken)
{
    return await sender.Send(new Commands.UpdateReview.UpdateReviewCommand
    {
        Id = id,
        Stars = stars
    }, cancellationToken);
}

Don't

  • Register types one by one with AddType or AddQueryType. The generator does it.
  • Use Hot Chocolate's [UseOffsetPaging], [UseFiltering] or [UseSorting], or return IQueryable. Paging, search and order belong to Application.
  • Catch exceptions or check for null in a field.
  • Write input or payload classes for a mutation, or return a Boolean to say it worked. The conventions build them, and the payload's errors says what went wrong.
  • Resolve a child list per item with sender.Send inside a type. Use a DataLoader.
  • Document sender or the cancellation token.

Check

dotnet build
dotnet test tests/Presentation.Tests.Integration
dotnet run --project ./src/Presentation   # then try it in Nitro at http://localhost:7330/graphql

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.