PolyglotDataStudio.GraphQL.CLI
1.2.1
dotnet tool install --global PolyglotDataStudio.GraphQL.CLI --version 1.2.1
dotnet new tool-manifest
dotnet tool install --local PolyglotDataStudio.GraphQL.CLI --version 1.2.1
#tool dotnet:?package=PolyglotDataStudio.GraphQL.CLI&version=1.2.1
nuke :add-package PolyglotDataStudio.GraphQL.CLI --version 1.2.1
PolyglotDataStudio.GraphQL.CLI
A small command-line tool that generates C# code from GraphQL SDL or the JSON output of an introspection query using the
T4 templates included in this project. Built for .NET 10 and using Mono.Options for command-line parsing. The CLI reads
GraphQL schema files (SDL or JSON) and emits generated C# files according to the templates located in the Templates
folder.
The generated C# code has a dependency on the PolyglotDataStudio.GraphQL library, which provides the base types for GraphQL
objects. See the PolyglotDataStudio.GraphQL README for details on using the generated
types.
Features
- Generate C# object, interface, enum and operation models from GraphQL SDL or Introspection JSON using T4 templates.
- Templates are included in the
Templatesfolder and configured for design-time T4 processing. - Generates comprehensive C# types that map to GraphQL schema definitions, designed to work with the PolyglotDataStudio.GraphQL.
Requirements
- .NET 10 SDK
- The project uses
Mono.Optionsfor argument parsing - Output depends on
PolyglotDataStudio.GraphQLlibrary
Installation
The recommended path for usage is to install the CLI tool as a global .NET tool (optional):
dotnet tool install --global PolyglotDataStudio.GraphQL.CLI
Command-line options
This CLI provides the following options:
-f, --file "<file>"- Path to the GraphQL SDL or JSON file to be imported.
- SDL file must conform to the GraphQL Schema Definition Language specification.
- JSON file should be the output of a GraphQL introspection query.
-uor--url "<url>"- URL of a GraphQL endpoint to fetch the schema via introspection query.
- Does not yet support authentication headers
- Example:
--url "https://api.spacex.land/graphql/"
-o, --outputDir <directory>- Directory where generated C# files will be written.
-n, --namespace "<namespace>"- Root namespace applied to generated types.
- Example:
--namespace "PolyglotDataStudio.GraphQL.Generated"
--public- Generate
publictypes instead ofinternal; useful when packaging types into a library for shared use.
- Generate
--partial- Add
partialmodifiers to generated classes and interfaces
- Add
--force- Do not prompt before overwriting existing files in the output directory.
-?, --help- Show usage and exit.
Examples
Generate code from a single SDL file and write output to src/Generated:
PolyglotDataStudio.GraphQL.CLI -f my-schema.graphql -o src/Generated --namespace MyCompany.GraphQL --public
Show help:
PolyglotDataStudio.GraphQL.CLI -?
Generated Types & Naming Conventions
Both C# and GraphQL are case-sensitive languages, but C# is a bit more restrictive. In particular, C# does not allow members to have the same name as their containing type. To address this, the CLI applies the following naming conventions:
- Type names are always coerced to title case
- Fields and other members, are coerced to camel case, except enum values
If your schema contains field names that differ only by case of their first letter, you will receive a naming collision warning.
At this time, the CLI does not automatically resolve such collisions, and you will need to manually adjust your schema or update
the final generated code using the partial mechanism.
While camel-case member names are not common in C#, these are idiomatic for GraphQL, and results in the lowest probability of
collision. A side-effect is that member names may now collide with C# reserved keywords such as class, event and so on. In
these cases the CLI prepends the C# escape character @ to the member name to avoid compilation errors.
GraphQL Introspection Query
This is the query that will be executed against a GraphQL endpoint when using the --url option. The query may be
run in the GraphQL Playground or using any other tool, with the output saved into a JSON file that can also be processed
by this tool.
query IntrospectionQuery {
__schema {
queryType { name }
mutationType { name }
subscriptionType { name }
types { ...FullType }
directives { name description locations args { ...InputValue } }
}
}
fragment FullType on __Type {
kind name description
fields(includeDeprecated: true) { name description args { ...InputValue } type { ...TypeRef } isDeprecated deprecationReason }
inputFields { ...InputValue }
interfaces { ...TypeRef }
enumValues(includeDeprecated: true) { name description isDeprecated deprecationReason }
possibleTypes { ...TypeRef }
}
fragment InputValue on __InputValue {
name
description
type {
...TypeRef
}
defaultValue
}
fragment TypeRef on __Type {
kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name } } } } }
** Note that we do not yet support nested lists. The __Type fragment will support at most, a complexity of [Type!]!
GraphQL SDL (Schema Definition Language) documentation
Official resources:
- GraphQL SDL overview (learn): https://graphql.org/learn/schema/
- GraphQL specification (official): https://spec.graphql.org/
Both links were verified active as of November 28, 2025.
Contributing
Contributions are welcome. Please open issues for bugs or feature requests and submit pull requests for fixes. If present, follow the repository CONTRIBUTING.md for contribution process and code-style requirements.
License
Add your project license here (for example: MIT).
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
This package has no dependencies.
v1.2.1
✔️ Add parameter for emitting partial classes
v1.1.0
✔️ Re-organise generator to output query and response model for a given Type into a single file, rather than two separate files