Skip to content

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

License

Notifications You must be signed in to change notification settings

jonownbey-nuix/graphql-aspnet

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GraphQL ASP.NET (beta)

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 Develop Branch Build Status
Master Master Branch Build Status

Example Usage:

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
          }
        }
      }
    }
  }
}

Add the Package from Nuget*:

> Install-Package GraphQL.AspNet -AllowPrereleaseVersions

*This library is still in beta

Register GraphQL with your Application:

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

Subscriptions

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.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 99.8%
  • PowerShell 0.2%