A tool to build GraphQL query from a C# model.
See complete documentation here
See sample here
> dotnet add package GraphQL.Query.Builder
// Create the query
var query = new Query<Human>("humans") // set the name of the query
.AddArguments(new { id = "uE78f5hq" }) // add query arguments
.AddField(h => h.FirstName) // add firstName field
.AddField(h => h.LastName) // add lastName field
.AddField( // add a sub-object field
h => h.HomePlanet, // set the name of the field
sq => sq /// build the sub-query
.AddField(p => p.Name)
)
.AddField<human>( // add a sub-list field
h => h.Friends,
sq => sq
.AddField(f => f.FirstName)
.AddField(f => f.LastName)
);
// This corresponds to:
// humans(id: "uE78f5hq") {
// FirstName
// LastName
// HomePlanet {
// Name
// }
// Friends {
// FirstName
// LastName
// }
// }
Console.WriteLine("{" + query.Build() + "}");
// Output:
// {humans(id:"uE78f5hq"){FirstName LastName HomePlanet{Name}Friends FirstName LastName}}
- Dawn.Guard (>= 1.12.0)
- Newtonsoft.Json (>= 11.0.1)