HotChocolatier.Adnotations
1.0.0
dotnet add package HotChocolatier.Adnotations --version 1.0.0
NuGet\Install-Package HotChocolatier.Adnotations -Version 1.0.0
<PackageReference Include="HotChocolatier.Adnotations" Version="1.0.0" />
paket add HotChocolatier.Adnotations --version 1.0.0
#r "nuget: HotChocolatier.Adnotations, 1.0.0"
// Install HotChocolatier.Adnotations as a Cake Addin #addin nuget:?package=HotChocolatier.Adnotations&version=1.0.0 // Install HotChocolatier.Adnotations as a Cake Tool #tool nuget:?package=HotChocolatier.Adnotations&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 | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 292 | 11/10/2023 |