GraphQL.EntityFrameworkCore.DynamicLinq
1.0.3
dotnet add package GraphQL.EntityFrameworkCore.DynamicLinq --version 1.0.3
NuGet\Install-Package GraphQL.EntityFrameworkCore.DynamicLinq -Version 1.0.3
<PackageReference Include="GraphQL.EntityFrameworkCore.DynamicLinq" Version="1.0.3" />
<PackageVersion Include="GraphQL.EntityFrameworkCore.DynamicLinq" Version="1.0.3" />
<PackageReference Include="GraphQL.EntityFrameworkCore.DynamicLinq" />
paket add GraphQL.EntityFrameworkCore.DynamicLinq --version 1.0.3
#r "nuget: GraphQL.EntityFrameworkCore.DynamicLinq, 1.0.3"
#addin nuget:?package=GraphQL.EntityFrameworkCore.DynamicLinq&version=1.0.3
#tool nuget:?package=GraphQL.EntityFrameworkCore.DynamicLinq&version=1.0.3
GraphQL.EntityFrameworkCore.DynamicLinq
Add EntityFramework Core Dynamic IQueryable support to GraphQL.
How To
With this project you can easily expose all properties from the EF Entities as searchable fields on the GraphQL query.
Entity Type
public class Room
{
[Key]
public int Id { get; set; }
public int Number { get; set; }
public string Name { get; set; }
public bool AllowedSmoking { get; set; }
public RoomStatus Status { get; set; }
}
GraphQL Type
public class RoomType : ObjectGraphType<Room>
{
public RoomType()
{
Field(x => x.Id);
Field(x => x.Name);
Field(x => x.Number);
Field(x => x.AllowedSmoking);
Field<RoomStatusType>(nameof(RoomModel.Status));
}
}
Execute the Query
Filter on allowedSmoking
query {
rooms (allowedSmoking: false) {
name
number
allowedSmoking
status
}
}
OrderBy name
It's also possible to add support for an OrderBy field, just add the .SupportOrderBy();
in the code.
query {
rooms (orderBy: "name desc") {
name
number
status
}
}
Paging
It's also possible to add support for Paging, just add the .SupportPaging();
in the code.
query {
roomsWithPaging (page: 1, pageSize: 2) {
id
name
number
status
}
}
How to use
Add the required dependency injections
public void ConfigureServices(IServiceCollection services)
{
+ services.Configure<QueryArgumentInfoListBuilderOptions>(Configuration.GetSection("QueryArgumentInfoListBuilderOptions"));
+ services.AddGraphQLEntityFrameworkCoreDynamicLinq();
}
Update your GraphQL Query
public class MyHotelQuery : ObjectGraphType
{
public MyHotelQuery(MyHotelRepository myHotelRepository, IQueryArgumentInfoListBuilder builder)
{
1 var roomQueryArgumentList = builder.Build<RoomType>()
2 .Exclude("Id")
3 .SupportOrderBy()
4 .SupportPaging();
Field<ListGraphType<RoomType>>("rooms",
5 arguments: roomQueryArgumentList.ToQueryArguments(),
resolve: context => myHotelRepository.GetRoomsQuery()
6 .ApplyQueryArguments(roomQueryArgumentList, context)
.ToList()
);
}
}
- Use the
IQueryArgumentInfoListBuilder
to build all possible arguments based on the fields from the GraphQL type (e.g.RoomType
) - Optionally include/exclude some properties which should not be searchable (this can also be a wildcard like
*Id
) - Optionally add support for OrderBy (argument-name will be
OrderBy
) - Optionally add support for Paging (argument-names will be
Page
andPageSize
) - Call the
.ToQueryArguments()
to create a newQueryArguments
object. - Call the
ApplyQueryArguments
extension method to apply the search criteria (optionally the OrderBy and Paging)
Sponsors
Entity Framework Extensions and Dapper Plus are major sponsors and proud to contribute to the development of GraphQL.EntityFrameworkCore.DynamicLinq.
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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.3 is compatible. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net451 is compatible. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Universal Windows Platform | uap was computed. uap10.0 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.5.1
- GraphQL (>= 2.4.0)
- Microsoft.EntityFrameworkCore.DynamicLinq (>= 1.1.6)
-
.NETStandard 1.3
- GraphQL (>= 2.4.0)
- Microsoft.EntityFrameworkCore.DynamicLinq (>= 1.1.6)
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 2.0
- GraphQL (>= 2.4.0)
- Microsoft.EntityFrameworkCore.DynamicLinq (>= 1.1.6)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
See CHANGELOG.md