Documentation: https://graphql-aspnet.github.io
Targets: netstandard2.0, net6.0, net7.0, net8.0
GraphQL ASP.NET is a fully featured graphql library that utilizes a controller/action programming model familiar to ASP.NET developers. Instead of focusing on schemas and resolvers, the focus on controllers and model objects. This library will automatically generate the schema to match your code.
✅ Controller-Based Programming Model similar to ASP.NET
✅ No Boilerplate Code
✏️ Write This Controller
// BakeryController.cs
[GraphRoute("groceryStore/bakery")]
public class BakeryController : GraphController
{
[Query("pastries/search")]
public IEnumerable<IPastry> SearchPastries(string nameLike)
{/* ... */}
[Query("pastries/recipe")]
public Recipe RetrieveRecipe(int id)
{/* ... */}
[Query("breadCounter/orders")]
public IEnumerable<BreadOrder> FindOrders(int customerId)
{/* ... */}
}
query {
groceryStore {
bakery {
pastries {
search(nameLike: "donut") {
name
type
}
recipe(id: 15) {
name
ingredients {
name
}
}
}
breadCounter {
orders(id: 36) {
id
items {
id
quantity
}
}
}
}
}
}
# Package Manager Console
> Install-Package GraphQL.AspNet
# cli
> dotnet add package GraphQL.AspNet
// Program.cs
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddGraphQL();
var app = builder.Build();
// Configure the HTTP request pipeline.
app.UseGraphQL();
app.Run();
GraphQL ASP.NET supports web-socket based subscriptions out of the box. Subscription support can be extended to multi-server environments and even other messaging protocols.