Skip to content

Commit

Permalink
Added support for taking between both cursors in ef (#7806)
Browse files Browse the repository at this point in the history
  • Loading branch information
CronKz authored and michaelstaib committed Dec 16, 2024
1 parent b0c4e1c commit a570145
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ private async ValueTask<Connection> SliceAsync(
if (arguments.After is not null)
{
var cursor = CursorParser.Parse(arguments.After, keys);
query = query.Where(ExpressionHelpers.BuildWhereExpression<TEntity>(keys, cursor, forward));
query = query.Where(ExpressionHelpers.BuildWhereExpression<TEntity>(keys, cursor, true));
}

if (arguments.Before is not null)
{
var cursor = CursorParser.Parse(arguments.Before, keys);
query = query.Where(ExpressionHelpers.BuildWhereExpression<TEntity>(keys, cursor, forward));
query = query.Where(ExpressionHelpers.BuildWhereExpression<TEntity>(keys, cursor, false));
}

if (arguments.First is not null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,78 @@ public async Task Paging_Last_10_With_Default_Sorting_HasPreviousPage()
result.MatchMarkdownSnapshot();
}

[Fact]
public async Task Paging_Fetch_First_2_Items_Between()
{
var connectionString = CreateConnectionString();
await SeedAsync(connectionString);

var executor = await new ServiceCollection()
.AddScoped(_ => new CatalogContext(connectionString))
.AddGraphQLServer()
.AddQueryType<Query>()
.AddSorting()
.AddDbContextCursorPagingProvider()
.BuildRequestExecutorAsync();

var result = await executor.ExecuteAsync(q => q
.SetDocument(
"""
{
brands(first: 2, after:"MQ==", before:"NA==") {
nodes {
name
}
pageInfo {
hasNextPage
hasPreviousPage
endCursor
startCursor
}
}
}
""")
.SetGlobalState("printSQL", true));

result.MatchMarkdownSnapshot();
}

[Fact]
public async Task Paging_Fetch_Last_2_Items_Between()
{
var connectionString = CreateConnectionString();
await SeedAsync(connectionString);

var executor = await new ServiceCollection()
.AddScoped(_ => new CatalogContext(connectionString))
.AddGraphQLServer()
.AddQueryType<Query>()
.AddSorting()
.AddDbContextCursorPagingProvider()
.BuildRequestExecutorAsync();

var result = await executor.ExecuteAsync(q => q
.SetDocument(
"""
{
brands(last: 2, after:"OTc=", before:"MTAw") {
nodes {
name
}
pageInfo {
hasNextPage
hasPreviousPage
endCursor
startCursor
}
}
}
""")
.SetGlobalState("printSQL", true));

result.MatchMarkdownSnapshot();
}

public class Query
{
[UsePaging]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Paging_Fetch_First_2_Items_Between

```json
{
"data": {
"brands": {
"nodes": [
{
"name": "Brand1"
},
{
"name": "Brand2"
}
],
"pageInfo": {
"hasNextPage": true,
"hasPreviousPage": true,
"endCursor": "Mw==",
"startCursor": "Mg=="
}
}
},
"extensions": {
"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"
}
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Paging_Fetch_Last_2_Items_Between

```json
{
"data": {
"brands": {
"nodes": [
{
"name": "Brand97"
},
{
"name": "Brand98"
}
],
"pageInfo": {
"hasNextPage": true,
"hasPreviousPage": true,
"endCursor": "OTk=",
"startCursor": "OTg="
}
}
},
"extensions": {
"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"
}
}
```

0 comments on commit a570145

Please sign in to comment.