graphql_entityframeworkcore_dynamiclinq - GraphQL.EntityFrameworkCore.DynamicLinq 1.0.2-ci-13729

GraphQL EntityFrameworkCore Dynamic Linq extensions to query GraphQL types dynamically

PM> Install-Package GraphQL.EntityFrameworkCore.DynamicLinq -Version 1.0.2-ci-13729 -Source https://www.myget.org/F/graphql_entityframeworkcore_dynamiclinq/api/v3/index.json

Copy to clipboard

> nuget.exe install GraphQL.EntityFrameworkCore.DynamicLinq -Version 1.0.2-ci-13729 -Source https://www.myget.org/F/graphql_entityframeworkcore_dynamiclinq/api/v3/index.json

Copy to clipboard

> dotnet add package GraphQL.EntityFrameworkCore.DynamicLinq --version 1.0.2-ci-13729 --source https://www.myget.org/F/graphql_entityframeworkcore_dynamiclinq/api/v3/index.json

Copy to clipboard
<PackageReference Include="GraphQL.EntityFrameworkCore.DynamicLinq" Version="1.0.2-ci-13729" />
Copy to clipboard
source https://www.myget.org/F/graphql_entityframeworkcore_dynamiclinq/api/v3/index.json

nuget GraphQL.EntityFrameworkCore.DynamicLinq  ~> 1.0.2-ci-13729
Copy to clipboard

> choco install GraphQL.EntityFrameworkCore.DynamicLinq --version 1.0.2-ci-13729 --source https://www.myget.org/F/graphql_entityframeworkcore_dynamiclinq/api/v2

Copy to clipboard
Import-Module PowerShellGet
Register-PSRepository -Name "graphql_entityframeworkcore_dynamiclinq" -SourceLocation "https://www.myget.org/F/graphql_entityframeworkcore_dynamiclinq/api/v2"
Install-Module -Name "GraphQL.EntityFrameworkCore.DynamicLinq" -RequiredVersion "1.0.2-ci-13729" -Repository "graphql_entityframeworkcore_dynamiclinq" -AllowPreRelease
Copy to clipboard

GraphQL.EntityFrameworkCore.DynamicLinq

Add EntityFramework Core Dynamic IQueryable support to GraphQL.

Info

  Build Azure Build Status
  Codecov codecov
  NuGet NuGet: GraphQL.EntityFrameworkCore.DynamicLinq
  MyGet (preview) MyGet: GraphQL.EntityFrameworkCore.DynamicLinq

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()
        );
    }
}
  1. Use the IQueryArgumentInfoListBuilder to build all possible arguments based on the fields from the GraphQL type (e.g. RoomType)
  2. Optionally include/exclude some properties which should not be searchable (this can also be a wildcard like *Id)
  3. Optionally add support for OrderBy (argument-name will be OrderBy)
  4. Optionally add support for Paging (argument-names will be Page and PageSize)
  5. Call the .ToQueryArguments() to create a new QueryArguments object.
  6. Call the ApplyQueryArguments extension method to apply the search criteria (optionally the OrderBy and Paging)

Example

See example projec: examples/MyHotel for more details.

References

See CHANGELOG.md

  • .NETFramework 4.5.1
    • GraphQL (>= 2.4.0)
    • Microsoft.EntityFrameworkCore.DynamicLinq (>= 1.0.19)
  • .NETStandard 1.3
    • GraphQL (>= 2.4.0)
    • Microsoft.EntityFrameworkCore.DynamicLinq (>= 1.0.19)
    • NETStandard.Library (>= 1.6.1)
  • .NETStandard 2.0
    • GraphQL (>= 2.4.0)
    • Microsoft.EntityFrameworkCore.DynamicLinq (>= 1.0.19)
  • .NETFramework 4.5.1: 4.5.1.0
  • .NETStandard 1.3: 1.3.0.0
  • .NETStandard 2.0: 2.0.0.0

Owners

Stef

Authors

Stef Heyenrath

Project URL

https://github.com/StefH/GraphQL.EntityFrameworkCore.DynamicLinq

License

Apache-2.0

Tags

GraphQL ef efcore entityframework core entityframeworkcore dynamiclinq dynamic linq

Info

185 total downloads
3 downloads for version 1.0.2-ci-13729
Download (37.32 KB)
Found on the current feed only

Package history

Version Size Last updated Downloads Mirrored?
1.0.2-ci-14869 37.32 KB Wed, 31 Mar 2021 06:01:51 GMT 3
1.0.2-ci-14867 37.33 KB Wed, 31 Mar 2021 00:56:38 GMT 3
1.0.2-ci-14782 37.32 KB Wed, 10 Mar 2021 04:27:19 GMT 3
1.0.2-ci-13747 37.33 KB Fri, 11 Sep 2020 02:40:45 GMT 3
1.0.2-ci-13745 37.32 KB Thu, 10 Sep 2020 10:19:35 GMT 3
1.0.2-ci-13731 37.32 KB Fri, 04 Sep 2020 22:46:06 GMT 3
1.0.2-ci-13729 37.32 KB Fri, 04 Sep 2020 17:33:35 GMT 3
1.0.2-ci-13726 37.32 KB Fri, 04 Sep 2020 15:22:40 GMT 3
1.0.2-ci-13656 37.16 KB Sat, 01 Aug 2020 10:33:24 GMT 3
1.0.2-ci-13648 37.16 KB Fri, 31 Jul 2020 13:29:32 GMT 3
1.0.2-ci-13623 37.17 KB Sun, 19 Jul 2020 07:24:04 GMT 3
1.0.2-ci-13619 37.16 KB Fri, 17 Jul 2020 23:53:18 GMT 3
1.0.2-ci-13598 37.17 KB Wed, 08 Jul 2020 02:35:18 GMT 3
1.0.2-ci-13596 37.16 KB Tue, 07 Jul 2020 22:19:39 GMT 3
1.0.2-ci-13450 37.16 KB Sun, 07 Jun 2020 17:46:03 GMT 3
1.0.2-ci-13448 37.16 KB Sun, 07 Jun 2020 03:43:45 GMT 3
1.0.2-ci-13262 37.16 KB Thu, 30 Apr 2020 14:11:31 GMT 2
1.0.2-ci-13260 37.16 KB Thu, 30 Apr 2020 10:54:51 GMT 3
1.0.2-ci-13181 37.16 KB Thu, 16 Apr 2020 23:21:25 GMT 3
1.0.2-ci-13175 37.16 KB Thu, 16 Apr 2020 19:38:42 GMT 3
1.0.2-ci-13126 37.16 KB Sun, 05 Apr 2020 17:45:25 GMT 3
1.0.2-ci-13118 37.16 KB Sat, 04 Apr 2020 22:36:06 GMT 3
1.0.2-ci-12497 39.68 KB Sat, 18 Jan 2020 17:59:42 GMT 3
1.0.2-ci-12493 39.02 KB Sat, 18 Jan 2020 10:33:19 GMT 2
1.0.2-ci-12491 37.16 KB Fri, 17 Jan 2020 06:03:16 GMT 3
1.0.2-ci-12490 37.15 KB Thu, 16 Jan 2020 17:43:22 GMT 4
1.0.2-ci-12477 37.16 KB Wed, 15 Jan 2020 19:45:06 GMT 3
1.0.1-ci-12462 35.64 KB Tue, 14 Jan 2020 13:09:52 GMT 3
1.0.1-ci-12461 35.65 KB Tue, 14 Jan 2020 13:09:48 GMT 3
1.0.1-ci-12460 35.65 KB Tue, 14 Jan 2020 13:09:48 GMT 2
1.0.1-ci-12459 35.65 KB Tue, 14 Jan 2020 13:09:48 GMT 3
1.0.1-ci-12457 35.65 KB Tue, 14 Jan 2020 13:09:59 GMT 3
1.0.1-ci-12456 35.65 KB Tue, 14 Jan 2020 11:09:25 GMT 3
1.0.1-ci-12454 35.65 KB Tue, 14 Jan 2020 08:17:56 GMT 3
1.0.1-ci-12447 35.65 KB Sun, 12 Jan 2020 11:54:36 GMT 2
1.0.1-ci-12446 35.65 KB Sun, 12 Jan 2020 09:30:45 GMT 3
1.0.1-ci-12445 35.65 KB Sat, 11 Jan 2020 09:33:56 GMT 2
1.0.1-ci-12444 35.66 KB Sat, 11 Jan 2020 08:38:19 GMT 3
1.0.1-ci-12019 35.67 KB Sat, 12 Oct 2019 16:32:48 GMT 3
1.0.0-ci-11875 35.74 KB Sat, 07 Sep 2019 14:52:59 GMT 2
0.0.2-ci-11723 35.76 KB Mon, 19 Aug 2019 17:13:43 GMT 3
0.0.1-ci-11722 35.75 KB Mon, 19 Aug 2019 17:10:26 GMT 3
0.0.1-ci-11705 35.75 KB Mon, 19 Aug 2019 06:03:32 GMT 3
0.0.1-ci-11704 35.75 KB Mon, 19 Aug 2019 05:57:08 GMT 3
0.0.1-ci-11703 35.75 KB Sun, 18 Aug 2019 15:28:05 GMT 3
0.0.1-ci-11640 35.8 KB Thu, 15 Aug 2019 20:27:12 GMT 3
0.0.1-ci-11634 36.38 KB Thu, 15 Aug 2019 18:54:13 GMT 3
0.0.1-ci-11630 36.77 KB Wed, 14 Aug 2019 20:50:50 GMT 3
0.0.1-ci-11628 36.78 KB Wed, 14 Aug 2019 20:50:21 GMT 3
0.0.1-ci-11626 36.78 KB Wed, 14 Aug 2019 20:47:51 GMT 3
0.0.1-ci-11624 36.78 KB Wed, 14 Aug 2019 20:44:02 GMT 2
0.0.1-ci-11618 33.25 KB Wed, 14 Aug 2019 08:55:36 GMT 3
0.0.1-ci-11616 33.25 KB Wed, 14 Aug 2019 07:49:32 GMT 3
0.0.1-ci-11614 33.25 KB Wed, 14 Aug 2019 07:17:54 GMT 3
0.0.1-ci-11612 31.9 KB Tue, 13 Aug 2019 17:45:19 GMT 3
0.0.1-ci-11610 31.89 KB Tue, 13 Aug 2019 17:22:20 GMT 3
0.0.1-ci-11606 31.9 KB Tue, 13 Aug 2019 07:41:52 GMT 3
0.0.1-ci-11604 30.18 KB Mon, 12 Aug 2019 19:18:32 GMT 3
0.0.1-ci-11603 29.86 KB Mon, 12 Aug 2019 16:28:55 GMT 2
0.0.1-ci-11602 28.61 KB Mon, 12 Aug 2019 07:25:02 GMT 2
0.0.1-ci-11589 28.61 KB Sun, 11 Aug 2019 14:22:20 GMT 2
0.0.1-ci-11587 28.61 KB Sun, 11 Aug 2019 13:58:26 GMT 3
0.0.1-ci-11585 28.61 KB Sun, 11 Aug 2019 13:51:41 GMT 2
0.0.1-ci-11583 28.61 KB Sun, 11 Aug 2019 13:46:42 GMT 3
0.0.1-ci-11581 28.61 KB Sun, 11 Aug 2019 13:38:37 GMT 3