GraphQL ASP.NET .NET 6+
Write a Controller
// C# Controller
[GraphRoute("groceryStore/bakery")]
public class BakeryController : GraphController
{
[Query("pastries/search")]
public IEnumerable<IPastry> SearchPastries(string text)
{ /* ... */ }
[Query("pastries/recipe")]
public async Task<Recipe> RetrieveRecipe(int id)
{ /* ... */ }
[Query("breadCounter/orders")]
public IEnumerable<BreadOrder> FindOrders(int id)
{ /* ... */ }
}
Execute a Query
# GraphQL Query
query SearchGroceryStore($pastryName: String!) {
groceryStore {
bakery {
pastries {
search(text: $pastryName) {
name
type
}
recipe(id: 15) {
name
ingredients {
name
}
}
}
}
breadCounter {
orders(id:36) {
id
items {
id
quantity
}
}
}
}
}