graphql-aspnet / graphql-aspnet

A GraphQL library for ASP.NET developers. This repo represents the library's core source code.

Home Page:https://graphql-aspnet.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GraphQL ASP.NET

Targets: netstandard2.0, net6.0, net7.0, net8.0

CI-CD

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)
    {/* ... */}
}

▶️ Execute This Query

query {
  groceryStore {
    bakery {
      pastries {
        search(nameLike: "donut") {
          name
          type
        }
        recipe(id: 15) {
          name
          ingredients {
            name
          }
        }
      }
      breadCounter {
        orders(id: 36) {
          id
          items {
            id
            quantity
          }
        }
      }
    }
  }
}

📦 Add the Package from Nuget:

# Package Manager Console
> Install-Package GraphQL.AspNet

# cli
> dotnet add package GraphQL.AspNet

📐 Register GraphQL with your Application:

// 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();

Subscriptions

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.

About

A GraphQL library for ASP.NET developers. This repo represents the library's core source code.

https://graphql-aspnet.github.io

License:MIT License


Languages

Language:C# 99.9%Language:PowerShell 0.1%Language:HTML 0.0%