Soenneker.GraphQL.Generator 11.0.216

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Soenneker.GraphQL.Generator --version 11.0.216
                    
NuGet\Install-Package Soenneker.GraphQL.Generator -Version 11.0.216
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Soenneker.GraphQL.Generator" Version="11.0.216" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.GraphQL.Generator" Version="11.0.216" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.GraphQL.Generator" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.GraphQL.Generator --version 11.0.216
                    
#r "nuget: Soenneker.GraphQL.Generator, 11.0.216"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Soenneker.GraphQL.Generator@11.0.216
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.GraphQL.Generator&version=11.0.216
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.GraphQL.Generator&version=11.0.216
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

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 Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 72 12/3/2026
11.0.229 93 12/3/2026
11.0.228 82 12/3/2026
11.0.227 80 12/3/2026
11.0.226 72 12/2/2026
11.0.225 74 12/2/2026
11.0.224 74 12/2/2026
11.0.221 93 12/2/2026
11.0.220 98 12/2/2026
11.0.219 91 12/2/2026
11.0.218 87 12/2/2026
11.0.217 87 12/1/2026
11.0.216 91 12/1/2026
11.0.215 120 12/1/2026
11.0.214 92 12/1/2026
11.0.213 94 12/1/2026
11.0.212 115 11/30/2026
11.0.211 101 11/30/2026
11.0.210 101 11/30/2026
11.0.209 100 11/29/2026
Loading failed

Update soenneker/nuget-resilient-publish action to v5 (#369)