Schemaless GraphQL query builder for .NET Core with fluent syntax. Zero dependencies.
dotnet add package NGql.Core
Library allows creation of Query
and Mutation
's.
Both have an implicit conversion to string
.
var query = new Query("PersonAndFilms")
.Select(new Query("person")
.Where("id", "cGVvcGxlOjE=")
.Select("name")
.Select(new Query("filmConnection")
.Select(new Query("films")
.Select("title")))
);
the output will be the following
query PersonAndFilms{
person(id:"cGVvcGxlOjE="){
name
filmConnection{
films{
title
}
}
}
}
var mutation = new Mutation("CreateUser")
.Select(new Query("createUser")
.Where("name", "Name")
.Where("password", "Password")
.Select("id", "name"))
.ToString();
the output will be the following
mutation CreateUser{
createUser(name:"Name", password:"Password"){
id
name
}
}
Variables allows to reuse existing queries and mutations instead of building them from start every time.
// define a variable
var variable = new Variable("$name", "String");
// pass as constructor parameter
var ctor = new Query("name", variables: variable);
// or as method variable
var fluent = new Query("name", variables: variable).Variable(variable););
the output will be the following
query name($name:String){
id
}