Documentation: https://graphql-aspnet.github.io
Targets: netstandard2.0, net6.0
GraphQL ASP.NET is a fully featured graphql library that utilizes a controller/action programming model familiar to ASP.NET MVC developers. Instead of focusing on schemas and mapping resolvers, the focus on controllers and models. GraphQL ASP.NET will automatically generate the schema to match your code.
Recent Builds | |
---|---|
Development | |
Master |
This Controller
// BakeryController.cs
[GraphRoute("groceryStore/bakery")]
public class BakeryController : GraphController
{
// Automatic "scoped" dependency injection
public BakeryController(IPastryService pastryService, IBreadService breadService)
{/* ... */}
[Query("pastries/search")]
public IEnumerable<IPastry> SearchPastries(string nameLike, int maxResults = 50)
{/* ... */}
[Query("pastries/recipe")]
public Recipe RetrieveRecipe(int id)
{/* ... */}
[Query("breadCounter/orders")]
public IEnumerable<BreadOrder> FindOrders(int customerId)
{/* ... */}
}
This GraphQL Query
query SearchGroceryStore($pastryName: String!) {
groceryStore {
bakery {
pastries {
search(nameLike: $pastryName) {
name
type
}
recipe(id: 15) {
name
ingredients {
name
}
}
}
breadCounter {
orders(id: 36) {
id
items {
id
quantity
}
}
}
}
}
}
> Install-Package GraphQL.AspNet -AllowPrereleaseVersions
*This library is still in beta
// Startup.cs
public void ConfigureServices(IServiceCollection services)
{
// other code and configuration options
// omitted for brevity
services.AddGraphQL();
}
public void Configure(IApplicationBuilder appBuilder)
{
// other code omitted for brevity
appBuilder.UseGraphQL();
}
GraphQL ASP.NET supports web-socket based subscriptions using the Apollo client messaging protocol out of the box. Subscription support can be easily extended to multi-server environments and even other messaging protocols.