Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Issue with sorting and GraphQLType #4443

Merged
merged 3 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/HotChocolate/Data/src/Data/Sorting/Fields/SortField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected override void OnCompleteField(

if (Member?.DeclaringType is not null)
{
RuntimeType = context.TypeInspector.GetReturnType(Member);
RuntimeType = context.TypeInspector.GetReturnType(Member, ignoreAttributes: true);
michaelstaib marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
55 changes: 55 additions & 0 deletions src/HotChocolate/Data/test/Data.Sorting.Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using HotChocolate.Execution;
using HotChocolate.Tests;
using HotChocolate.Types;
using Microsoft.Extensions.DependencyInjection;
using Xunit;

namespace HotChocolate.Data.Tests;

public class IntegrationTests
{
[Fact]
public async Task Sorting_Should_Work_When_UsedWithNonNullDateTime()
{
// arrange
IRequestExecutor executor = await new ServiceCollection()
.AddGraphQL()
.AddQueryType<Query>()
.AddSorting()
.BuildRequestExecutorAsync();

const string query = @"
{
foos(order: { createdUtc: DESC }) {
createdUtc
}
}
";

// act
IExecutionResult result = await executor.ExecuteAsync(query);

// assert
result.MatchSnapshot();
}
}

public class Query
{
[UseSorting]
public IEnumerable<Foo> Foos() => new[]
{
new Foo { CreatedUtc = new DateTime(2000, 1, 1, 1, 1, 1) },
new Foo { CreatedUtc = new DateTime(2010, 1, 1, 1, 1, 1) },
new Foo { CreatedUtc = new DateTime(2020, 1, 1, 1, 1, 1) }
};
}

public class Foo
{
[GraphQLType(typeof(NonNullType<DateType>))]
public DateTime CreatedUtc { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"data": {
"foos": [
{
"createdUtc": "2020-01-01"
},
{
"createdUtc": "2010-01-01"
},
{
"createdUtc": "2000-01-01"
}
]
}
}