Skip to content

Commit

Permalink
Added Marten Test
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Jan 22, 2025
1 parent 015631f commit 3d98e23
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected async Task<IRequestExecutor> CreateSchemaAsync<TEntity, T>(
TEntity[] entities,
FilterConvention? convention = null,
bool withPaging = false,
Action<ISchemaBuilder>? configure = null)
Action<IRequestExecutorBuilder>? configure = null)
where TEntity : class
where T : FilterInputType<TEntity>
{
Expand All @@ -33,7 +33,10 @@ protected async Task<IRequestExecutor> CreateSchemaAsync<TEntity, T>(

var resolver = await BuildResolverAsync(store, entities);

var builder = SchemaBuilder.New()
var services = new ServiceCollection();
var builder = services.AddGraphQL();

builder
.AddMartenFiltering()
.AddQueryType(
c =>
Expand All @@ -54,13 +57,7 @@ protected async Task<IRequestExecutor> CreateSchemaAsync<TEntity, T>(

configure?.Invoke(builder);

var schema = builder.Create();

return await new ServiceCollection()
.Configure<RequestExecutorSetup>(
Schema.DefaultName,
o => o.Schema = schema)
.AddGraphQL()
builder
.UseRequest(
next => async context =>
{
Expand All @@ -76,8 +73,9 @@ protected async Task<IRequestExecutor> CreateSchemaAsync<TEntity, T>(
})
.ModifyPagingOptions(o => o.IncludeTotalCount = true)
.ModifyRequestOptions(x => x.IncludeExceptionDetails = true)
.UseDefaultPipeline()
.Services
.UseDefaultPipeline();

return await services
.BuildServiceProvider()
.GetRequiredService<IRequestExecutorResolver>()
.GetRequestExecutorAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -63,7 +65,7 @@ await Snapshot
.MatchAsync();
}

private static void Configure(ISchemaBuilder builder)
private static void Configure(IRequestExecutorBuilder builder)
=> builder
.AddObjectType<InterfaceImpl1>(x => x.Implements<InterfaceType<Test>>())
.AddObjectType<InterfaceImpl2>(x => x.Implements<InterfaceType<Test>>())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Concurrent;
using HotChocolate.Data.Filters;
using HotChocolate.Execution;
using HotChocolate.Execution.Configuration;

namespace HotChocolate.Data;

Expand All @@ -11,7 +12,7 @@ public class SchemaCache : FilterVisitorTestBase
public async Task<IRequestExecutor> CreateSchemaAsync<T, TType>(
T[] entities,
bool withPaging = false,
Action<ISchemaBuilder>? configure = null)
Action<IRequestExecutorBuilder>? configure = null)
where T : class
where TType : FilterInputType<T>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,105 +1,12 @@
---------------
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": {
"nodes": [
{
"bar": true
}
]
],
"totalCount": 1
}
}
}
---------------

0 comments on commit 3d98e23

Please sign in to comment.