Skip to content

Commit

Permalink
Fixed: Projection when using offset paging (#2476)
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalSenn committed Oct 25, 2020
1 parent 0de8364 commit 4ac43f5
Show file tree
Hide file tree
Showing 18 changed files with 294 additions and 1 deletion.
Expand Up @@ -134,7 +134,8 @@ protected override ISelectionVisitorAction Visit(IOutputField field, TContext co

foreach (var selection in selections)
{
if (selection.Field.Name.Value is "nodes" &&
if ((selection.Field.Name.Value is "nodes" ||
selection.Field.Name.Value is "items") &&
selection.SyntaxNode.SelectionSet is not null)
{
context.SelectionSetNodes.Push(
Expand Down
Expand Up @@ -50,6 +50,7 @@ public class ProjectionVisitorTestBase
ProjectionProvider? provider = null,
Action<ModelBuilder>? onModelCreating = null,
bool usePaging = false,
bool useOffsetPaging = false,
ObjectType<TEntity>? objectType = null)
where TEntity : class
{
Expand Down Expand Up @@ -86,6 +87,11 @@ public class ProjectionVisitorTestBase
descriptor.UsePaging<ObjectType<TEntity>>();
}
if (useOffsetPaging)
{
descriptor.UseOffsetPaging<ObjectType<TEntity>>();
}
descriptor
.Use(
next => async context =>
Expand Down
Expand Up @@ -276,6 +276,133 @@ public async Task Create_Projection_Should_Stop_When_UsePagingEncountered()
res1.MatchSqlSnapshot();
}

[Fact]
public async Task CreateOffsetPaging_ProjectsTwoProperties_Items_WithArgs()
{
// arrange
IRequestExecutor tester = _cache.CreateSchema(
_fooEntities,
useOffsetPaging: true);

// act
// assert
IExecutionResult res1 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery("{ root(take:10, skip:1){ items { bar baz } }}")
.Create());

res1.MatchSqlSnapshot();
}

[Fact]
public async Task CreateOffsetPaging_ProjectsTwoProperties_Items()
{
// arrange
IRequestExecutor tester = _cache.CreateSchema(
_fooEntities,
useOffsetPaging: true);

// act
// assert
IExecutionResult res1 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery("{ root{ items { bar baz } }}")
.Create());

res1.MatchSqlSnapshot();
}

[Fact]
public async Task CreateOffsetPaging_ProjectsOneProperty_Items()
{
// arrange
IRequestExecutor tester = _cache.CreateSchema(
_fooEntities,
useOffsetPaging: true);

// act
// assert
IExecutionResult res1 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery("{ root{ items { baz } }}")
.Create());

res1.MatchSqlSnapshot();
}


[Fact]
public async Task CreateOffsetPagingNullable_ProjectsTwoProperties_Items()
{
// arrange
IRequestExecutor tester = _cache.CreateSchema(
_fooNullableEntities,
useOffsetPaging: true);

// act
// assert
IExecutionResult res1 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery("{ root{ items { bar baz } }}")
.Create());

res1.MatchSqlSnapshot();
}

[Fact]
public async Task CreateOffsetPagingNullable_ProjectsOneProperty_Items()
{
// arrange
IRequestExecutor tester = _cache.CreateSchema(
_fooNullableEntities,
useOffsetPaging: true);

// act
// assert
IExecutionResult res1 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery("{ root{ items { baz } }}")
.Create());

res1.MatchSqlSnapshot();
}

[Fact]
public async Task CreateOffsetPaging_Projection_Should_Stop_When_UseProjectionEncountered()
{
// arrange
IRequestExecutor tester = _cache.CreateSchema(
_fooEntities,
useOffsetPaging: true);

// act
// assert
IExecutionResult res1 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery("{ root{ items{ bar list { barBaz } } }}")
.Create());

res1.MatchSqlSnapshot();
}

[Fact]
public async Task CreateOffsetPaging_Projection_Should_Stop_When_UsePagingEncountered()
{
// arrange
IRequestExecutor tester = _cache.CreateSchema(
_fooEntities,
useOffsetPaging: true);

// act
// assert
IExecutionResult res1 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery("{ root{ items{ bar paging { nodes {barBaz }} } }}")
.Create());

res1.MatchSqlSnapshot();
}

public class Foo
{
public int Id { get; set; }
Expand Down
Expand Up @@ -17,6 +17,7 @@ public class SchemaCache
T[] entities,
Action<ModelBuilder>? onModelCreating = null,
bool usePaging = false,
bool useOffsetPaging = false,
ObjectType<T>? objectType = null)
where T : class
{
Expand All @@ -26,6 +27,7 @@ public class SchemaCache
k => base.CreateSchema(
entities,
usePaging: usePaging,
useOffsetPaging: useOffsetPaging,
onModelCreating: onModelCreating,
objectType: objectType));
}
Expand Down
@@ -0,0 +1,17 @@
{
"data": {
"root": {
"items": [
{
"baz": "a"
},
{
"baz": null
},
{
"baz": "c"
}
]
}
}
}
@@ -0,0 +1,2 @@
SELECT "d"."Baz"
FROM "Data" AS "d"
@@ -0,0 +1,20 @@
{
"data": {
"root": {
"items": [
{
"bar": true,
"baz": "a"
},
{
"bar": null,
"baz": null
},
{
"bar": false,
"baz": "c"
}
]
}
}
}
@@ -0,0 +1,2 @@
SELECT "d"."Bar", "d"."Baz"
FROM "Data" AS "d"
@@ -0,0 +1,34 @@
{
"data": {
"root": {
"items": [
{
"bar": true,
"paging": {
"nodes": [
{
"barBaz": "a_a"
},
{
"barBaz": "a_b"
}
]
}
},
{
"bar": false,
"paging": {
"nodes": [
{
"barBaz": "a_a"
},
{
"barBaz": "a_b"
}
]
}
}
]
}
}
}
@@ -0,0 +1,2 @@
SELECT "d"."Bar"
FROM "Data" AS "d"
@@ -0,0 +1,30 @@
{
"data": {
"root": {
"items": [
{
"bar": true,
"list": [
{
"barBaz": "a_a"
},
{
"barBaz": "a_b"
}
]
},
{
"bar": false,
"list": [
{
"barBaz": "a_a"
},
{
"barBaz": "a_b"
}
]
}
]
}
}
}
@@ -0,0 +1,2 @@
SELECT "d"."Bar"
FROM "Data" AS "d"
@@ -0,0 +1,14 @@
{
"data": {
"root": {
"items": [
{
"baz": "a"
},
{
"baz": "b"
}
]
}
}
}
@@ -0,0 +1,2 @@
SELECT "d"."Baz"
FROM "Data" AS "d"
@@ -0,0 +1,16 @@
{
"data": {
"root": {
"items": [
{
"bar": true,
"baz": "a"
},
{
"bar": false,
"baz": "b"
}
]
}
}
}
@@ -0,0 +1,12 @@
{
"data": {
"root": {
"items": [
{
"bar": false,
"baz": "b"
}
]
}
}
}
@@ -0,0 +1,2 @@
SELECT "d"."Bar", "d"."Baz"
FROM "Data" AS "d"
@@ -0,0 +1,2 @@
SELECT "d"."Bar", "d"."Baz"
FROM "Data" AS "d"

0 comments on commit 4ac43f5

Please sign in to comment.