HotChocolatier.Tool 1.0.0

dotnet tool install --global HotChocolatier.Tool --version 1.0.0
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo
dotnet tool install --local HotChocolatier.Tool --version 1.0.0
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=HotChocolatier.Tool&version=1.0.0
nuke :add-package HotChocolatier.Tool --version 1.0.0

HotChocolatier

HotChocolate GraphQL Schema Generator for Entity Framework DbSets It enables you to create hassle-free GraphQL APIs without having to write Schema manually (for queries and subscriptions - i still recommend using rest for writes)

How it Works

It generates GraphQL Schema for Query and Subscription. Example use:

`-a E:\Projects\GameDesignStudio\src\Backend\GameDesignStudio.Data\bin\Debug\net7.0\GameDesignStudio.Data.dll -n GameDesignStudio.GraphQL.Schema

-o E:\Projects\GameDesignStudio\src\Backend\GameDesignStudio.GraphQL`

  • -a is a dll holding the DbContext class
  • -n is a target namespace of generated schema
  • -v is used to display verbose logs
  • -o defines output directory (of course it will create its' own Schema folder with subsequent Query and Subscription folders to organize each partial classes.

It automatically names partials based on DbSet name. So example output will look like:

// ... inside DbContext
 [GraphQlSubscription(Authorize = true),
 GraphQlList(UseSorting = true, UseFiltering = true, UseProjection = true, Authorize = true),
 GraphQlPagedList(UseSorting = true, UseFiltering = true, UseProjection = true, Authorize = true),
 GraphQlGetById(Authorize = true)]
    public DbSet<User> Users { get; set; }

In order to get the attributes you need the HotChocolatier.Adnotations package. It contains following attributes:

  • GraphQLSubscription (creates subscriptions with Added and Updated Event - you need to trigger them manually from other services - see (https://chillicream.com/docs/hotchocolate/v13/defining-a-schema/subscriptions)
  • GraphQLList (exposes raw IQueryable for projections, sorting etc - of course you can configure which one you want and which one you don't want)
  • GraphQlPagedList (uses offset paging)
  • GraphQLGetById (allows to get one item by integer id)

Output for Users DbSet will look like this (File Name: Query.Users.cs):

using Microsoft.EntityFrameworkCore;
using HotChocolate.Authorization;
namespace GameDesignStudio.GraphQL.Schema;

public partial class Query{
    
[Authorize, UseProjection, UseFiltering, UseSorting]
public IQueryable<GameDesignStudio.Data.Model.Auth.User> GetUsers([Service(ServiceKind.Synchronized)] GameDesignStudio.Data.Context.GameDesignStudioContext context)
 => context.Users;


[Authorize, UseOffsetPaging(DefaultPageSize = 50, IncludeTotalCount = true, MaxPageSize = 1000), UseProjection, UseFiltering, UseSorting]
public IQueryable<GameDesignStudio.Data.Model.Auth.User> GetUsersWithPaging([Service(ServiceKind.Synchronized)] GameDesignStudio.Data.Context.GameDesignStudioContext context)
 => context.Users;


public async ValueTask<GameDesignStudio.Data.Model.Auth.User?> GetUser([Service(ServiceKind.Synchronized)] GameDesignStudio.Data.Context.GameDesignStudioContext context, int id)
=> await context.Users.FirstOrDefaultAsync(x => x.Id == id);


}

I'M SOLD WHERE TO GET THIS

I will post here links for tool install and nuget package for adnotations soon

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last updated
1.0.0 237 11/10/2023