A tool to build GraphQL query from a C# model.
Total Downloads
3.1M
3,115,237
Published
Aug 21, 2026
1mo ago
Get Started
dotnet add package GraphQL.Query.Builder --version 3.0.0
| Product | Versions |
|---|---|
| .NET Standard |
README
GraphQL Query Builder .NET

A tool to build GraphQL query from a C# model.
See complete documentation here
See sample here
Upgrading from v2.x? See the migration guide.
Install
dotnet add package GraphQL.Query.Builder
Usage
Basic Query
IGraphQLField<Human> field = new GraphQLField<Human>("humans")
.AddArguments(new { id = "uE78f5hq" })
.AddField(h => h.FirstName)
.AddField(h => h.LastName)
.AddField(
h => h.HomePlanet,
sq => sq.AddField(p => p.Name)
)
.AddField<Human>(
h => h.Friends,
sq => sq
.AddField(f => f.FirstName)
.AddField(f => f.LastName)
);
string query = new GraphQLOperation(OperationType.Query)
.AddQuery(field)
.Build();
// Output:
// query{humans(id:"uE78f5hq"){FirstName LastName HomePlanet{Name} Friends{FirstName LastName}}}
Variables
var idVar = new GraphQLVariable("id", "ID!");
string query = new GraphQLOperation(OperationType.Query, "GetHuman")
.AddVariable(idVar)
.AddQuery(
new GraphQLField<Human>("human")
.AddArgument("id", idVar.Reference())
.AddField(h => h.FirstName)
.AddField(h => h.LastName))
.Build();
// Output:
// query GetHuman($id:ID!){human(id:$id){FirstName LastName}}
Directives
var showFriends = new GraphQLVariable("showFriends", "Boolean!");
new GraphQLField<Human>("human")
.AddField(h => h.FirstName)
.AddField<Human>(
h => h.Friends,
sq => sq.AddField(f => f.FirstName),
GraphQLDirective.Include(showFriends.Reference()));
// Field output:
// human{FirstName Friends @include(if:$showFriends){FirstName}}
Fragments
var nameFields = new GraphQLFragment("NameFields", "Human",
new GraphQLField<Human>("Human")
.AddField(h => h.FirstName)
.AddField(h => h.LastName));
string query = new GraphQLOperation(OperationType.Query)
.AddQuery(
new GraphQLField<Human>("hero").AddFragment(nameFields))
.AddQuery(
new GraphQLField<Human>("villain").AddFragment(nameFields))
.AddFragment(nameFields)
.Build();
// Output:
// query{hero{...NameFields} villain{...NameFields}} fragment NameFields on Human{FirstName LastName}
Multiple Root Fields
string query = new GraphQLOperation(OperationType.Query)
.AddQuery(new GraphQLField<Human>("hero").AddField(h => h.FirstName))
.AddQuery(new GraphQLField<Droid>("droid").AddArgument("id", 1).AddField(d => d.Name))
.Build();
// Output:
// query{hero{FirstName} droid(id:1){Name}}
Mutations
string mutation = new GraphQLOperation(OperationType.Mutation, "CreateHuman")
.AddQuery(
new GraphQLField<Human>("createHuman")
.AddArgument("name", "Luke")
.AddField(h => h.Id)
.AddField(h => h.FirstName))
.Build();
// Output:
// mutation CreateHuman{createHuman(name:"Luke"){Id FirstName}}
Options
// CamelCase field names
var options = new QueryOptions
{
Formatter = CamelCasePropertyNameFormatter.Format
};
new GraphQLField<Human>("human", options)
.AddField(h => h.FirstName);
// Field output: human{firstName}
// Control null property handling
var ignoreNullOptions = new QueryOptions
{
DefaultIgnoreCondition = QueryIgnoreCondition.WhenWritingNull
};
Downloads by Version
Similar & Alternative Packages
Hand-picked matching NuGet libraries based on tags & ecosystem
Depended On By
Find packages that declare this package as a dependency. NuGet does not provide a reverse-dependency endpoint, so candidates are checked on demand.
Adoption Assessment
Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.
Compatibility metadata lists 1 target framework; confirm the exact target used by your application.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.