Soenneker.GraphQL.Generator
11.0.230
Prefix Reserved
dotnet add package Soenneker.GraphQL.Generator --version 11.0.230
NuGet\Install-Package Soenneker.GraphQL.Generator -Version 11.0.230
<PackageReference Include="Soenneker.GraphQL.Generator" Version="11.0.230" />
<PackageVersion Include="Soenneker.GraphQL.Generator" Version="11.0.230" />
<PackageReference Include="Soenneker.GraphQL.Generator" />
paket add Soenneker.GraphQL.Generator --version 11.0.230
#r "nuget: Soenneker.GraphQL.Generator, 11.0.230"
#:package Soenneker.GraphQL.Generator@11.0.230
#addin nuget:?package=Soenneker.GraphQL.Generator&version=11.0.230
#tool nuget:?package=Soenneker.GraphQL.Generator&version=11.0.230
Soenneker.GraphQL.Generator
Generates C# schema models, operation builders, selection sets, JSON serialization metadata, and an HTTP transport from GraphQL SDL.
Install
dotnet add package Soenneker.GraphQL.Generator
Generate in memory
Use the parameterless generator when the caller will inspect or write the generated files:
var config = new GeneratorConfig
{
Namespace = "MyCompany.MyApi.GraphQL",
OutputDirectory = "./Generated",
EntryClientName = "MyApiClient"
};
var generator = new GraphQlGenerator();
GenerationResult result = generator.Generate(schemaSdl, config);
foreach (GeneratedFile file in result.Files)
Console.WriteLine(file.RelativePath);
Generate() does not access the filesystem; OutputDirectory is ignored by that method.
Generate files with DI
services.AddGraphQlGeneratorAsScoped();
GenerationRunResult run = await generator.Run(
schemaSdl,
config,
cancellationToken);
Run() writes each generated file beneath OutputDirectory and returns its resolved absolute path with the generation counts. Existing files at generated paths are overwritten. Files no longer produced by a changed schema are not deleted, so use a dedicated output directory and clean it explicitly when stale output must be removed.
Singleton registration is also available through AddGraphQlGeneratorAsSingleton().
Generate from a config file
{
"SchemaPath": "./schema.graphql",
"OutputDirectory": "./Generated",
"Namespace": "MyCompany.MyApi.GraphQL",
"EntryClientName": "MyApiClient",
"IdClrType": "string",
"EmitRootTypes": true,
"EmitScalarAliases": false,
"EmitJsonSerializerContext": true,
"JsonSerializerContextName": "MyApiJsonContext",
"EmitOperationClients": true,
"MaxSelectionDepth": 2
}
GenerationRunResult run = await generator.RunFromConfig(
"./gql2cs.json",
cancellationToken);
Relative SchemaPath and OutputDirectory values are resolved from the process working directory.
The repository also contains a CLI project. After building or publishing cli/Soenneker.GraphQL.Generator.Cli, run:
gql2cs --config ./gql2cs.json
Generated client usage
The output includes GraphQlHttpClient, IGraphQlClient, transport DTOs, and the configured entry client:
var httpClient = new HttpClient
{
BaseAddress = new Uri("https://api.example.com/graphql")
};
var transport = new GraphQlHttpClient(httpClient);
var client = new MyApiClient(transport);
Generated operation builders create query documents and variables from the SDL. HTTP errors throw through EnsureSuccessStatusCode; GraphQL errors in a successful HTTP response remain in GraphQlResponse<T>.Errors for the caller to inspect.
Important options
| Option | Effect |
|---|---|
ScalarMappings |
Overrides GraphQL scalar-to-CLR type mappings. |
EmitScalarAliases |
Emits global aliases for otherwise unmapped custom scalars. |
EmitOperationClients |
Emits request builders and the entry client for query and mutation fields. |
MaxSelectionDepth |
Limits automatic nested selection-set expansion. |
GlobalUsings |
Adds namespace imports to generated files. |
EmitJsonSerializerContext |
Emits the configured source-generated JSON context. |
Schema parsing and in-memory generation are synchronous. Cancellation applies to filesystem reads, directory creation, and file writes performed by Run() and RunFromConfig().
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- GraphQL-Parser (>= 9.5.1)
- Soenneker.Extensions.ValueTask (>= 11.0.139)
- Soenneker.Utils.Directory (>= 11.0.1002)
- Soenneker.Utils.File (>= 11.0.2369)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Soenneker.GraphQL.Generator:
| Package | Downloads |
|---|---|
|
gql2cs
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 11.0.230 | 56 | 12/3/2026 |
| 11.0.229 | 91 | 12/3/2026 |
| 11.0.228 | 80 | 12/3/2026 |
| 11.0.227 | 79 | 12/3/2026 |
| 11.0.226 | 70 | 12/2/2026 |
| 11.0.225 | 72 | 12/2/2026 |
| 11.0.224 | 71 | 12/2/2026 |
| 11.0.221 | 91 | 12/2/2026 |
| 11.0.220 | 97 | 12/2/2026 |
| 11.0.219 | 90 | 12/2/2026 |
| 11.0.218 | 86 | 12/2/2026 |
| 11.0.217 | 86 | 12/1/2026 |
| 11.0.216 | 90 | 12/1/2026 |
| 11.0.215 | 119 | 12/1/2026 |
| 11.0.214 | 91 | 12/1/2026 |
| 11.0.213 | 93 | 12/1/2026 |
| 11.0.212 | 114 | 11/30/2026 |
| 11.0.211 | 100 | 11/30/2026 |
| 11.0.210 | 100 | 11/30/2026 |
| 11.0.209 | 99 | 11/29/2026 |
Updated Multiple NuGet packages