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
- LeanMeanCleanApps/CleanLambdaFunctiontheir own version, first seen Nov 15, 2026
- LeanMeanCleanApps/CleanWebApitheir own version, first seen Nov 15, 2026
- LeanMeanCleanApps/CleanMinimalApitheir own version, first seen Nov 15, 2026
- LeanMeanCleanApps/CleanModelContextProtocoltheir own version, first seen Nov 8, 2026
Other versions4 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 4
- LeanMeanCleanApps/CleanMinimalApi★ 400same name
- LeanMeanCleanApps/CleanWebApi★ 4same name
- LeanMeanCleanApps/CleanModelContextProtocol★ 1same name
- LeanMeanCleanApps/CleanLambdaFunction★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
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
- dataloadersSkill
- docker-and-composeSkill
- docs-and-voiceSkill
- errors-and-exceptionsSkill
- 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
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
- Very specific: line 28
Add the use case first (add-a-use-case).
- Very specific: line 29
Add the field to the feature's class in Queries/ or Mutations/.
- Very specific: line 34
Document the method (<summary>, <param> for each argument except sender and the token).
- Very specific: line 35
Update the schema snapshot (schema-snapshot), then test the field through HTTP (presentation-integration-tests).
- Very specific: line 92
Use Hot Chocolate's [UseOffsetPaging], [UseFiltering] or [UseSorting], or return IQueryable.
- Very specific: line 94
Write input or payload classes for a mutation, or return a Boolean to say it worked.
- Very specific: line 96
Document sender or the cancellation token.
“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.
Files
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/:
| Folder | Holds | Shape |
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 filter | api-conventions |
DataLoaders/ | Batched lookups for fields on list items | dataloaders |
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
- Add the use case first (
add-a-use-case). - Add the field to the feature's class in
Queries/orMutations/. The method name minusGetandAsyncbecomes the field name (GetMoviesismovies). - In a solution with authentication, put
[Authorize]on every field,versionincluded (optional-token-auth). Without it, leave the attribute out; the examples below show it. - Lists use
[UsePaging(ConnectionName = "...")], takeint? firstandstring? after, and returnpage.ToConnection()withafter.ToOffset()as the offset (api-conventions). - A mutation takes its input fields as plain arguments and returns the result itself.
AddMutationConventions(applyToAllMutations: true)wraps them in<Mutation>Inputand<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 asreviewIdondeleteReview. - A new entity gets a type in
Types/: declare each field, mark non-null strings withNonNullType<StringType>, and resolve child lists on list items through a DataLoader. - Document the method (
<summary>,<param>for each argument exceptsenderand the token). The<param>tags become the input fields' descriptions. - 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
AddTypeorAddQueryType. The generator does it. - Use Hot Chocolate's
[UseOffsetPaging],[UseFiltering]or[UseSorting], or returnIQueryable. 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
Booleanto say it worked. The conventions build them, and the payload'serrorssays what went wrong. - Resolve a child list per item with
sender.Sendinside a type. Use a DataLoader. - Document
senderor 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/graphqlDoes 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.

