Skip to content

Commit a570145

Browse files
CronKzmichaelstaib
authored andcommitted
Added support for taking between both cursors in ef (#7806)
1 parent b0c4e1c commit a570145

File tree

4 files changed

+128
-2
lines changed

4 files changed

+128
-2
lines changed

src/HotChocolate/Data/src/EntityFramework/Pagination/EfQueryableCursorPagingHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ private async ValueTask<Connection> SliceAsync(
4545
if (arguments.After is not null)
4646
{
4747
var cursor = CursorParser.Parse(arguments.After, keys);
48-
query = query.Where(ExpressionHelpers.BuildWhereExpression<TEntity>(keys, cursor, forward));
48+
query = query.Where(ExpressionHelpers.BuildWhereExpression<TEntity>(keys, cursor, true));
4949
}
5050

5151
if (arguments.Before is not null)
5252
{
5353
var cursor = CursorParser.Parse(arguments.Before, keys);
54-
query = query.Where(ExpressionHelpers.BuildWhereExpression<TEntity>(keys, cursor, forward));
54+
query = query.Where(ExpressionHelpers.BuildWhereExpression<TEntity>(keys, cursor, false));
5555
}
5656

5757
if (arguments.First is not null)

src/HotChocolate/Data/test/Data.EntityFramework.Pagination.Tests/IntegrationTests.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,78 @@ public async Task Paging_Last_10_With_Default_Sorting_HasPreviousPage()
316316
result.MatchMarkdownSnapshot();
317317
}
318318

319+
[Fact]
320+
public async Task Paging_Fetch_First_2_Items_Between()
321+
{
322+
var connectionString = CreateConnectionString();
323+
await SeedAsync(connectionString);
324+
325+
var executor = await new ServiceCollection()
326+
.AddScoped(_ => new CatalogContext(connectionString))
327+
.AddGraphQLServer()
328+
.AddQueryType<Query>()
329+
.AddSorting()
330+
.AddDbContextCursorPagingProvider()
331+
.BuildRequestExecutorAsync();
332+
333+
var result = await executor.ExecuteAsync(q => q
334+
.SetDocument(
335+
"""
336+
{
337+
brands(first: 2, after:"MQ==", before:"NA==") {
338+
nodes {
339+
name
340+
}
341+
pageInfo {
342+
hasNextPage
343+
hasPreviousPage
344+
endCursor
345+
startCursor
346+
}
347+
}
348+
}
349+
""")
350+
.SetGlobalState("printSQL", true));
351+
352+
result.MatchMarkdownSnapshot();
353+
}
354+
355+
[Fact]
356+
public async Task Paging_Fetch_Last_2_Items_Between()
357+
{
358+
var connectionString = CreateConnectionString();
359+
await SeedAsync(connectionString);
360+
361+
var executor = await new ServiceCollection()
362+
.AddScoped(_ => new CatalogContext(connectionString))
363+
.AddGraphQLServer()
364+
.AddQueryType<Query>()
365+
.AddSorting()
366+
.AddDbContextCursorPagingProvider()
367+
.BuildRequestExecutorAsync();
368+
369+
var result = await executor.ExecuteAsync(q => q
370+
.SetDocument(
371+
"""
372+
{
373+
brands(last: 2, after:"OTc=", before:"MTAw") {
374+
nodes {
375+
name
376+
}
377+
pageInfo {
378+
hasNextPage
379+
hasPreviousPage
380+
endCursor
381+
startCursor
382+
}
383+
}
384+
}
385+
""")
386+
.SetGlobalState("printSQL", true));
387+
388+
result.MatchMarkdownSnapshot();
389+
}
390+
319391
public class Query
320392
{
321393
[UsePaging]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Paging_Fetch_First_2_Items_Between
2+
3+
```json
4+
{
5+
"data": {
6+
"brands": {
7+
"nodes": [
8+
{
9+
"name": "Brand1"
10+
},
11+
{
12+
"name": "Brand2"
13+
}
14+
],
15+
"pageInfo": {
16+
"hasNextPage": true,
17+
"hasPreviousPage": true,
18+
"endCursor": "Mw==",
19+
"startCursor": "Mg=="
20+
}
21+
}
22+
},
23+
"extensions": {
24+
"sql": "-- @__p_0='1'\n-- @__p_1='4'\n-- @__p_2='3'\nSELECT b.\"Id\", b.\"AlwaysNull\", b.\"DisplayName\", b.\"Name\", b.\"BrandDetails_Country_Name\"\nFROM \"Brands\" AS b\nWHERE b.\"Id\" > @__p_0 AND b.\"Id\" < @__p_1\nORDER BY b.\"Id\"\nLIMIT @__p_2"
25+
}
26+
}
27+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Paging_Fetch_Last_2_Items_Between
2+
3+
```json
4+
{
5+
"data": {
6+
"brands": {
7+
"nodes": [
8+
{
9+
"name": "Brand97"
10+
},
11+
{
12+
"name": "Brand98"
13+
}
14+
],
15+
"pageInfo": {
16+
"hasNextPage": true,
17+
"hasPreviousPage": true,
18+
"endCursor": "OTk=",
19+
"startCursor": "OTg="
20+
}
21+
}
22+
},
23+
"extensions": {
24+
"sql": "-- @__p_0='97'\n-- @__p_1='100'\n-- @__p_2='3'\nSELECT b.\"Id\", b.\"AlwaysNull\", b.\"DisplayName\", b.\"Name\", b.\"BrandDetails_Country_Name\"\nFROM \"Brands\" AS b\nWHERE b.\"Id\" > @__p_0 AND b.\"Id\" < @__p_1\nORDER BY b.\"Id\" DESC\nLIMIT @__p_2"
25+
}
26+
}
27+
```

0 commit comments

Comments
 (0)