This library contains a bunch of methods to make my life as developer easier. Some common tasks have been abstracted away in reusable and composable sections.
The main reason to use this library are the following methods:
Slice()
- An extension method to theQuery
object (SqlKata) which applies cursor based pagination to the provided query.ToConnection()
- An extension method to theQuery
object which applies pagination (using theSlice
method) and returns aConnection
object.EntityLoader()
- An extension method on theIDataLoaderContextAccessor
to retrieve a single value via the data-loader based on a LINQ predicate. The loader will combine all similiar requests.EntityCollectionLoader()
- An extension method on theIDataLoaderContextAccessor
to retrieve multiple values based on a LINQ predicate. The loader will combine all similiar requests.- A more natural way to add authorization to queries. A detailed blog post explaining this functionality is available here.
new Query("Companies")
.Where("City", "Amsterdam")
.Slice(
after: "cursor",
first: 25);
Connection<Company>()
.Name("companies")
.ResolveAsync(async context => {
return await new Query("Companies")
.Where("City", "Amsterdam")
.ToConnection<Company, object>(context);
});
Field<AircraftType, Aircraft>()
.Name("aircraft")
.ResolveAsync(async context =>
{
return await dataLoader.EntityLoader(
dbProvider.Get().Aircraft,
aircraft => aircraft.Id,
context.Source.AirfieldId);
});
List<Flight> flights = await dataLoader.EntityCollectionLoader(
dbProvider.Get().Flights,
flight => flight.AircraftId,
context.Source.Id)
You can copy some specific code over from this repository or you can install the whole package via NuGet.
Install-Package Boerman.GraphQL.Contrib
or
dotnet add package Boerman.GraphQL.Contrib
This library has quite a few dependencies. This comes from my own workflow where I start using Entity Framework, and use SqlKata for some specialized logic. Because Entity Framework acts as my base I also reuse the data models with SqlKata.
All of this functionality has been documented over the course of several blog posts: