MetaEngine.CSharp.GraphQL.HttpClient.Tool
GraphQL SDL → C# HttpClient services and System.Text.Json models with typed queries, mutations & subscriptions (subscriptions surface as IAsyncEnumerable<T> over a ClientWebSocket using the graphql-transport-ws subprotocol), plus bearer/basic auth, retries, custom headers, smart HTTP-status error handling, fragments and @oneOf inputs. Ships as a NuGet library plus a dotnet tool CLI.
Pick your registry
The same generator, published to every ecosystem we support. Install however your project expects.
Drive it from the CLI or programmatically
dotnet tool ships a zero-config CLI. NuGet ships the same generator as a C# fluent API — same options, same output.
After install, point the CLI at your schema. It writes the generated tree to your chosen output directory.
metaengine-graphql-csharp-httpclient <input> <output> <namespace> [options]Generates C# HttpClient services and System.Text.Json models from a GraphQL SDL schema — typed queries, mutations & subscriptions (subscriptions surface as IAsyncEnumerable<T> over a ClientWebSocket using the graphql-transport-ws subprotocol). Install as a global .NET tool with: dotnet tool install --global MetaEngine.CSharp.GraphQL.HttpClient.Tool (requires the .NET 8.0+ SDK).
dotnet tool install --global MetaEngine.CSharp.GraphQL.HttpClient.Toolmetaengine-graphql-csharp-httpclient ./schema.graphql ./Generated Shop.Client \
--fragments \
--documentation \
--retries 3metaengine-graphql-csharp-httpclient ./schema.graphql ./Generated Shop.Client \
--bearer-auth API_TOKEN \
--error-handling \
--custom-scalar DateTime=System.DateTimemetaengine-graphql-csharp-httpclient ./schema.graphql ./Generated Shop.Client \
--middleware \
--subscription-url /api/graphqlEvery knob, documented
Every option is available on the C# fluent API as a method, and most are also exposed as CLI flags. Cross-cutting auth, headers, retries and timeouts apply across frameworks.
C# Output
2WithMiddleware()Generate middleware infrastructure (ApiDelegatingHandler + ServiceCollectionExtensions) for DI-ready registrationWithOptionsObjectThreshold(int)Parameter count at which an operation collapses its arguments into a single options object (default: 4)
Auth · Headers · Resilience
11WithErrorHandling()Smart error handling based on HTTP status semantics (404 / 403 → null · 400 / 422 / 409 → error body · 401 / 5xx → throw). GraphQL operations travel over HTTP POST.WithErrorHandling(errors => errors...)Per-status routing: ReturnNullFor(404, 403) · ReturnErrorFor(400, 422) · ThrowFor(401, 500)WithBearerAuth()Bearer token from env var (default API_TOKEN) — adds an Authorization headerWithBearerAuth(string)Bearer token from a specific env var nameWithBearerAuth(string, string)Bearer token from an env var with a custom header nameWithBasicAuth()HTTP Basic auth from default env vars (API_USERNAME / API_PASSWORD)WithBasicAuth(string, string)HTTP Basic auth from username + password env varsWithCustomHeader(string, string)Static header read from an env var. Repeatable (e.g. X-Tenant-ID ← TENANT_ID)WithRetries()Retries with exponential backoff (default status 429, 503)WithRetries(int)Retries with a custom max-attempts countWithRetries(int, double, double, int[])Retries with full custom settings: max attempts · base delay · max delay · retryable status codes
GraphQL Options
6WithDocumentation()Generate XML doc comments (///) on services and models from SDL type & field descriptionsWithFragments()Emit reusable named fragments for object-type selections (...TypeFields spreads)WithOneOfInputs()Generate idiomatic @oneOf input types (tagged-union inputs where exactly one field is set)WithCustomScalar(string, Type)Map a GraphQL custom scalar to a .NET type (e.g. DateTime → System.DateTime). Unmapped scalars default to stringWithTypeFilter(Func)Filter extracted GraphQL types before registration — only types returning true are generated (e.g. t => t.IsUsed)WithMethodNames(Func)Custom method naming rule
Subscriptions (WebSocket)
1WithSubscriptionUrl(string)Path appended to the WebSocket base URL (after http→ws / https→wss upgrade of baseUrl) for GraphQL subscriptions (default /graphql). Baked into the generated BaseHttpClient at generation time. Subscriptions surface as IAsyncEnumerable<T> over a ClientWebSocket using the graphql-transport-ws subprotocol.
Naming Transformations
3Types(Func)Transform type namesPaths(Func)Transform output pathsFileNames(Func)Transform file names
File Management
5CleanDestination()Clean output directory before generationAlwaysOverwrite()Always overwrite existing filesOnlyWhenModelChanged()Update only when model changesOnlyWhenNew()Write only new files, preserve existingCleanDirectories(...)Clean specific subdirectories
Diagnostics
2Verbose()Enable verbose loggingWithLogger(Action<string>)Route generation log output to a custom sink