Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,58 @@ await Snapshot
.MatchAsync(TestContext.Current.CancellationToken);
}

[Fact]
public async Task Sorting_Should_Apply_OrderBy_When_Query_Is_Projected()
Comment thread
michaelstaib marked this conversation as resolved.
Resolved
{
// arrange
var executor = await new ServiceCollection()
.AddGraphQL()
.AddQueryType<Query>()
.AddSorting()
.ModifyRequestOptions(o => o.IncludeExceptionDetails = true)
.BuildRequestExecutorAsync(cancellationToken: TestContext.Current.CancellationToken);

// act
var result = await executor.ExecuteAsync(
OperationRequestBuilder
.New()
.SetDocument(
"""
{
projectedWithExistingOrder(order: { someProperty: DESC }) {
someProperty
Comment on lines +108 to +110
}
}
""")
.Build(),
TestContext.Current.CancellationToken);

// assert
result.MatchInlineSnapshot(
"""
{
"data": {
"projectedWithExistingOrder": [
{
"someProperty": "b"
},
{
"someProperty": "a"
}
]
}
}
""");
}

public class Query
{
private static readonly Source[] s_source =
[
new() { SomeProperty = "a", CreateDate = new DateTime(2020, 1, 1) },
new() { SomeProperty = "b", CreateDate = new DateTime(2021, 1, 1) }
];

[UseSorting]
public IEnumerable<Foo> ShouldWork(IResolverContext context)
{
Expand All @@ -109,6 +159,15 @@ public IEnumerable<Foo> MissingMiddleware(IResolverContext context)
{
return s_fooEntities.Sort(context);
}

[UseSorting]
public IQueryable<Projection> ProjectedWithExistingOrder()
{
return s_source
.AsQueryable()
.OrderBy(x => x.CreateDate)
.Select(x => new Projection { SomeProperty = x.SomeProperty });
}
}

public class Foo
Expand All @@ -124,6 +183,17 @@ public class Foo
public string? NotSettable { get; }
}

public class Source
{
public string SomeProperty { get; set; } = default!;
public DateTime CreateDate { get; set; }
}

public class Projection
{
public string SomeProperty { get; set; } = default!;
}

public class AddTypeMismatchMiddlewareAttribute : ObjectFieldDescriptorAttribute
{
protected override void OnConfigure(
Expand Down
Loading