From 3d98e23a88bcfaf08a3810413d93ea14a34cda7c Mon Sep 17 00:00:00 2001 From: Michael Staib Date: Wed, 22 Jan 2025 15:20:28 +0100 Subject: [PATCH] Added Marten Test --- .../FilterVisitorTestBase.cs | 20 ++-- .../FilteringAndPaging.cs | 5 +- .../QueryableFilterVisitorInterfacesTests.cs | 4 +- .../Data.Marten.Filters.Tests/SchemaCache.cs | 3 +- ...eringAndPaging.Paging_With_TotalCount.snap | 97 +------------------ 5 files changed, 18 insertions(+), 111 deletions(-) diff --git a/src/HotChocolate/Marten/test/Data.Marten.Filters.Tests/FilterVisitorTestBase.cs b/src/HotChocolate/Marten/test/Data.Marten.Filters.Tests/FilterVisitorTestBase.cs index 3c3ebb9285f..9cff3ff20ab 100644 --- a/src/HotChocolate/Marten/test/Data.Marten.Filters.Tests/FilterVisitorTestBase.cs +++ b/src/HotChocolate/Marten/test/Data.Marten.Filters.Tests/FilterVisitorTestBase.cs @@ -23,7 +23,7 @@ protected async Task CreateSchemaAsync( TEntity[] entities, FilterConvention? convention = null, bool withPaging = false, - Action? configure = null) + Action? configure = null) where TEntity : class where T : FilterInputType { @@ -33,7 +33,10 @@ protected async Task CreateSchemaAsync( var resolver = await BuildResolverAsync(store, entities); - var builder = SchemaBuilder.New() + var services = new ServiceCollection(); + var builder = services.AddGraphQL(); + + builder .AddMartenFiltering() .AddQueryType( c => @@ -54,13 +57,7 @@ protected async Task CreateSchemaAsync( configure?.Invoke(builder); - var schema = builder.Create(); - - return await new ServiceCollection() - .Configure( - Schema.DefaultName, - o => o.Schema = schema) - .AddGraphQL() + builder .UseRequest( next => async context => { @@ -76,8 +73,9 @@ protected async Task CreateSchemaAsync( }) .ModifyPagingOptions(o => o.IncludeTotalCount = true) .ModifyRequestOptions(x => x.IncludeExceptionDetails = true) - .UseDefaultPipeline() - .Services + .UseDefaultPipeline(); + + return await services .BuildServiceProvider() .GetRequiredService() .GetRequestExecutorAsync(); diff --git a/src/HotChocolate/Marten/test/Data.Marten.Filters.Tests/FilteringAndPaging.cs b/src/HotChocolate/Marten/test/Data.Marten.Filters.Tests/FilteringAndPaging.cs index a9ab915b63c..72165403c46 100644 --- a/src/HotChocolate/Marten/test/Data.Marten.Filters.Tests/FilteringAndPaging.cs +++ b/src/HotChocolate/Marten/test/Data.Marten.Filters.Tests/FilteringAndPaging.cs @@ -42,14 +42,13 @@ public async Task Paging_With_TotalCount() // act var res1 = await tester.ExecuteAsync( OperationRequestBuilder.New() - .SetDocument("{ root(where: { bar: { eq: true } }) { nodes { bar } } }") + .SetDocument("{ root(where: { bar: { eq: true } }) { nodes { bar } totalCount } }") .Build()); // assert await Snapshot .Create() - .Add(tester.Schema.ToString()) - .Add(res1, "true") + .Add(res1, "Result with TotalCount") .MatchAsync(); } diff --git a/src/HotChocolate/Marten/test/Data.Marten.Filters.Tests/QueryableFilterVisitorInterfacesTests.cs b/src/HotChocolate/Marten/test/Data.Marten.Filters.Tests/QueryableFilterVisitorInterfacesTests.cs index 62e8c8a1ff5..e5018a7f6ae 100644 --- a/src/HotChocolate/Marten/test/Data.Marten.Filters.Tests/QueryableFilterVisitorInterfacesTests.cs +++ b/src/HotChocolate/Marten/test/Data.Marten.Filters.Tests/QueryableFilterVisitorInterfacesTests.cs @@ -1,7 +1,9 @@ using System.ComponentModel.DataAnnotations; using HotChocolate.Data.Filters; using HotChocolate.Execution; +using HotChocolate.Execution.Configuration; using HotChocolate.Types; +using Microsoft.Extensions.DependencyInjection; namespace HotChocolate.Data; @@ -63,7 +65,7 @@ await Snapshot .MatchAsync(); } - private static void Configure(ISchemaBuilder builder) + private static void Configure(IRequestExecutorBuilder builder) => builder .AddObjectType(x => x.Implements>()) .AddObjectType(x => x.Implements>()) diff --git a/src/HotChocolate/Marten/test/Data.Marten.Filters.Tests/SchemaCache.cs b/src/HotChocolate/Marten/test/Data.Marten.Filters.Tests/SchemaCache.cs index db3b42b5275..f981aee67c6 100644 --- a/src/HotChocolate/Marten/test/Data.Marten.Filters.Tests/SchemaCache.cs +++ b/src/HotChocolate/Marten/test/Data.Marten.Filters.Tests/SchemaCache.cs @@ -1,6 +1,7 @@ using System.Collections.Concurrent; using HotChocolate.Data.Filters; using HotChocolate.Execution; +using HotChocolate.Execution.Configuration; namespace HotChocolate.Data; @@ -11,7 +12,7 @@ public class SchemaCache : FilterVisitorTestBase public async Task CreateSchemaAsync( T[] entities, bool withPaging = false, - Action? configure = null) + Action? configure = null) where T : class where TType : FilterInputType { diff --git a/src/HotChocolate/Marten/test/Data.Marten.Filters.Tests/__snapshots__/FilteringAndPaging.Paging_With_TotalCount.snap b/src/HotChocolate/Marten/test/Data.Marten.Filters.Tests/__snapshots__/FilteringAndPaging.Paging_With_TotalCount.snap index f28d6be19ce..b3ba2d8a2ef 100644 --- a/src/HotChocolate/Marten/test/Data.Marten.Filters.Tests/__snapshots__/FilteringAndPaging.Paging_With_TotalCount.snap +++ b/src/HotChocolate/Marten/test/Data.Marten.Filters.Tests/__snapshots__/FilteringAndPaging.Paging_With_TotalCount.snap @@ -1,96 +1,3 @@ ---------------- -schema { - query: Query -} - -type Foo { - id: Int! - bar: Boolean! -} - -"Information about pagination in a connection." -type PageInfo { - "Indicates whether more edges exist following the set defined by the clients arguments." - hasNextPage: Boolean! - "Indicates whether more edges exist prior the set defined by the clients arguments." - hasPreviousPage: Boolean! - "When paginating backwards, the cursor to continue." - startCursor: String - "When paginating forwards, the cursor to continue." - endCursor: String -} - -type Query { - root("Returns the first _n_ elements from the list." first: Int "Returns the elements in the list that come after the specified cursor." after: String "Returns the last _n_ elements from the list." last: Int "Returns the elements in the list that come before the specified cursor." before: String where: FooFilterInput): RootConnection - rootExecutable("Returns the first _n_ elements from the list." first: Int "Returns the elements in the list that come after the specified cursor." after: String "Returns the last _n_ elements from the list." last: Int "Returns the elements in the list that come before the specified cursor." before: String where: FooFilterInput): RootExecutableConnection -} - -"A connection to a list of items." -type RootConnection { - "Information to aid in pagination." - pageInfo: PageInfo! - "A list of edges." - edges: [RootEdge!] - "A flattened list of the nodes." - nodes: [Foo] -} - -"An edge in a connection." -type RootEdge { - "A cursor for use in pagination." - cursor: String! - "The item at the end of the edge." - node: Foo -} - -"A connection to a list of items." -type RootExecutableConnection { - "Information to aid in pagination." - pageInfo: PageInfo! - "A list of edges." - edges: [RootExecutableEdge!] - "A flattened list of the nodes." - nodes: [Foo] -} - -"An edge in a connection." -type RootExecutableEdge { - "A cursor for use in pagination." - cursor: String! - "The item at the end of the edge." - node: Foo -} - -input BooleanOperationFilterInput { - eq: Boolean - neq: Boolean -} - -input FooFilterInput { - and: [FooFilterInput!] - or: [FooFilterInput!] - id: IntOperationFilterInput - bar: BooleanOperationFilterInput -} - -input IntOperationFilterInput { - eq: Int - neq: Int - in: [Int] - nin: [Int] - gt: Int - ngt: Int - gte: Int - ngte: Int - lt: Int - nlt: Int - lte: Int - nlte: Int -} ---------------- - -true ---------------- { "data": { "root": { @@ -98,8 +5,8 @@ true { "bar": true } - ] + ], + "totalCount": 1 } } } ----------------