Skip to content

Commit

Permalink
Merge branch 'develop' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Oct 16, 2020
2 parents 02d6789 + 911db2a commit c508b34
Show file tree
Hide file tree
Showing 26 changed files with 367 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public static class NodeObjectTypeExtensions
return new NodeDescriptor<T>(descriptor);
}

[Obsolete("Use ImplementNode.")]
[Obsolete("Use ImplementsNode.")]
public static INodeDescriptor AsNode(
this IObjectTypeDescriptor descriptor) =>
ImplementsNode(descriptor);

[Obsolete("Use ImplementNode.")]
[Obsolete("Use ImplementsNode.")]
public static INodeDescriptor<T> AsNode<T>(
this IObjectTypeDescriptor<T> descriptor) =>
ImplementsNode<T>(descriptor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public override FieldMiddleware CreateExecutor<TEntityType>(NameString argumentN
source = e.AsQueryable();
}

if (source != null && argument.Type is ISortInputType sortInput)
if (source != null &&
argument.Type is ListType lt &&
lt.ElementType is ISortInputType sortInput)
{
var visitorContext = new QueryableSortContext(
sortInput,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ public static class SortObjectFieldDescriptorExtensions
throw SortObjectFieldDescriptorExtensions_CannotInfer();
}
argumentType = typeof(ListType<>).MakeGenericType(argumentType);
var argumentDefinition = new ArgumentDefinition
{
Name = argumentPlaceholder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected override ISyntaxVisitorAction Enter(IValueNode node, TContext context)
}
else
{
throw new InvalidOperationException();
return Continue;
}

return Break;
Expand All @@ -104,7 +104,7 @@ protected override ISyntaxVisitorAction Enter(IValueNode node, TContext context)
}
else
{
throw new InvalidOperationException();
return Continue;
}

return Break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,28 @@ public async Task Create_Boolean_OrderBy()
res2.MatchSnapshot("DESC");
}

[Fact]
public async Task Create_Boolean_OrderBy_List()
{
// arrange
IRequestExecutor tester = _cache.CreateSchema<Foo, FooSortType>(_fooEntities);

// act
IExecutionResult res1 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery("{ root(order: [{ bar: ASC}]){ bar}}")
.Create());

IExecutionResult res2 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery("{ root(order: [{ bar: DESC}]){ bar}}")
.Create());

// assert
res1.MatchSnapshot("ASC");
res2.MatchSnapshot("DESC");
}

[Fact]
public async Task Create_Boolean_OrderBy_Nullable()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ public async Task Create_ObjectNullableEnum_OrderBy()

res2.MatchSnapshot("13");
}

[Fact]
public async Task Create_ObjectString_OrderBy()
{
Expand Down Expand Up @@ -327,6 +328,7 @@ public async Task Create_ObjectNullableString_OrderBy()

res2.MatchSnapshot("13");
}

[Fact]
public async Task Create_ObjectBool_OrderBy()
{
Expand Down Expand Up @@ -382,6 +384,71 @@ public async Task Create_ObjectNullableBool_OrderBy()
res2.MatchSnapshot("13");
}

[Fact]
public async Task Create_ObjectString_OrderBy_TwoProperties()
{
// arrange
IRequestExecutor tester = _cache.CreateSchema<Bar, BarSortType>(_barEntities);

// act
// assert
IExecutionResult res1 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery(
"{ root(order: { foo: { barBool: ASC, barShort: ASC }}) " +
"{ foo{ barBool barShort}}}")
.Create());

res1.MatchSnapshot("ASC");

IExecutionResult res2 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery(
@"
{
root(order: [
{ foo: { barBool: ASC } },
{ foo: { barShort: ASC } }]) {
foo {
barBool
barShort
}
}
}
")
.Create());

res2.MatchSnapshot("ASC");

IExecutionResult res3 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery(
"{ root(order: { foo: { barBool: DESC, barShort: DESC}}) " +
"{ foo{ barBool barShort}}}")
.Create());

res3.MatchSnapshot("DESC");

IExecutionResult res4 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery(
@"
{
root(order: [
{ foo: { barBool: DESC } },
{ foo: { barShort: DESC } }]) {
foo {
barBool
barShort
}
}
}
")
.Create());

res4.MatchSnapshot("DESC");
}

public class Foo
{
public int Id { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"data": {
"root": [
{
"bar": false
},
{
"bar": true
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"data": {
"root": [
{
"bar": true
},
{
"bar": false
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"data": {
"root": [
{
"foo": {
"barBool": false,
"barShort": 13
}
},
{
"foo": {
"barBool": true,
"barShort": 12
}
},
{
"foo": {
"barBool": true,
"barShort": 14
}
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"data": {
"root": [
{
"foo": {
"barBool": true,
"barShort": 14
}
},
{
"foo": {
"barBool": true,
"barShort": 12
}
},
{
"foo": {
"barBool": false,
"barShort": 13
}
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@

namespace HotChocolate.Data.Sorting
{

public class QueryableSortVisitorBooleanTests
: IClassFixture<SchemaCache>
{
private static readonly Foo[] _fooEntities =
{
new Foo { Bar = true },
new Foo { Bar = false }
new Foo { Bar = true }, new Foo { Bar = false }
};

private static readonly FooNullable[] _fooNullableEntities =
Expand Down Expand Up @@ -52,6 +50,28 @@ public async Task Create_Boolean_OrderBy()
res2.MatchSqlSnapshot("DESC");
}

[Fact]
public async Task Create_Boolean_OrderBy_List()
{
// arrange
IRequestExecutor tester = _cache.CreateSchema<Foo, FooSortType>(_fooEntities);

// act
IExecutionResult res1 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery("{ root(order: [{ bar: ASC}]){ bar}}")
.Create());

IExecutionResult res2 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery("{ root(order: [{ bar: DESC}]){ bar}}")
.Create());

// assert
res1.MatchSnapshot("ASC");
res2.MatchSnapshot("DESC");
}

[Fact]
public async Task Create_Boolean_OrderBy_Nullable()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ public async Task Create_ObjectNullableBool_OrderBy()
.SetQuery(
"{ root(order: { foo: { barBool: ASC}}) " +
"{ foo{ barBool}}}")
.Create());
.Create());

IExecutionResult res2 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
Expand All @@ -372,6 +372,71 @@ public async Task Create_ObjectNullableBool_OrderBy()
res2.MatchSqlSnapshot("13");
}

[Fact]
public async Task Create_ObjectString_OrderBy_TwoProperties()
{
// arrange
IRequestExecutor tester = _cache.CreateSchema<Bar, BarSortType>(_barEntities);

// act
// assert
IExecutionResult res1 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery(
"{ root(order: { foo: { barBool: ASC, barShort: ASC }}) " +
"{ foo{ barBool barShort}}}")
.Create());

res1.MatchSnapshot("ASC");

IExecutionResult res2 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery(
@"
{
root(order: [
{ foo: { barBool: ASC } },
{ foo: { barShort: ASC } }]) {
foo {
barBool
barShort
}
}
}
")
.Create());

res2.MatchSnapshot("ASC");

IExecutionResult res3 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery(
"{ root(order: { foo: { barBool: DESC, barShort: DESC}}) " +
"{ foo{ barBool barShort}}}")
.Create());

res3.MatchSnapshot("DESC");

IExecutionResult res4 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery(
@"
{
root(order: [
{ foo: { barBool: DESC } },
{ foo: { barShort: DESC } }]) {
foo {
barBool
barShort
}
}
}
")
.Create());

res4.MatchSnapshot("DESC");
}

public class Foo
{
public int Id { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"data": {
"root": [
{
"bar": false
},
{
"bar": true
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"data": {
"root": [
{
"bar": true
},
{
"bar": false
}
]
}
}

0 comments on commit c508b34

Please sign in to comment.